Pep and Nom

home | documentation | examples | translators | download | blog | all blog posts

statement blocks in the ℕ𝕠𝕞 language

Nom blocks : grouping statements together to create grammar rule reductions.

Statements can be grouped together in the Nom language with braces as follows

delete and count all newline characters


    # 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;
    }
  

blocks and grammar rules

Block are very often used in the parsing section of the script to create grammar rule reductions when parsing a language or pattern.

nesting blocks

Blocks can be nested as deeply as required, and this nesting provides away to make complex logic tests on the workspace

The code below is equivalent to the following [ebnf] grammar rule:


   statement : ??= (command quotedtext) | ?? (expression quotedtext ) | ?? (operator quotedtext) ;
  

complex grammar rule recognition using nesting of blocks


    pop;pop;
    E"quoted.text*" {
      B"command*",B"expression*",B"operator*" {
        clear; add "statement*"; push; .reparse
      }
    }
  

notes

Unlike SED or the c language a single statement is not allowed after a test unless it is within a block

incorrect ℕ𝕠𝕞 syntax
 "tree" clear;

correct ℕ𝕠𝕞 syntax


    "tree" { clear; }
  

Also, unlike SED and other (modern) languages, even the last statement in a block must be terminated with a semi-colon

incorrect syntax


    [:space:] { while [:space:]; put; clear } 
    # missing semi-colon