# The new takeon found this legitimate error!

# * Error: P<BooleanwordA> can left-recurse indirectly through <BooleanwordD>

# Main cheats - it invokes the parsing routines explicitly,
# in order to reduce the size of the parse tree for a whole
# file.  Also allows recovery of errors at useful boundaries

B<eof> = 0;
B<nl> = 1;

P<SS> = ;

P<Actual> =
    <Expression>
|   <Wordreference>
|   <Destination>
|   <Name> ;


P<Actuallist> =
    <Actual> <RestofActuallist> ;

P<RestofActuallist> =
    ',' <Actual> <RestofActuallist>
|   ;

P<Addoperator> =
    '+'
|   '-' ;


P<Alternative> =
    <Statement> ;


P<Answerspec> =
    <Numbertype>
|   ;


P<Answerstatement> =
    "a̲n̲s̲w̲e̲r̲" <Expression> ;


P<Arraydec> =
    <Numbertype> "a̲r̲r̲a̲y̲" <Arraylist> <Presetlist> ;


P<Arrayitem> =
    <Idlist> '[' <Sizelist> ']' ;


P<Arraylist> =
    <Arrayitem> <RestofArraylist> ;

P<RestofArraylist> =
    ',' <Arrayitem> <RestofArraylist>
|   ;


P<Assignmentstatement> =
    <Variable> ':=' <Expression>
|   <Macrocall> ':=' <Expression> ;


P<Base> =
    '(' <Id> ')'
|   <Id> '[' <Signedinteger> ']' ;


P<Bitposition> = <Integer> ;


P<Block> =
    "b̲e̲g̲i̲n̲" ;


P<Booleanword> =
    <Typedprimary> <RestofBooleanexpr> ;

P<RestofBooleanexpr> =
    <Boolop> <Typedprimary> <RestofBooleanexpr>
|   ;

P<Boolop> =
    "d̲i̲f̲f̲e̲r̲"
|   "u̲n̲i̲o̲n̲"
|   "m̲a̲s̲k̲"
|   "s̲r̲l̲"
|   "s̲l̲l̲" ;

P<OldBooleanword> =
    <BooleanwordA>
|   <BooleanwordC> "d̲i̲f̲f̲e̲r̲" <BooleanwordD> ;


P<BooleanwordA> =
    <BooleanwordB>
|   <BooleanwordD> "u̲n̲i̲o̲n̲" <BooleanwordE> ;


P<BooleanwordB> =
    <BooleanwordE> "m̲a̲s̲k̲" <Typedprimary> ;


P<BooleanwordC> =
    <Booleanword>
|   <Typedprimary> ;


P<BooleanwordD> =
    <BooleanwordA>
|   <Typedprimary> ;


P<BooleanwordE> =
    <BooleanwordB>
|   <Typedprimary> ;


P<Bracketedcomment> =
    «\([^\)]*\)» 
|   ;

P<Codesequence> =
    «\<[^\>]*\>» ;

P<Codestatement> =
    "c̲o̲d̲e̲" "b̲e̲g̲i̲n̲" <Codesequence> "e̲n̲d̲" <endtag> ;


P<Commentsentence> =
    "c̲o̲m̲m̲e̲n̲t̲" «[^;]*» ;

P<clines> =
    «[^;]*» <nl> <clines>
|   ;

P<Commoncommunicator> =
    <exttype> '(' <Commonitemlist> ')' ;

P<exttype> =
    "c̲o̲m̲m̲o̲n̲"
|   "e̲x̲t̲e̲r̲n̲a̲l̲" ;

P<Commonitem> =
    <Datadec>
|   <Overlaydec>
|   <Placespec>
|   <Procedurespec>
|   <Commentsentence> ;


P<Commonitemlist> =
    <Commonitem> ';' <RestofCommonitemlist> ;

P<RestofCommonitemlist> =
    <Commonitem> ';' <RestofCommonitemlist>
|   ;

P<Comparator> =
    '='
|   '>='
|   '>'
|   '<='
|   '<>'
|   '<' ;


P<Comparison> =
    <Simpleexpression> <Comparator> <Simpleexpression> ;

P<Compoundstatement> =
    "b̲e̲g̲i̲n̲" ;

P<Condition> =
    <SubCondition> <RestofCondition> ;

P<RestofCondition> =
    "o̲r̲" <SubCondition> <RestofCondition>
|   ;


P<Conditionalexpression> =
    "i̲f̲" <Condition> "t̲h̲e̲n̲" <Expression> "e̲l̲s̲e̲" <Expression> ;


P<Conditionalstatement> =
    "i̲f̲" <Condition> "t̲h̲e̲n̲" <LabelledStatement> <RestofConditionalstatement> ;

