add or appends the given text to the end of the workspace
buffer.
This command is a real workhorse of the ℙ𝕖𝕡 and ℕ𝕠𝕞 system. It is used for creating the text attributes that go onto the tape and also for making the parse-tokens that are pushed onto the stack .
The command takes one quoted parameter which is the text to be appended to the workspace*. The parameter can be single-quoted or double, there is no difference. And the quoted parameter can extend over multiple lines.
No other register or buffer within the pep virtual machine is affected by the add command.
pop;pop;
"command*end* {
clear; add "statement* ??"; push; .reparse
}
push;push;
begin {
add '
A multi-line
argument for the "add" command.
';
} read; print; clear;
It is possible to use escaped characters such as \n \r \t \f or \" in the quoted argument.
r; E"." { add "\ ??count"; } print; clear;
read; add ' '; print; clear;
# or the same using abbreviated commands
# r; a ' ';p;d;
“Add” is used to create new tokens and to modify the token attributes.
"style* ??type* ??" {
clear;
add "command* ??";
push;
}
The script above does a shift-reduce operation while parsing some
hypothetical language. The “add” command is used to add a new token name to
the 'workspace' buffer which is then pushed onto the stack (using the 'push'
operation, naturally). In the above script the text added can be seen to be
a token name (as opposed to some other arbitrary piece of text) because it
ends in the “*” character. Actually any character can be used to delimit
the token names, put “*” is the default. This can be changed with
the delim
command.
The add command takes one and only one parameter, or argument.
add is the typical way to create new parse-tokens during
shift-reduce parsing (after clearing the workspace
buffer). But when we use lookahead for contextual parse-token
sequence reductions, then we often need to use replace
instead
of add*. This is because we may not know what the lookahead token is - we only know what it is not .
r; [\:] { add "\ ??""; } print; clear; # non java fix!!
r; [:] { add "\""; } print; clear; # java version
But it shouldn't be necessary to escape ':'