%\filename{SynChart-example.tex}
%\edited{by stolfi on Fri Dec 27 13:31:42 1985}

% Exerciser for my version of Mike Plass's syntax chart macros

\input SynChart

\font\NonTerminalFont=amti10 \relax
\font\TerminalFont=amtt10 \relax
\font\KeywordFont=amtt10 \relax

\SyntaxChart

\hsize=7.3in
\hoffset=-0.4in

% Spacing between alternatives:

\AltSpacing=2

% Turn off the right arrows because they make the charts too wide.

\OmitRightArrows

% What to do with multiline charts:

\MinLineWidth=0pt

% Useful abbreviations:

\def\N#1{\NonTerminal{\Strut #1\/}}
\def\T#1{\Terminal{\OpStrut #1}}
\def\K#1{\Keyword{\Strut #1}}

\def\Optional#1{\Alternatives{\Middle{#1}\Lower{\Arrow}}}
\def\Rept#1{\Repeat{\Upper{\Arrow}\Middle{#1}}}
\def\Star#1{\Repeat{\Upper{#1}\Middle{\Arrow}}}

\def\TwoAlts#1#2{\Alternatives{\Upper{#1}\Lower{#2}}}
\def\RAW#1#2{\Repeat{\Upper{#1}\Middle{#2}}} % Repeat Above With
\def\RBW#1#2{\Repeat{\Middle{#2}\Lower{#1}}} % Repeat Below With

\catcode`\:=\active \let:=\Fil
\def\-{\UULine}

\def\lpar{\T{\kern-1.5pt(\kern1.5pt}} \def\rpar{\T{\kern1.5pt)\kern-1.5pt}}
\def\lbrak{\T{\kern-1pt[\kern1pt}} \def\rbrak{\T{\kern1pt]\kern-1pt}}
\def\comma{\T{,}}
\def\colon{\T{\char`:}}
\def\eq{\T{=}}
\def\semicolon{\T{;}}
\def\period{\T{.}}
\def\gets{\T{\raise 1pt\hbox{\char`:}=}}
\def\dotdot{\T{.\kern-1.5pt.}}

\def\constant{\N{constant}}
\def\type{\N{type}}
\def\statement{\N{statement}}
\def\id{\N{identifier}}
\def\idlist{\RAW\comma\id}
\def\expression{\N{expression}}
\def\variable{\N{variable}}

\Define{Program}
\Fil
\K{program}\id\lpar\RAW\comma\id\rpar\semicolon\N{block}\period
\Fil\Fil
\EndDef

\def\blockbody{\K{begin}\-\RAW\semicolon\statement\-\K{end}}

{ % Block

\def\labelpart{\K{label}\-\RAW\comma{\N{unsigned integer}}\-\semicolon}

\def\constpart{\K{const}\-\Rept{\id\eq\constant\semicolon}}

\def\typepart{\K{type}\-\Rept{\id\eq\type\semicolon}}

\def\varpart{\K{var}\-\Rept{\-\idlist\-\colon\type\semicolon}}

\def\prochead{\N{procedure head}}
\def\funchead{\N{function head}}
\def\pfhead{\Alternatives{\Upper{\prochead}\Lower{\funchead}}}

\def\pfdeclpart{\Rept{\-\pfhead\-\semicolon\N{block}\semicolon}}

\Define{Block}
\OptionalLines{
\Line{\Arrow\-\labelpart:}
\Line{\Arrow\-\constpart:}
\Line{\Arrow\-\typepart:}
\Line{\Arrow\-\varpart:}
\Line{\Arrow\-\pfdeclpart:}
}
\Arrow\-\blockbody\Fil\Fil
\EndDef

} % end of Block

\vfil\eject

{ % Declaration Extras

\def\simpletype{\N{simple type}}

\def\typelist{\lbrak\RAW\comma{\simpletype}\rbrak}

\Define{Type}
\Fil
\Alternatives{
\Upper{\Arrow\-\simpletype:}
\Upper{\Arrow\-\T{\char`\^}\N{type identifier}:}
\Middle{\Arrow\Optional{\K{packed}}\K{array}\typelist\K{of}\type:}
\Lower{\Arrow\-\K{file}\K{of}\type:}
\Lower{\Arrow\-\K{set}\K{of}\simpletype:}
\Lower{\Arrow\-\K{record}\N{field list}\K{end}:}
}
\Fil\Fil
\EndDef

\Define{Simple type}
\Fil
\Alternatives{
\Upper{\N{type identifier}}
\Middle{\lpar\idlist\rpar}
\Lower{\constant:\dotdot:\constant}
}
\Fil\Fil
\EndDef

\def\varianthead{\K{case}:\Optional{\id:\colon}:\N{type identifier}:\K{of}}

\Define{Field list}
\Fil
\Rept{\-\Optional{\idlist\colon\type}\semicolon}
\NewLine
\Optional{\varianthead:\RAW\semicolon{\-\Optional{
\RAW\comma\constant\colon\lpar\N{field list}\rpar
}\-}}
\Fil
\EndDef

\def\funorvar{\Alternatives{
\Upper{\K{function}}\Middle{\Arrow}\Lower{\K{var}
}}}

\def\formalparmgroup{\Alternatives{
\Middle{\funorvar\-\idlist\-\colon\N{type identifier}}
\Lower{\K{procedure}\-\RBW\comma\id:}
}}

\Define{Parameter list}
\Fil
\Optional{\lpar\-\RAW\semicolon{\-\formalparmgroup\-}\-\rpar}
\Fil\Fil
\EndDef

} % end of Declaration Extras
\vfil\eject