P<RestofConditionalstatement> =
    "e̲l̲s̲e̲" <Alternative>
|   ;

P<Constant> =
    <Number>
|   <Addoperator> <Number>
|   <Expression> ;


P<Constantlist> =
    <Group> <RestofConstantlist> ;

P<RestofConstantlist> =
    ',' <Group> <RestofConstantlist>
|   ;

P<Datadec> =
    <Numberdec>
|   <Arraydec>
|   <Tabledec> ;


P<Dec> =
    <Datadec>
|   <Overlaydec>
|   <Switchdec>
|   <Proceduredec> ;


P<Declist> =
    <Dec> <RestofDeclist> ;

P<RestofDeclist> =
    ';' <Dec> <RestofDeclist>
|   ;

P<Destination> =
    <Label>
|   <Switch> '[' <Index> ']' ;


P<Digit> =
    «[0-9]» ;

P<Digitlist> =
    «[0-9][0-9]*» ;

P<Dimension> =
    <Lowerbound> ':' <Upperbound> ;


P<Dummystatement> =
    <?term><!eof> ;

P<term> = ';'
|     "e̲n̲d̲" <endtag>
|     "e̲l̲s̲e̲" ;

P<likesemi> =
    ';'
|   <?term> ;

P<Elementdec> =
    <Id> <Numbertype> <Wordposition>
|   <Id> <Partwordtype> <Wordposition> ',' <Bitposition> ;


P<Elementdeclist> =
    <Elementdec> <RestofElementdeclist> ;

P<RestofElementdeclist> =
    ';'  <Elementdeclist>
|   ;

P<Elementpresetlist> =
    "p̲r̲e̲s̲e̲t̲" <Constantlist>
|   ;

P<Elementscale> =
    '(' <Totalbits> ',' <Fractionbits> ')'
|   '(' <Totalbits> ')' ;


P<Endcomment> =
    <Id> ;


P<Expression> =
    <Unconditionalexpression>
|   <Conditionalexpression> ;


P<Factor> =
    <Primary> <!Boolop>
|   <Booleanword> ;


P<Forelement> =
    <Expression> "w̲h̲i̲l̲e̲" <Condition>
|   <Expression> "s̲t̲e̲p̲" <Expression> "u̲n̲t̲i̲l̲" <Expression>
|   <Expression> ;


P<Forlist> =
    <Forelement> <RestofForlist> ;

P<RestofForlist> =
    ',' <Forelement> <RestofForlist>
|   ;

P<Formalpair> =
    <Id> ':' <Id> ;

P<Formalpairlist> =
    <Formalpair> <RestofFormalpairlist> ;

P<RestofFormalpairlist> =
    ',' <Formalpair> <RestofFormalpairlist>
|   ;

P<Forstatement> =
    "f̲o̲r̲" <Wordreference> ':=' <Forlist> "d̲o̲" <Statement> ;


P<Fractionbits> =
    <Signedinteger> ;


P<Gotostatement> =
    "g̲o̲t̲o̲" <Destination> ;

P<Group> =
    <Constant>
|   '(' <Constantlist> ')'
|   ;

P<Id> =
    «[a-z][_a-z0-9]*» ;

P<Idlist> =
    <Id> <RestofIdlist> ;

P<RestofIdlist> =
    ',' <Idlist>
|   ;

P<Index> =
    <Expression> ;


P<Integer> =
    <Digitlist>
|   "h̲e̲x̲" '(' <Hexlist> ')'
|   "o̲c̲t̲a̲l̲" '(' <Octallist> ')'
|   "l̲i̲t̲e̲r̲a̲l̲" '(' «.» ')' ;

P<Hexlist> =
    «[a-f0-9][a-f0-9]*» ;


P<Label> =
    <Id> ;


P<Labellist> =
    <Label> <RestofLabellist> ;

P<RestofLabellist> =
    ',' <Labellist>
|   ;

P<Length> =
    <Integer> ;


P<Letter> =
    «[a-z]» ;

P<Letterdigitstring> =
    «[a-z0-9]*» ;

P<Lowerbound> =
    <Signedinteger> ;


P<Macrobody> =
    «[^\"]*» ;

P<Macrocall> =
    <Macroname> '(' <Macrostringlist> ')'
|   <Macroname> <!lbrack> ;


P<Macrodefinition> =
    "d̲e̲f̲i̲n̲e̲" <Macroname> '\'' <Macrobody> '"' <OptDefCom> 
|   "d̲e̲f̲i̲n̲e̲" <Macroname> '(' <Idlist> ')' '"' <Macrobody> '"' <OptDefCom> ;

P<OptDefCom> =
    ';' «\([^\)]*\)» 
