Nom blocks : grouping statements together to create grammar rule reductions.
Statements can be grouped together in the Nom language with braces as follows
# a begin block
begin { add "Counting lines...\n"; print; clear; }
read;
# a block after a character test
[\n] { clear; a+; }
clear;
# the end-of-file test and block
(eof) {
add "# lines: ";
count; print;
quit;
}
Block are very often used in the parsing section of the script to create grammar rule reductions when parsing a language or pattern.
Blocks can be nested as deeply as required, and this nesting provides away to make complex logic tests on the workspace
statement : ??= (command quotedtext) | ?? (expression quotedtext ) | ?? (operator quotedtext) ;
pop;pop;
E"quoted.text*" {
B"command*",B"expression*",B"operator*" {
clear; add "statement*"; push; .reparse
}
}
Unlike SED or the c language a single statement is not allowed after a test unless it is within a block
"tree" clear;
"tree" { clear; }
Also, unlike SED and other (modern) languages, even the last statement in a block must be terminated with a semi-colon
[:space:] { while [:space:]; put; clear }
# missing semi-colon