- program $\rightarrow$ declaration-list
-
declaration-list
$\rightarrow$ declaration-list declaration | declaration -
declaration
$\rightarrow$ var-declaration | fun-declaration -
var-declaration
$\rightarrow$ type-specifier ID ; | type-specifier ID [ NUM ] ; -
type-specifier
$\rightarrow$ int | void ==== -
fun-declaration
$\rightarrow$ type-specifier ID ( params ) compound-stmt -
params
$\rightarrow$ param-list | void -
param-list
$\rightarrow$ param-list , param | param -
param
$\rightarrow$ type-specifier ID | type-specifier ID [ ] -
compount-stmt
$\rightarrow$ { local-declarations statement-list } -
local-declarations
$\rightarrow$ local-declarations var-declaration |$\boldsymbol{\epsilon}$ -
statement-list
$\rightarrow$ statement-list statement |$\boldsymbol{\epsilon}$ -
statement
$\rightarrow$ expression-stmt | compound-stmt | selection-stmt | iteration-stmt | return-stmt -
expression
$\rightarrow$ expression ; | ; -
selection-stmt
$\rightarrow$ if ( expression**)** statement | if ( expression ) statement else statement -
iteration-stmt
$\rightarrow$ while ( expression ) statement ==== -
return-stmt
$\rightarrow$ return ; | return expression ; -
expression
$\rightarrow$ var = expression | simple-expression -
var
$\rightarrow$ ID | ID [ expression ] -
simple-expression
$\rightarrow$ additive-expression relop additive-expression | additive-expression -
relop
$\rightarrow$ <= | < | > | >= | == | != -
additive-expression
$\rightarrow$ additive-expression addop term | term -
addop
$\rightarrow$ +|- -
term
$\rightarrow$ term mulop factor | factor -
mulop
$\rightarrow$ ** * **| / -
factor
$\rightarrow$ ( expression ) | var | call | NUM -
call
$\rightarrow$ ID ( args ) -
args
$\rightarrow$ arg-list |$\boldsymbol{\epsilon}$ -
arg-list
$\rightarrow$ arg-list , expression | expression