|   ';' ;

P<Macrodeletion> =
    "d̲e̲l̲e̲t̲e̲" <Macroname> ';' ;


P<Macroname> =
    <Id> ;


P<Macrostring> =
    «[^\)]*» ;

P<Macrostringlist> =
    <Macrostring> <RestofMacrostringlist> ;

P<RestofMacrostringlist> =
    ',' <Macrostring> <RestofMacrostringlist> 
|   ;

P<Multoperator> =
    '*' 
|   '/' ;


P<Name> =
    <Id> ;


P<Number> =
    <Real> 
|   <Integer> ;


P<Numberdec> =
    <Numbertype> <Idlist> <Presetlist> ;


P<Numbertype> =
    "f̲l̲o̲a̲t̲i̲n̲g̲" 
|   "f̲i̲x̲e̲d̲" <Scale> 
|   "l̲o̲n̲g̲i̲n̲t̲e̲g̲e̲r̲" 
|   "i̲n̲t̲e̲g̲e̲r̲" 
|   "c̲o̲n̲s̲t̲a̲n̲t̲" 
|   "b̲y̲t̲e̲" ;

P<Octaldigit> =
    «[0-7]» ;

P<Octallist> =
    «[0-7][0-7]*» ;

P<Overlaydec> =
    "o̲v̲e̲r̲l̲a̲y̲" <Base> "w̲i̲t̲h̲" <Datadec> ;


P<Parameterspec> =
    "v̲a̲l̲u̲e̲" <Formalpairlist> 
|   "l̲o̲c̲a̲t̲i̲o̲n̲" <Formalpairlist> 
|   <Specifier> <Idlist> 
|   <Tablespec> 
|   <Procedurespec> ;


P<Parameterspeclist> =
    <Parameterspec> <RestofParameterspeclist> ;

P<RestofParameterspeclist> =
    ';' <Parameterspeclist> 
|   ;

P<Partword> =
    <Id> '[' <Index> ']' 
|   "b̲i̲t̲s̲" '[' <Totalbits> ',' <Bitposition> ']' <Typedprimary> ;


P<Partwordreference> =
    <Id> '[' <Index> ']' 
|   "b̲i̲t̲s̲" '[' <Totalbits> ',' <Bitposition> ']' <Wordreference> ;


P<Partwordtype> =
    <Elementscale> 
|   "u̲n̲s̲i̲g̲n̲e̲d̲" <Elementscale> ;


P<Placespec> =
    "l̲a̲b̲e̲l̲" <Idlist> 
|   "s̲w̲i̲t̲c̲h̲" <Idlist> ;


P<Presetlist> =
    ':=' <Constantlist> 
|   ;

P<Primary> =
    <Untypedprimary> 
|   <Typedprimary> ;


P<Procedurecall> =
    <Id> '(' <Actuallist> ')' <!ass> 
|   <Id> <!lbrack> <!ass> ;


P<Proceduredec> =
    <Answerspec> <Recursive> <Procedureheading> <?term> ;

P<Recursive> =
    "r̲e̲c̲u̲r̲s̲i̲v̲e̲" 
|   "p̲r̲o̲c̲e̲d̲u̲r̲e̲" ;

P<Procedureheading> =
   <Id> '(' <Parameterspeclist> ')' 
|  <Id> ;

P<Procedurespec> =
    <Answerspec> "p̲r̲o̲c̲e̲d̲u̲r̲e̲" <Procparamlist> ;

P<Procparameter> =
    <Id> '(' <Typelist> ')' 
|   <Id> ;


P<Procparamlist> =
    <Procparameter> <RestofProcparamlist> ;

P<RestofProcparamlist> =
    ',' <Procparameter> <RestofProcparamlist> 
|   ;

P<Real> =
    <Digitlist> '.' <Digitlist> <subten> <Signedinteger> 
|   <Digitlist> '.' <Digitlist> 
|   <Digitlist> <subten> <Signedinteger> 
|   <subten> <Signedinteger> <!Id> <!lbrack> 
|   "o̲c̲t̲a̲l̲" '(' <Octallist> '.' <Octallist> ')' ;

P<subten> =
    '@' 
|   'e' ;

P<lbrack> =
    '(' 
|   '[' ;

P<Scale> =
    '(' <Totalbits> ',' <Fractionbits> ')' ;


P<Sign> =
    '+'
|   '-'
|   ;

P<Signedinteger> =
    <Integer> 
|   <Addoperator> <Integer> ;


P<Simpleexpression> =
    <Term> <RestofSimpleexpression> 
|   <Addoperator> <Term> <RestofSimpleexpression> ;

P<RestofSimpleexpression> =
    <Addoperator> <Term> <RestofSimpleexpression> 