{ % Statement

\def\varorfunid{\TwoAlts{\N{variable}}{\N{function identifier}}}

\def\assignment{\varorfunid\gets\expression}

\def\procid{\N{procedure identifier}}

\def\actualarg{\Alternatives{\Middle{\expression}\Lower{\procid}}}

\def\actualarglist{\lpar\-\RAW\comma{\-\actualarg\-}\-\rpar}

\def\proccall{\procid\Optional{\actualarglist}}

\def\ifstatement{\K{if}\expression\K{then}\statement
\Optional{\K{else}\statement}
}

\def\casepart{\-\RBW\comma\constant\-\colon:\statement}
\def\cases{\Optional{\RAW\semicolon\casepart}}
\def\casestatement{\K{case}\expression\K{of}\cases\K{end}}

\def\whilestatement{\K{while}\expression\K{do}\statement}

\def\repeatstatement{\K{repeat}\-\RAW\semicolon\statement\-
\K{until}\expression
}

\def\toordownto{\TwoAlts{\K{to}}{\K{downto}}}
\def\forstatement{\K{for}\N{variable identifier}\gets\expression
\toordownto\expression\K{do}\statement
}

\def\withstatement{\K{with}\-\RAW\comma\variable\-\K{do}\statement}

\def\gotostatement{\K{goto}\N{unsigned integer}}

\Define{Statement}
\Fil
\UULine\UULine\Optional{\N{unsigned integer}\colon}\-\NewLine
\Fil\Alternatives{
\Middle{\Arrow:}
\Lower{\Arrow\-\assignment:}
\Lower{\Arrow\-\proccall:}
\Lower{\Arrow\-\blockbody:}
\Lower{\Arrow\-\ifstatement:}
\Lower{\Arrow\-\casestatement:}
\Lower{\Arrow\-\whilestatement:}
\Lower{\Arrow\-\repeatstatement:}
\Lower{\Arrow\-\forstatement:}
\Lower{\Arrow\-\withstatement:}
\Lower{\Arrow\-\gotostatement:}
}
\Fil\Fil
\EndDef

} % end of Statement

\vfil\eject

{ % Expression

\def\relop{{\Fil\OmitArrows
\HorzAlternatives
{\Alternative{\T{=}}
\Alternative{\T{<}}
\Alternative{\T{>}}
\Alternative{\T{<>}}
\Alternative{\T{<=}}
\Alternative{\T{>=}}
\Alternative{\K{in}}}}}

\Define{Expression}
\Fil
\N{simple expression}
\Optional{\relop:\N{simple expression}}
\Fil\Fil
\EndDef

\Define{Simple expression}
\Fil
\Alternatives{\Upper{\T{+}}\Middle{\Empty}\Lower{\T{-}}}\-
\Repeat{\Upper{\T{+}}\Upper{\T{-}}\Middle{\N{term}}\Lower{\K{or}}}
\Fil\Fil\Fil
\EndDef

\def\mulop{{\OmitArrows
\HorzAlternatives
{\Alternative{\T{*}}
\Alternative{\T{/}}
\Alternative{\K{div}}
\Alternative{\K{mod}}
\Alternative{\K{and}}}}}

\Define{Term}
\Fil
\N{factor}\Optional{\Rept{\-\mulop\N{factor}}}
\Fil\Fil\Fil\Fil
\EndDef

\def\actualarglist{\Optional{\lpar\-\RAW\comma\expression\-\rpar}}

\def\indexrangelist{\RAW\comma{\expression\Optional{\dotdot\expression}\-}}

\Define{Factor}
\Fil
\Alternatives{
\Upper{:\N{unsigned constant}:}
\Upper{:\variable:}
\Upper{:\lpar\expression\rpar:}
\Middle{\N{function identifier}\actualarglist:}
\Lower{:\K{not}\N{factor}:}
\Lower{:\lbrak\indexrangelist\rbrak:}
}
\Fil\Fil
\EndDef

\Define{Variable}
\Fil
\TwoAlts{\N{variable identifier}}{\N{field identifier}}
\-
\Repeat{\Upper{\T{\char`\^}}
\Middle{\Empty}
\Lower{\N{selector}}}
\Fil\Fil
\EndDef

\Define{Selector}\Fil
\Alternatives
{\Upper{\period\N{field identifier}}
\Lower{\-\lbrak\RBW\comma\expression\rbrak\-}}
\Fil\Fil\EndDef
} % end of Expression

\def\singlequote{\char'015} % symmetric single quote in tty font.

\def\character{\Alternatives{
\Upper{\N{character}}
\Lower{\T{\singlequote\singlequote}}
}}

\def\constornum{\TwoAlts{\N{constant identifier}}{\N{unsigned number}}}

\def\sign{\Alternatives{\Upper{\T{+}}\Middle{\Arrow}\Lower{\T{-}}}}

\def\signedconst{\sign\-\constornum}

\def\stringliteral{\-\T{\singlequote}\Rept{\-\character\-}\T{\singlequote}\-}

\Define{Constant}\Fil
\TwoAlts{\signedconst}{\stringliteral}
\Fil\Fil\EndDef

\Define{Unsigned constant}\Fil
\Alternatives{
\Upper{\N{constant identifier}}
\Upper{\N{unsigned number}}
\Middle{:\K{nil}::}
\Lower{\stringliteral}
}
\Fil\Fil\EndDef

\def\digits{\Rept{\N{digit}}}

\Define{Unsigned number}\Fil
\digits\-\Optional{\period\-\digits}\-\Optional{\T{E}\-\sign\-\digits}
\Fil\Fil\EndDef

\Define{Unsigned integer}\Fil
\digits
\Fil\Fil\Fil\EndDef

\Define{Identifer}\Fil
\N{letter}\-
\Repeat{\Upper{\N{letter}}\Middle{\Arrow}\Lower{\N{digit}}}
\Fil\Fil\EndDef


\vfill\bye