Grammar for mini-Python:
- Program := Statement | Statement Program
- Statement := DefStatement | IfStatement | ReturnStatement | PrintStatement | WhileStatement | AssignStatment | FunctionCall
- DefStatement := def identifier ( ArgList ) : Sequence
- ArgList := identifier Arglist | ε
- MoreArgs := , identifier MoreArgs | ε
- IfStatement := if Expression : Sequence else : Sequence
- WhileStatement := while Expression : Sequence
- ReturnStatement := return Expression NEWLINE
- PrintStatement := print Expression NEWLINE
- AssignStatement := identifier = Expression NEWLINE
- Sequence := NEWLINE INDENT MoreStatements DEDENT
- MoreStatements := Statement MoreStatements | Statement
- Expression := AdditionExpression Comparison
- Comparison := (<|>|<=|>=|==) AdditionExpression Comparison | ε
- AdditionExpression := MultiplicationExpression AdditionFactor
- AdditionFactor := (+|-) MultiplicationExpression AdditionFactor | ε
- MultiplicationExpression := ElementExpression MultiplicationFactor
- MultiplicationFactor := (*|/) ElementExpression MultiplicationFactor | ε
- ElementExpression := PrimitiveExpression ElementAccess
- ElementAccess := [ Expression ] ElementAcess | ε
- FunctionCallExpression := PrimitiveExpression ( ExpressionList )
- ExpressionList := Expression MoreExpressions | ε
- MoreExpressions := , Expression MoreExpressions | ε
- PrimitiveExpression := Integer | NAME | ( Expression ) | ListExpression | BAR Expression BAR
- FunctionCallStatement := PrimitiveExpression ( ExpressionList ) NEWLINE