
\documentstyle[glammar]{article}
\topmargin      0 mm
\headheight     0 mm
\headsep        0 mm
\textheight     240 mm
\footskip       7 mm
\footheight     11 mm

\oddsidemargin  0 mm
\evensidemargin 0 mm
\textwidth      159.2 mm
\author{Eric Voss}
\title{Description of builtins in Glammar}
\makeindex
\begin{document}
\maketitle
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\noindent
This section contains the description of  the current set of builtins.  
Some builtins may not be redefined.
The comment statement \verb+#plain+ indicates this for hyperrules.
None of the metabuiltins can be redefined.
In addition, you may not even use some builtins.
This is the case when its name ends with a underscore. 
Other properties of a builtin are implicit in the form of its definition.
These properties are:
\begin{enumerate}
\item
deterministic builtins have only one production:
{\small
\begin{glammar}
\L{\LB{        \K{builtin}: x.}}
\L{\LB{}}
\end{glammar}}

\item
      nondeterministic builtins that can be forced
             to behave deterministicly (-d option) have two productions:
{\small
\begin{glammar}
\L{\LB{          \K{builtin }: x;}}
\L{\LB{          builtin : x.}}
\L{\LB{}}
\end{glammar}}


\item
nondeterministic builtins have three productions:
{\small
\begin{glammar}
\L{\LB{          \Proc{1}\K{builtin }\index{builtin 1}: x;}}
\L{\LB{          builtin : x;}}
\L{\LB{          builtin : x.}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}
\item
 builtins that always succeed have no members in the right hand side:
{\small
\begin{glammar}
\L{\LB{          \Proc{1}\K{builtin }\index{builtin 1}: .}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\item
builtins that do not produce empty have a terminal ({\tt "a"} by default) in the right hand side:
{\small
\begin{glammar}
\L{\LB{          \Proc{1}\K{builtin }\index{builtin 1}: \T{}"x"\TE{}.}}
\L{\LB{}}
\end{glammar}}


\item
builtins that use an inherited affix for affix directed parsing
             have a single affix terminal on this position:
{\small
\begin{glammar}
\L{\LB{          \Proc{1}\K{builtin }\index{builtin 1}\D{}(\>\S{}\"x\"\SE{})\DE{} : x.}}
\L{\LB{}}
\end{glammar}}


\item
builtins that do not use an inherited affix for affix directed parsing
             have a single affix variable on this position:
{\small
\begin{glammar}
\L{\LB{         \Proc{1}\K{builtin }\index{builtin 1}\D{}(\>x)\DE{} : x.}}
\L{\LB{}}
\end{glammar}}
\end{enumerate}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{99}\K{empty }::.}}
\L{\LB{\Proc{100}\K{nlcr }:: \S{}\"\!n\"\SE{}.}}
\L{\LB{\Proc{101}\K{quote }:: \S{}\"\!"\"\SE{}.}}
\L{\LB{\Proc{102}\K{back slash }:: \S{}\"\!\!\"\SE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent These are some metanotions which you can use to recognize frequently used special symbols.
\label{empty.}
\label{nlcr.}
\label{quote.}
\label{backslash.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{110}\K{generation time }:: \S{}\"Fri Sep 22 11:53:37 1989\"\SE{}.}}
\L{\LB{\Proc{111}\K{generation date }:: \S{}\"Sep 22, 1989\"\SE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent The time and date the grammar was generated (\g was invoked).
This metarule is set when you compile the grammar.  
The definitions below show their form only.
\label{generationtime.}
\label{generationdate.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\noindent  All special symbols can be denoted by giving the 
octal ascii representation escaped by a back slash.
To remain compatible with earlier implementations some special symbols
are predefined. 
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{126}\index{end of sentence 126}\K{end of sentence}= ?\T{}"\!000"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent Tests for reached the end of the input.
\label{endofsentence.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{131}\index{nlcr 131}\K{nlcr}= \T{}"\!n"\TE{}.}}
\L{\LB{\Proc{132}\index{quote  132}\K{quote }= \T{}"\!""\TE{}.}}
\L{\LB{\Proc{133}\index{back slash  133}\K{back slash }= \T{}"\!\!"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent Recognize a newline, quote or back slash respectively.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\noindent This is a list of predicates which have been implemented in very early
versions also.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{144}\index{equal  144}\K{equal }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"x\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{146}\index{not equal  146}\K{not equal }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"y\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent Recognizes the empty string (`succeeds') if the values of {\tt x} and {\tt y} are
(not) equal.
\label{equal.}
\label{notequal.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{154}\index{compare  154}\K{compare }\D{}(\>x,\>y,tail x\>, tail y\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent Let K be the longest common prefix of (the values of)  {\tt x} and  {\tt y}.
Then   {\tt tail x} and  {\tt tail y} 
will assigned values such that   {\tt x}  = K +  {\tt tail x} and  {\tt y} = K +  {\tt tail y}.
\label{compare.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{162}\index{charnum  162}\K{charnum }\D{}(pos\>)\DE{}= .}}
\L{\LB{\Proc{163}\index{settabstop  163}\K{settabstop }\D{}(\>tabstop)\DE{}= .}}
\L{\LB{\Proc{164}\index{linenum  164}\K{linenum }\D{}(line\>)\DE{}= .}}
\L{\LB{\Proc{165}\index{length  165}\K{length }\D{}(\>in,length\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent The affix {\tt pos} in {\tt charnum} is given the number of characters, in decimal, already recognized in the input.
The affix {\tt tabstop} in {\tt settabstop} specifies the value (in decimal) of the variable {\tt tabstop}.
This value is used in {\tt charnum}.
The default value for {\tt tabstop} is {\tt 8}.
The affix {\tt line} in {\tt linenum} is given the value (in decimal) of the current line number.
The affix {\tt length} in {\tt length} is given the value (in decimal) of the number of characters 
of affix {\tt in}.
\label{charnum.}
\label{settabstop.}
\label{linenum.}
\label{length.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{180}\index{some name  180}\K{some name }\D{}(name\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent The affix name is given a value $L_X$, where $X$ is some large number in hexadecimal notation.
Each number can occur only once in one parse.
\label{somename.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\noindent GLAMMAR allows the manipulation of certain ordered sequences of pairs of values 
for historic reasons called {\em lists} but {\em tables} would be better instead.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{191}\index{add to  191}\K{add to }\D{}(\>table, \>key,\>value)\DE{}= ;}}
\L{\LB{add to \D{}(\>table, \>key,\>value)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent Each table is recorded under a name which is an arbitrary affix value 
(it may be empty, contain newlines, be obtained from {\tt some name} etc.)
However it may not be composite
(i.e: {\small  add to ($>$x*y,>$k$, >$v$)} is not allowed).
Initiative every possible affix value is the name of an empty table.
The builtin {\tt add to} puts the pair (K,P) in front of the table
named L, where L,K and P are the values of {\tt table, key} and {\tt value}
respectively.
Upon backtracking the pair is 
deleted from the table, prohibited that it is not forced to behave deterministic.
\label{addto.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{207}\index{value of  207}\K{value of }\D{}(\>\S{}\"table\"\SE{}, \>\S{}\"key\"\SE{},value\>)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent If (K,P) is the first pair, if any, in table L such that L
and K are the values of {\tt table} and {\tt key} respectively
(which most be both known), then the value of {\tt value} is P otherwise it
is the empty string.
\label{valueof.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{216}\index{select  216}\K{select }\D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{};}}
\L{\LB{select \D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{};}}
\L{\LB{select \D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent The values of key and value are K and P respectively, where (K,P)
is any pair in the table L, where L is the value of table (which must be known).
Note that {\tt select} succeeds once for each pair.
\label{select.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{225}\index{delete  225}\K{delete }\D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{};}}
\L{\LB{delete \D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{};}}
\L{\LB{delete \D{}(\>\S{}\"table\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\label{delete.}
\noindent {\tt delete} is quite a  strange predicate.
Basicly it deletes all pairs in the table, one at a time.
When a pair is deleted,  upon backtracking the  deleted item is 
not restored. 
Instead one more element is deleted,
until the table is empty.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{239}\index{contents of  239}\K{contents of }\D{}(\>\S{}\"table\"\SE{}, \>key val sep,\>key key sep,contents\>)\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\label{contentsof.}
\noindent {\tt contents of} finds the contents of a table in one go,
with the pairs separated with {\tt key key sep} and
the two items of a pair separated by {\tt key val sep}.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{247}\index{size  247}\K{size }\D{}(\>\S{}\"table\"\SE{}, size\>)\DE{}=  .}}
\L{\LB{}}
\end{glammar}}

\label{size.}
\noindent Affix {\tt size} is given the number of pairs of {\tt table}, in decimal notation.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{252}\index{lookup  252}\K{lookup }\D{}(\>\S{}\"table\"\SE{}, \>\S{}\"key\"\SE{},value\>)\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent {\tt lookup} finds the first pair in the table with matching key.
It fails if there is no such pair.
\label{lookup.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{259}\index{includes  259}\K{includes }\D{}(\>\S{}\"table\"\SE{}, \>\S{}\"key\"\SE{})\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{\Proc{260}\index{excludes  260}\K{excludes }\D{}(\>\S{}\"table\"\SE{}, \>\S{}\"key\"\SE{})\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent Above predicates succeed if there is a (no) pair (K,P) in table L where
L and K  are the values of table and key respectively.
\label{includes.}
\label{excludes.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{269}\index{pair  269}\K{pair }\D{}(cell\>, \>key,\>value)\DE{}=  .}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{271}\index{unpair  271}\K{unpair }\D{}(\>\S{}\"cell\"\SE{}, key\>,value\>)\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\label{pair.}
\label{unpair.}
\noindent In addition to the table (tables) processing builtins there are three builtins
which work on named tuples.
Each tuple has a unique name.
You can always work around  using the predicates {\tt pair} and {\tt unpair}.
Both are  generated by eliminating  the composition operator.
For example to two following rules are equal :
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{    \Proc{2}\K{b }\index{b 2}\D{}(\>L1)\DE{}:}}
\L{\LB{         unpair \D{}(\>L1,a\>,L2\>)\DE{},}}
\L{\LB{         unpair \D{}(\>L2,b\>,c\>)\DE{}.}}
\L{\LB{}}
\L{\LB{    \Proc{6}\K{b }\index{b 6}\D{}( \>a*b*c)\DE{}:.}}
\end{glammar}}
If the left position is applying instead of defining {\tt unpair} must be replaced with  {\tt pair}.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{293}\index{repair  293}\K{repair }\D{}(\>\S{}\"cell\"\SE{}, \>key,\>value)\DE{}= \T{}"a"\TE{};}}
\L{\LB{repair \D{}(\>\S{}\"cell\"\SE{}, \>key,\>value)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}
 
\noindent {\tt repair} updates the earlier created cell (with {\tt pair}) with new values.
Upon backtracking this is undone unless deterministic behavior is forced.
{\tt repair} fails if there is no tuple {\tt (key,value)} with name {\tt cell}.
\label{repair.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{303}\index{where  303}\K{where }\D{}(\>x,x\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent Because the composition operator is not associative brackets are needed
to denote certain structures.
Glammar does not allow you to write brackets in affix expressions.
For example  {\tt >a*(x*y)*c} is not allowed.
You can however make such structures using where.
For example :
{\small
\begin{glammar}
\L{\LB{   \Proc{2}\K{t }\index{t 2}\D{}(\>a*b*c)\DE{}:}}
\L{\LB{       my own where \D{}(\>b,x*y\>)\DE{}.}}
\L{\LB{}}
\L{\LB{   \Proc{5}\K{my own where }\index{my own where 5}\D{}(\>x,x\>)\DE{}:.}}
\end{glammar}}
After the composition operator is removed :
{\small
\begin{glammar}
\L{\LB{    \Proc{2}\K{t }\index{t 2}\D{}(\>L1)\DE{}:}}
\L{\LB{        unpair \D{}(\>L1,a\>,L2\>)\DE{},}}
\L{\LB{        unpair \D{}(\>L2,b\>,c\>)\DE{},}}
\L{\LB{        my own where \D{}(\>b,L3\>)\DE{},}}
\L{\LB{        unpair \D{}(\>L3,x\>,y\>)\DE{}.}}
\L{\LB{}}
\L{\LB{    \Proc{8}\K{my own where }\index{my own where 8}\D{}(\>x,x\>)\DE{}:.}}
\end{glammar}}
\noindent It is obvious that {\tt my own where} has become superfluous if we substitute
{\tt b} for {\tt L3}.
This is the reason why there is a predefined built-in {\tt where}.
The compiler tries to remove {\tt where} if it is possible by renaming affixes.
So when used {\tt where} instead of {\tt my our own where} the result after transformation
would have been :
{\small
\begin{glammar}
\L{\LB{\Proc{1}\K{t }\index{t 1}\D{}(\>L1)\DE{}:}}
\L{\LB{    unpair \D{}(\>L1,a\>,L2\>)\DE{},}}
\L{\LB{    unpair \D{}(\>L2,b\>,c\>)\DE{},}}
\L{\LB{    unpair \D{}(\>b,x\>,y\>)\DE{}.}}
\L{\LB{}}
\end{glammar}}
\label{where.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{346}\index{lexical less  346}\K{lexical less }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"y\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{347}\index{lexical more  347}\K{lexical more }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"y\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{348}\index{lexical less equal  348}\K{lexical less equal }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"y\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{349}\index{lexical more equal  349}\K{lexical more equal }\D{}(\>\S{}\"x\"\SE{},\>\S{}\"y\"\SE{})\DE{}= \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent These builtins compare affixes to their lexical ordening.
\label{lexicalless.}
\label{lexicalmore.}
\label{lexicallessequal.}
\label{lexicalmoreequal.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{358}\index{compute  358}\K{compute }\D{}(\>expr, result\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent If  {\tt expr} is a string representing a simple expression (like  {\tt 2*(3+1)})
 {\tt result} will assigned the value of this expression in decimal ( {\tt 8}).
The expression may only contain the one-character operators $! < > = + - * /$ and
signed integer notation.
The maximum integer value is inherited from the C value for this.  
Booleans are implemented as $\{0,X\}$,  where $0$ denotes {\tt false}, anything 
else (preferably $1$) is taken to be {\tt true}. 
Anything not an operator or integral number (spaces included) terminates 
the expression.
A not well-formed expression however gives an error message. 
For arbitrary precision arithmetic you can set up a connection to the unix
program {\tt dc}.
\label{compute.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{374}\index{realtoint  374}\K{realtoint }\D{}(\>number, result\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}
 
\noindent Converts a decimal real in scientific notation to the nearest decimal integer not greater than real.
\label{realtoint.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{379}\index{decimal to unary  379}\K{decimal to unary }\D{}(\>number, result\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}
 
\noindent Converts a decimal integer value to unary with base notation {\tt 1}.
\label{decimaltounary.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{385}\index{identifier  385}\K{identifier }\D{}(x+y\>)\DE{}= !\T{}AB..Za..z\TE{}! \D{}(x\>)\DE{}, !\T{}A..Za..z1..0\'\_\TE{}! * \D{}(y\>)\DE{}.}}
\L{\LB{\Proc{386}\index{letter digit sequence  386}\K{letter digit sequence }\D{}(x+y\>)\DE{}= !\T{}AB..Za..z\TE{}! \D{}(x\>)\DE{}, !\T{}A..Za..z1..0\TE{}! * \D{}(y\>)\DE{}.}}
\L{\LB{}}
\end{glammar}}
 
\noindent These scan  an identifier as specified but 
only a little more efficient.
\label{identifier.}
\label{letterdigitsequence.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{394}\index{upper case  394}\K{upper case }\D{}(\>str, result\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}
 
\noindent {\tt upper case} transformes a value with mixed cased letters to a upper cased value.
\label{uppercase.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{400}\index{lower case  400}\K{lower case }\D{}(\>str, result\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}
 
\noindent {\tt lower case} transformes a value with mixed cased letters to a lower cased value.
\label{lowercase.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{406}\index{keyword  406}\K{keyword }\D{}(\>\S{}\"upper case word\"\SE{})\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{}}
\end{glammar}}
 
\noindent Matches upper case word to the lower or mixed case input.
So keyword\verb+(>"IF")+ scans {\tt if}, {\tt IF}, {\tt If}, and {\tt iF}.
\label{keyword.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{414}\index{layout  414}\K{layout }= !\T{}\!n\!t\!f \TE{}!*\D{}(ignored\>)\DE{}. }}
\L{\LB{}}
\end{glammar}}
 
\noindent You can use this rule to skip spaces, tabs,  carriage returns, newlines, vertical tabs, and form feeds.
\label{layout.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{420}\index{type out  420}\K{type out }\D{}(\>affix)\DE{}=.}}
\L{\LB{}}
\end{glammar}}
 
\noindent Write the value of affix to stderr.
\label{typeout.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{426}\index{type in  426}\K{type in }\D{}(affix\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent Read affix from stdin.
\label{typein.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{432}\index{fail  432}\K{fail }= not equal \D{}(\>empty,\>empty)\DE{}.}}
\L{\LB{}}
\end{glammar}}

\noindent {\tt fail just always fails. 
\label{fail.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}\#plain\CE{}}}
\L{\LB{\Proc{439}\index{cut 439}\K{cut}= .}}
\L{\LB{}}
\end{glammar}}

\noindent This predicate forces to fail the next productions --- if any. 
This member may also be written as {\tt ->}, and can be removed
by adding complementary members to all other productions.
\label{cut.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{447}\index{eval affix  447}\K{eval affix }\D{}(\>a,evaluated a\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\noindent This predicate reduces the evaluate count at 
run time (see -r option) for deterministic grammars.
Nondeterministic grammars overwrite the result of an affix evaluation 
and restore the original value upon backtracking.
Since deterministic grammars do not need to backtrack the original value 
cannot be restored that easily. 
Instead, the result of the affix evaluation is lost which means 
that the same affix most be evaluated over and over again.
When you have interest in making your compiler as efficient as possible
and you know that some affixes are tested frequently you can first 
evaluate this affix and use the result in the rest of the computation.
\label{evalaffix.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{463}\index{set line file  463}\K{set line file }\D{}(\>line,\>file)\DE{}= ;}}
\L{\LB{set line file \D{}(\>line,\>file)\DE{}= .}}
\L{\LB{\Proc{465}\index{get line file  465}\K{get line file }\D{}(line\>,file\>)\DE{}= ;}}
\L{\LB{get line file \D{}(line\>,file\>)\DE{}= .}}
\L{\LB{}}
\end{glammar}}

\label{setlinefile.}
\label{getlinefile.}
\noindent Line and file control.
In order to produce correct messages when the input was
the output of a preprocessor there is a predicate which
sets the current file name and line number.
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{476}\index{get next option  476}\K{get next option }\D{}(option\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent This predicate gets the next option (the first one will be the command name) 
from the command line that invoked the program. 
It fails if all option are processed.
\label{getnextoption.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{484}\index{get env  484}\K{get env }\D{}(\>\S{}\"name\"\SE{}, val\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent {\tt get env} searches the value of the environment variable. 
It fails if the environment variable is not defined. 
\label{getenv.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{491}\index{error message  491}\K{error message }\D{}(val\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent {\tt error message} generates on error message based upon the 
most advanced input pointer.
It causes to surpress output generation,
and the exit status will be {\tt 1}.
It can also be used to implement error recovery.
\label{errormessage.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{500}\index{set exit code 500}\K{set exit code}=.}}
\L{\LB{}}
\end{glammar}}

\label{setexitcode.}
\noindent This predicates sets the exit code to {\tt 2},
but output generation is not surpressed. 
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{507}\index{assign  507}\K{assign }\D{}(\>x,\>y,old x\>)\DE{}=;}}
\L{\LB{assign \D{}(\>x,\>y,old x\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent {\tt assign} is a very tricky predicate and therefore its use is not recommended.
Basicly it serves for not needing to add an affix to each rule if
this affix changes in rare cases only.
If this is the case you can let a metanotion take another value,
although this sometimes give surprising results.
It  is for example in many cases necessary to copy the metanotion
(when putting it in tables etc.),
because of the fact that on an affix expression
containing  the  metanotion,
an assignation of that metanotion
has effect on previous evaluations of that affix expression
(consistent substitution is not guaranteed.)
\label{assign.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{526}\index{get from unix  526}\K{get from unix }\D{}(\>cmd, cmd stdout\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}
 
\noindent The most simple and reliable way to get some information from unix
is to give a command,  wait for the command to exit and store
the result it produced.
Examples of such unix utility programs are {\tt date, cat, ls} etc.
They all do not need any input.
\label{getfromunix.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{536}\index{set up connection to unix  536}\K{set up connection to unix }\D{}(\>cmd,\>channel)\DE{}=.}}
\L{\LB{\Proc{537}\index{talk to unix  537}\K{talk to unix }\D{}(\>channel,\>to the programs stdin,from the programs stdout\>)\DE{}=.}}
\L{\LB{}}
\end{glammar}}

\noindent These two builtins are only available on an unix-system.
They can be used to set up and maintain a connection 
to unix.
Only 32 suchs connection can be made at a time.
When this limit is exceeded {\tt setup connection to unix} fails.

Useful programs to connect with are for instance {\tt dc} for
arbitrary precision arithmetic, or perhaps a program 
written by yourself.
Also the lexicon interface is implemented with connections.
 
As an example we will maintain a connection to {\tt dc}.
First we set up the connection.
{\small
\begin{glammar}
\L{\LB{ \Proc{1}\K{s}\index{s1}:}}
\L{\LB{ set up connection with unix \D{}(\>\S{}\"dc \"\SE{},\>DC CON)\DE{}.}}
\end{glammar}}

Here DC CON is a metadefined affix specifying the channel number.
This channel is assigned to the metarule by the set up builtin;
initiative it may be defined as empty (eg : DC CON::.).
 
Next we can give input to this programs {\tt stdin} and get the answer from
the programs {\tt stdout}. For example   
{\small
\begin{glammar}
\L{\LB{  \Proc{2}\K{x}\index{x2}:}}
\L{\LB{    talk to unix \D{}(\>DC CON , \>\S{}\"1 2 +ps.\!n\"\SE{},\S{}\"3\"\SE{}\>)\DE{}.}}
\end{glammar}}
will succeed.
Because the builtin  {\tt talk to unix} first supplies input to the unix-program 
and then waits for the answer communication problems can occur.
To solve this problem a very simple (not very reliable)  strategy is used :
As soon as a control char is read (iscntr) the answer reading is stopped
and the result so far is  made the total result. Caveat:
the next time the builtin is called there might be some output left from previous
 calls.  Also one has to take care that there always will be an answer. 
For instance in the above example the newline in the input given to 
{\tt talk to unix} is essential because {\tt dc} waits for it  before generating
any output, so both processes would have been locked forever ("deadlock")
if this new line was omitted.
\label{setupconnectiontounix.}
\label{talktounix.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}
 
\noindent The following builtins are for internal usage and should therefore not be
used in your own grammar.
It is not possible to redefine these builtins and when its name is followed 
by an underscore it is also not possible to use the builtin  yourself.  
\label{resetinputptr.} 
\label{setinputptrto.}
\label{nestarset.}
\label{nestarset.}
\label{nestarset.}
\label{nestaralt.}
\label{metaterminal.}
\label{intersect.}
\label{explintersect.}
\label{transformlattice.}
\label{tltraditional.}
\label{tltraditional.}
\label{tltraditional.}
\label{transformlatticeterm.}
\label{tltraditionalterm.}
\label{tltraditionalterm.}
\label{tltraditionalterm.}
\label{initmint.}
\label{initmeta.}
\label{evalmeta.}
\label{getip.}
\label{restoreip.}
\label{falseip.}
\label{skip.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\Proc{617}\index{reset inputptr 617}\K{reset inputptr\_ }\D{}(\>saved ip)\DE{}= .}}
\L{\LB{\Proc{618}\index{set inputptr to 618}\K{set inputptr to\_ }\D{}(\>x,saved ip\>)\DE{}= .}}
\L{\LB{\Proc{619}\index{nestarset  619}\K{nestarset }\D{}(a\>)\DE{}= ;}}
\L{\LB{nestarset \D{}(a\>)\DE{}= ;}}
\L{\LB{nestarset \D{}(a\>)\DE{}= .}}
\L{\LB{\Proc{622}\index{nestaralt 622}\K{nestaralt\_ }\D{}(a\>,\>saved ip)\DE{}= .}}
\L{\LB{\Proc{623}\index{metaterminal  623}\K{metaterminal }\D{}(\>\S{}\"m\"\SE{})\DE{}=  \T{}"a"\TE{}.}}
\L{\LB{\Proc{624}\index{intersect 624}\K{intersect\_ }\D{}(\>a,\>b)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{625}\index{explintersect 625}\K{explintersect\_ }\D{}(\>a,\>b)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{626}\index{transform lattice 626}\K{transform lattice\_ }\D{}( \>a,\>b,c\>)\DE{}= .}}
\L{\LB{\Proc{627}\index{tl traditional 627}\K{tl traditional\_ }\D{}( \>a,\>b,c\>)\DE{}= ;}}
\L{\LB{tl traditional\_ \D{}( \>a,\>b,c\>)\DE{}= ;}}
\L{\LB{tl traditional\_ \D{}( \>a,\>b,c\>)\DE{}= .}}
\L{\LB{\Proc{630}\index{transform latticeterm 630}\K{transform latticeterm\_ }\D{}( \>a,\>b,c\>)\DE{}= .}}
\L{\LB{\Proc{631}\index{tl traditionalterm 631}\K{tl traditionalterm\_ }\D{}( \>a,\>b,c\>)\DE{}= ;}}
\L{\LB{tl traditionalterm\_ \D{}( \>a,\>b,c\>)\DE{}= ;}}
\L{\LB{tl traditionalterm\_ \D{}( \>a,\>b,c\>)\DE{}= .}}
\L{\LB{\Proc{634}\index{init mint 634}\K{init mint\_ }\D{}( \>a,\>b)\DE{}= .}}
\L{\LB{\Proc{635}\index{initmeta  635}\K{initmeta }\D{}( \>a,\>b)\DE{}= .}}
\L{\LB{\Proc{636}\index{evalmeta  636}\K{evalmeta }\D{}( \>a)\DE{}= .}}
\L{\LB{\Proc{637}\index{get ip 637}\K{get ip\_ }\D{}( ip\>)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{638}\index{restore ip 638}\K{restore ip\_ }\D{}( \>ip)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{639}\index{false ip 639}\K{false ip\_ }\D{}( \>ip)\DE{}= \T{}"a"\TE{}.}}
\L{\LB{\Proc{640}\index{skip 640}\K{skip\_}= ;}}
\L{\LB{skip\_= ;}}
\L{\LB{skip\_= .}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\noindent The following builtins implement multiple precision integer
arithmetic.
These are implemented using the unix standard package {\tt mp}.
Some implementations of unix do however not support 
this package.
More information can be found in the manual page for {\tt mp}.
\label{equalto.}
\label{lessthan.}
\label{morethan.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{656}\K{equal to }::\S{}\"0\"\SE{}.}}
\L{\LB{\Proc{657}\K{less than }::\S{}\"\-1\"\SE{}.}}
\L{\LB{\Proc{658}\K{more than }::\S{}\"1\"\SE{}.}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}

\label{intplusintisint.}
\label{intsubintisint.}
\label{inttimesintisint.}
\label{intdividedbyintisintwithremainderint.}
\label{intisint.}
\label{intraisedbyintmodulointisint.}
\label{intisthegcdofintandint.}
\label{intisthesquarerootofintwithremainderint.}
\label{intisdec.}
\label{decisint.}
\label{freeint.}
\label{decrementsmallint.}
\label{incrementsmallint.}
\label{smalldecisint.}
\label{intisnegative.}
\label{negateint.}
\label{intispositive.}
\label{intiszero.}
{\small
\begin{glammar}
\L{\LB{}}
\L{\LB{\Proc{680}\index{int plus int is int  680}\K{int }\D{}(\>a)\DE{} \K{plus int }\D{}(\>b)\DE{} \K{is int }\D{}(c\>)\DE{}=.}}
\L{\LB{\Proc{681}\index{int sub int is int  681}\K{int }\D{}(\>a)\DE{} \K{sub int }\D{}(\>b)\DE{} \K{is int }\D{}(c\>)\DE{}=.}}
\L{\LB{\Proc{682}\index{int times int is int  682}\K{int }\D{}(\>a)\DE{} \K{times int }\D{}(\>b)\DE{} \K{is int }\D{}(c\>)\DE{}=.}}
\L{\LB{\Proc{683}\index{int divided by int is int with remainder int  683}\K{int }\D{}(\>a)\DE{} \K{divided by int }\D{}(\>b)\DE{} \K{is int }\D{}(q\>)\DE{} \K{with remainder int }\D{}(r\>)\DE{}=.}}
\L{\LB{\Proc{684}\index{int is int  684}\K{int }\D{}(\>a)\DE{} \K{is }\D{}(c\>)\DE{} \K{int }\D{}(\>b)\DE{}=.}}
\L{\LB{\Proc{685}\index{int raised by int modulo int is int  685}\K{int }\D{}(\>a)\DE{} \K{raised by int }\D{}(\>b)\DE{} \K{modulo int }\D{}(\>d)\DE{} \K{is int }\D{}(r\>)\DE{}=.}}
\L{\LB{\Proc{686}\index{int is the gcd of int and int  686}\K{int }\D{}(c\>)\DE{} \K{is the gcd of int }\D{}(\>a)\DE{} \K{and int }\D{}(\>b)\DE{}=.}}
\L{\LB{\Proc{687}\index{int is the square root of int with remainder int  687}\K{int }\D{}(s\>)\DE{} \K{is the square root of int }\D{}(\>a)\DE{} \K{with remainder int }\D{}(r\>)\DE{}=.}}
\L{\LB{\Proc{688}\index{int is dec  688}\K{int }\D{}(\>a)\DE{} \K{is dec }\D{}(dec a\>)\DE{}=.}}
\L{\LB{\Proc{689}\index{dec is int  689}\K{dec }\D{}(\>a)\DE{} \K{is int }\D{}(int a\>)\DE{}=.}}
\L{\LB{\Proc{690}\index{free int  690}\K{free int }\D{}(\>d)\DE{}=.}}
\L{\LB{\Proc{691}\index{decrement small int  691}\K{decrement small int }\D{}(\>d)\DE{}=.}}
\L{\LB{\Proc{692}\index{increment small int  692}\K{increment small int }\D{}(\>d)\DE{}=.}}
\L{\LB{\Proc{693}\index{small dec is int  693}\K{small dec }\D{}(\>d)\DE{} \K{is int }\D{}(i\>)\DE{}=.}}
\L{\LB{\Proc{694}\index{int is negative 694}\K{int }\D{}(\>a)\DE{} \K{is negative}=.}}
\L{\LB{\Proc{695}\index{negate int  695}\K{negate int }\D{}(\>a)\DE{} =.}}
\L{\LB{\Proc{696}\index{int is positive 696}\K{int }\D{}(\>a)\DE{} \K{is positive}=.}}
\L{\LB{\Proc{697}\index{int is zero 697}\K{int }\D{}(\>a)\DE{} \K{is zero}=.}}
\L{\LB{}}
\L{\LB{}}
\end{glammar}}
\input{\jobname.ind}
\end{document}


