Note: If the definition of a lexical element is in quotes, then it is meant to match exactly, the contained string. Otherwise, it is a regular expression. Square brackets in regular expressions are used as an abbreviation for matching ranges of letters. For example, [0-9] matches any digit, and [a-zA-Z] matches any English letter in capital or lower case.
Numbers, Literals, and Identifiers:
Symbols and Operators:
Keywords:
Built-in Procedures:
<program> ::= PROGRAM ident <declarations> BEGIN <statementSequence> END
<declarations> ::= VAR ident AS <type> SC <declarations>
| ε
<type> ::= ARRAY posnum OF INT
| INT
| BOOL
<statementSequence> ::= <statement> SC <statementSequence>
| ε
<statement> ::= <assignment>
| <ifStatement>
| <whileStatement>
| <writeInt>
<assignment> ::= <memCell> ASGN <expression>
| <memCell> ASGN READINT
<memCell> ::= ident
| ident LB <expression> RB
<ifStatement> ::= IF <expression> THEN <statementSequence> <elseClause> END
<elseClause> ::= ELSE <statementSequence>
| ε
<whileStatement> ::= WHILE <expression> DO <statementSequence> END
<writeInt> ::= WRITEINT <expression>
<expression> ::= <simpleExpression>
| <simpleExpression> OP4 <simpleExpression>
<simpleExpression> ::= <term> OP3 <term>
| <term>
<term> ::= <factor> OP2 <factor>
| <factor>
<factor> ::= <memCell>
| <literal>
| LP <expression> RP
<literal> ::= posnum
| zero
| negnum
| boollit