Defining Program Syntax: Chapter Two Modern Programming Languages, 2nd Ed. 1
Defining Program Syntax: Chapter Two Modern Programming Languages, 2nd Ed. 1
( <exp> )
( <exp> ) c
<exp> + <exp>
a b
a production
<NP> ::= <A> <N>
tokens
Chapter Two Modern Programming Languages, 2nd ed. 10
BNF Grammar Definition
A BNF grammar consists of four parts:
– The set of tokens
– The set of non-terminal symbols
– The start symbol
– The set of productions
a+b
a*b+c
(a+b)
(a+(b))
if-stmt
if expr then stmt else stmt
if-stmt
if expr then stmt else stmt
DoStatement:
do Statement while ( Expression ) ;
BasicForStatement:
for ( ForInitopt ; Expressionopt ; ForUpdateopt)
Statement