This is the grammar for CLite, a small subset of a C/Java like language that
include expressions, loops, assignment statements, and conditional statements.
The non-terminal Program is the start symbol. Symbols that
are bold and
blue are
EBNF symbols and not terminals (tokens) in CLite.
Program ⇒ int main ( ) { Declarations Statements }
Declarations ⇒ { Declaration }
Declaration ⇒ Type Identifier ;
Type ⇒ int | bool | float | char
Statements ⇒ { Statement }
Statement ⇒ ; | Block | Assignment | IfStatement | WhileStatement
Block ⇒ { Statements }
Assignment ⇒ Identifier = Expression ;
IfStatement ⇒ if ( Expression ) Statement [ else Statement ]
WhileStatement ⇒ while ( Expression ) Statement
Expression ⇒ Conjunction { || Conjunction }
Conjunction ⇒ Equality { && Equality }
Equality ⇒ Relation [ EquOp Relation ]
EquOp ⇒ == | !=
Relation ⇒ Addition [ RelOp Addition ]
RelOp ⇒ < | <= | > | >=
Addition ⇒ Term { AddOp Term }
AddOp ⇒ + | -
Term ⇒ Factor { MulOp Factor }
MulOp ⇒ * | / | %
Factor ⇒ [ UnaryOp ] Primary
UnaryOp ⇒ - | !
Primary ⇒ Identifier | IntLit | FloatLit | ( Expression )