Grammar is the syntax of the universe. Trueism
Nom blocks : grouping statements together to create grammar rule reductions.
Blocks in the nom language are indicated by the “curly braces ” {...} which are referred to as “crab pincers” by the author of the Poignant Guide to Ruby Blocks are always preceded by tests , either a single test or by a OR or AND sequence of tests. White-space is of no significance in blocks (except within quotes and classes).
Statements can be grouped together in the Nom language with braces as follows:
# a begin block, is only executed once at the beginning
# of a script (just like AWK's begin blocks).
begin { add "Counting lines...\n"; print; clear; }
read;
# a one-line block after a character class 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
}
}
Blocks in the nom language cannot be empty, because what is the point of that?
read;
[:space:] { }
But if you really want a do-nothing block, you could put the
do-nothing command nop
inside it like this:
read; [:space:] { nop; } # does nothing, as requested
Unlike SED or many other languages (eg: 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 (unless
it is a .reparse
or .restart
command.
[:space:] { while [:space:]; put; clear }
# missing semi-colon
Actually, you can put a parse> label in a block, but please don't unless you really, really know what you are doing. The parse label should be just after the lexical analysis phase of the script and should not be within {..}.