|   <!Boolop> ;


P<Sizelist> =
    <Dimension> ',' <Dimension> 
|   <Dimension> ;


P<Specifier> =
    "v̲a̲l̲u̲e̲" <Numbertype> 
|   "l̲o̲c̲a̲t̲i̲o̲n̲" <Numbertype> 
|   <Numbertype> "a̲r̲r̲a̲y̲" 
|   "l̲a̲b̲e̲l̲" 
|   "s̲w̲i̲t̲c̲h̲" ;


P<Specimen> =
    "a̲l̲p̲h̲a̲" <Sign> 
|   "b̲e̲t̲a̲" <Sign> ;


P<Simplestatement> =
    <Assignmentstatement> 
|   <Gotostatement> 
|   <Procedurecall> 
|   <Answerstatement> 
|   <Codestatement> 
|   <Compoundstatement> 
|   <Block> ;


P<LabelledStatement> =
    <Labels> <Simplestatement> ;

P<Labels> =
    <Label> <!ass> ':'  <Labels> 
|   ;

P<ass> = ':=' ;

P<Statement> =
    <LabelledStatement> 
|   <Conditionalstatement> 
|   <Forstatement> 
|   <Commentsentence> ;

P<endtag> =
    <!else> «[^;]*» 
|   ;

P<else> = "e̲l̲s̲e̲" ;

P<Statementlist> =
    <eof> 
|   <nl> 
|   <Labels> ';' 
|   "b̲e̲g̲i̲n̲" 
|   "e̲n̲d̲" "e̲l̲s̲e̲" "b̲e̲g̲i̲n̲" 
|   "e̲n̲d̲" "e̲l̲s̲e̲" <Alternative> 
|   "e̲n̲d̲" <endtag> 
|   <Macrodefinition> 
|   <Macrodeletion> 
|   "i̲n̲c̲l̲u̲d̲e̲" «"[^"]*";» 
|   <Dec> ';' <Bracketedcomment> 
|   <Statement> <likesemi> <Bracketedcomment> 
|   <Commoncommunicator> 
|   «[^;]*;» 
|   «.*END» 
|   «.*ELSE» 
|   «.*\)» 
|   «.*» <eof> 
|   «.*» ;

P<RestofStatementlist> =
    ';' <Statement> <RestofStatementlist> 
|   ;

P<String> =
    «\"[^\"]*\"» ;

P<SubCondition> =
    <Comparison> <RestofSubcondition> ;

P<RestofSubcondition> =
    "a̲n̲d̲" <Comparison> <RestofSubcondition> 
|   ;

P<Switch> =
    <Id> ;


P<Switchdec> =
    "s̲w̲i̲t̲c̲h̲" <Switch> ':=' <Labellist> ;


P<Tabledec> =
    "t̲a̲b̲l̲e̲" <Id> '[' <Width> ',' <Length> ']' <Tablerest> ;

P<Tablerest> =
    '[' <Elementdeclist> <Elementpresetlist> ']' <Presetlist> ;

P<Tablespec> =
    "t̲a̲b̲l̲e̲" <Id> '[' <Width> ',' <Length> ']' '[' <Elementdeclist> ']' ;


P<Term> =
    <Factor> <RestofTerm> ;

P<RestofTerm> =
    <Multoperator> <Factor> <RestofTerm> 
|   <!Boolop> ;


P<Totalbits> =
    <Integer> ;


P<Type> =
    <Specifier> 
|   "t̲a̲b̲l̲e̲" 
|   <Answerspec> "p̲r̲o̲c̲e̲d̲u̲r̲e̲" ;


P<Typedprimary> =
    <Procedurecall> 
|   <Macrocall> 
|   <Wordreference> 
|   <Partword> 
|   "l̲o̲c̲a̲t̲i̲o̲n̲" '(' <Wordreference> ')' 
|   <Numbertype> '(' <Expression> ')' 
|   <Integer> ;


P<Typelist> =
    <Type> <RestofTypelist> ;

P<RestofTypelist> =
    ',' <Type> <RestofTypelist> 
|   ;

P<Unconditionalexpression> =
    <Simpleexpression> 
|   <String> ;


P<Untypedprimary> =
    <Real> 
|   '(' <Expression> ')' ;


P<Upperbound> =
    <Signedinteger> ;


P<Variable> =
    <Wordreference> 
|   <Partwordreference> ;


P<Width> =
    <Integer> ;


P<Wordposition> =
    <Signedinteger> ;


P<Wordreference> =
    <Id> '[' <Index> ',' <Index> ']' 
|   <Id> '[' <Index> ']' 
|   <Macrocall> 
|   <Id> 
|   '['  ']' ;

E
