Skip to content
stack-based macro language
C Roff M4 Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

<style type="text/css"> p { margin-top: 0; margin-bottom: 0; vertical-align: top } pre { margin-top: 0; margin-bottom: 0; vertical-align: top } table { margin-top: 0; margin-bottom: 0; vertical-align: top } h1 { text-align: center } </style> <title>pushmac</title>




pushmac - a stack-based macro processor that can form macros based on results returned by scheme functions




pushmac is a stack-based macro processor. It reads from standard input, evaluates the macros provided to standard input, and writes the processed text to standard output. The macro language is parsed by reading one character at a time from left to right in a single pass.

The macro language is centered around a stack. When you are on the bottom of the stack, characters typed in are echoed to standard output until a command is reached. You can move up a level in the stack by using the PUSH command (by default: #). Text you enter at higher levels of the stack will not be put to standard output but can be accessed by pushmac commands.

Macro processing languages are used for text generation whether that text is code, a website, or writing.


The following are the pushmac commands. These characters will just be output as is if there are not enough "levels" in the stack. So most of these do not need to be escaped unless the stack already has some elements on it.


PUSH command. All text written after the command is the next level up on the stack.


DEFINE command. Pops the text off the top two levels of the stack and assigns the text at the top of the text to the macro name at the second level from the top.


REFERENCE command. Pops the text from the top of the stack, looks up the name of the macro specified there, and puts that text’s value to the next level down in the stack.


EXPAND command. Expands the macros in the text on the top level of the stack.


SHELL command. Evalutes the text on the top level of the stack as a shell command, and outputs the output of the command to the next level down on the stack.


PUSH2 command.


QUOTE text. Put the literal text to the current level of the stack. This is how you escape the command characters.


QUESTION command. If the first element on the stack is "yes", output the second element on the stack, otherwise output the third element on the stack.


IGNORE command. Ignore everything on the top of the stack (i.e. this is like a "comment" command).


SILENCE command. Do not print any of the characters on the top of the stack.


SPEAK command. Allow the characters (that presumably have been previously silenced) to print again.


Section header

pushmac commands could be used to create a section header in a standard way, like so:

#sec=’Section #i~: #title~’@
#title=The Beginning@
#title=After the Beginning@

are expanded to

Section 1: The Beginning
Section 2: After the Beginning

This is useful in case you may want to change later how the titles are formatted.

Boilerplate Guile Code

Guile is a Scheme language that is easy to use to extend programs. Guile functions have to be registered in the C program that wants to make use of them. pushmac makes this process easy to generate.

register_guile_functions (void* data)
scm_c_define_gsubr("#name~", #argnum~, 0, 0, &guile_#name~);@
return NULL;

Then, we can create guile functions like:

##gfunc~$ (SCM file) { ... }

And then type ##regbuild~$ to output the register_guile_functions function that can be used with Guile’s scm_with_guile function.



Please report as an issue to


Zach Flynn <> 0.0.1

You can’t perform that action at this time.