Picnic is a toy programming language, implemented in Java. It is an easy understanding programming language based on the book Introduction to Compiler Design, by Torben Ægidius Mogensen.
- The syntax of the language is given by a context free grammar.
- Only the production rules are explicitly given.
- The sets of terminals and non-terminals are obtained from the rules.
- The initial symbol is the non-terminal on the left side of the first production rule.
Production rule | Internal representation |
---|---|
Program → Funs | Program |
Funs → Fun | Sequence of Function definitions |
Funs → Fun Funs | |
Fun → TypeId ( TypeIds ) = Exp |
Function definition |
TypeId → bool id |
Type and identififier |
TypeId → int id |
|
TypeIds → TypeId | Sequence of types and identifiers |
TypeIds → TypeId TypeIds | |
Exp → num |
Expressions |
Exp → id |
|
Exp → Exp + Exp |
|
Exp → Exp < Exp |
|
Exp → id ( Exps ) |
|
Exp → if Exp then Exp else Exp |
|
Exp → let id = Exp in Exp |
|
Exps → Exp | Sequence of expressions |
Exps → Exp , Exps |