clear or delete the text in the workspace buffer.
A very common procedure in a nom script when parsing and translating a
formal language (examples of languages are the json
text data format, the “java” programming language, or the
set of palindromes is to 1st match a set of parse tokens,
then build the text attribute for the parse token
which will replace the matched tokens, and then put the new attribute
into the current tape cell. Then clear the workspace buffer and
create the new parse token. The example below (from a fictitious grammar for
parsing arithmetic expressions) illustrates these steps:
pop; pop; pop;
# match the token sequence 'leftbrace expression rightbrace'
"leftbrace*expression*rightbrace*" {
clear;
# build the new 'attribute' from each parse token attribute
get; ++; get; ++; get;
# realign the tape pointer and save the new attribute
--; --; put;
# clear the workspace, build the new parse token, and push on stack
clear; add "expression*"; push;
# jump back to the 'parse>' label: this allows any other
# grammar reductions/productions to take place
.reparse
}
The script above represent a single grammar rule or production namely
expression = leftbrace expression rightbrace ;
read; [\t\r] { clear; } print; clear;
while [:space:]; clear; (eof) { .reparse }
whilenot [:space:]; put; clear; add "word*"; push;
parse>
pop; "word*" {
clear; get;
"green","blue","yellow" { clear; add "colour*"; push; .reparse }
[:digit:] { clear; add "number*"; push; .reparse }
}
push;
# script continues.
By examining the diagrams below, it is possible to see exactly how the clear command affects machine state. Actually, only the workspace buffer is affected. Within the pep interpreter the instruction pointer is also affected, but when a script runs through a translator there is no equivalent program state.
Machine State stack
work char*char*
peep v
acc 0
flag TRUE
esc \\
delim *
chars 2
lines 1
Tape cell text mark (size: 500) 0> r 1 e 2
Partial Program Listing 57: add [text:pal*pal*] 58: testis [text:char*char*] 59: jumpfalse [int:19] 60> clear 61: get 62: ++
Machine State stack
work
peep v
acc 0
flag TRUE
esc \\
delim *
chars 2
lines 1
Tape cell text mark (size: 500) 0> r 1 e 2
Partial Program Listing 58: testis [text:char*char*] 59: jumpfalse [int:19] 60: clear 61> get 62: ++ 63: testtape
the current parse token