pargen.icn: Program to generate context-free parser

March 31, 1992; Ralph E. Griswold
This file is in the public domain.
   This program reads a context-free BNF grammar and produces an Icon
program that is a parser for the corresponding language.

   Nonterminal symbols are are enclosed in angular brackets. Vertical
bars separate alternatives.  All other characters are considered to
be terminal symbols.  The nonterminal symbol on the first line is
taken to be the goal.

   An example is:

     <expression>::=<term>|<term>+<expression>
     <term>::=<element>|<element>*<term>
     <element>::=x|y|z|{<expression>}

   Parentheses can be used for grouping symbols, as in

     <term>::=<element>(|*<term>)

   Note that an empty alternative is allowable.

   The right-hand side metacharacters <, >, (, ), and | are accessible
through the built-in symbols <lb>, <rb>, <lp>, <rp>, and <vb>,
respectively. There are two other build-in symbols, <empty> and <nl>
that match the empty string and a newline, respectively.

   Characters in nonterminal names are limited to letters, digits, and
underscores.

   An underscore is appended to the parsing procedure name to avoid
possible collisions with Icon function names.

   Lines beginning with an = are passed through unchanged. This allows
Icon declarations to be placed in the parser.  Lines beginning with
a # are considered to be comments and are ignored.

   If the name of a ucode file is given on the command line, a link
declaration for it is provided in the output. Otherwise the main
procedure in recog is used.
____________________________________________________________

Limitations:

   Left recursion in the grammar may cause the parser to loop.
There is no check that all nonterminal symbols that are referenced
are defined or that there may be duplicate definitions.
____________________________________________________________

Reference:

   The Icon Programming Language, Second Edition, Ralph E. and Madge T.
   Griswold, Prentice-Hall, 1990, pp. 180-187.
____________________________________________________________

Output links recog, matchlib

See also: recog.icn, matchlib.icn, and parscond.icn

Source code | Program Library Page | Icon Home Page