- program $\rightarrow$ declaration-list
-
declaration-list
$\rightarrow$ declaration-list declaration | declaration -
declaration
$\rightarrow$ var-declaration | fun-declaration -
var-declaration
$\rightarrow$ base-type id-list ; | base-type ID array-post ; | base-type ID array-post = { array-const-list } ; -
id-list
$\rightarrow$ id-list , ID | id-list , ID = expression | ID | ID = expression -
array-const-list
$\rightarrow$ array-const-list , single | single -
base_type
$\rightarrow$ int | double | float | char | bool -
fun-declaration
$\rightarrow$ base-type ID ( params ) compound-stmt | void ID ( params ) compound-stmt | extern base-type ID ( params ) | extern void ID ( params ) -
params
$\rightarrow$ param-list | void -
param-list
$\rightarrow$ param-list , param | param -
param
$\rightarrow$ base-type ID | base-type ID array-post-param -
array-post-param
$\rightarrow$ [ ] | [ NUM ] | array-post-param [ NUM ] -
compound-stmt
$\rightarrow$ { local-declarations statement-list } | { local-declarations } | { statement-list } | { } -
local-declarations
$\rightarrow$ local-declarations var-declaration | var-declaration -
statement-list
$\rightarrow$ statement-list statement | statement -
statement
$\rightarrow$ expression-stmt | compound-stmt | selection-stmt | iteration-stmt | return-stmt -
expression-stmt
$\rightarrow$ expression ; | ; -
selection-stmt
$\rightarrow$ if ( expression ) statement | if ( expression ) statement else statement -
iteration-stmt
$\rightarrow$ while-stmt | for-stmt -
while-stmt
$\rightarrow$ while ( expression ) statement -
for-stmt
$\rightarrow$ for ( expression ; expression ; expression ) statement -
return-stmt
$\rightarrow$ return ; | return expression ; -
expression
$\rightarrow$ var assop expression | operand -
assop
$\rightarrow$ = | += | -= | *= | /=| %=|^= | &= | |= | <<= | >>= - ==var
$\rightarrow$ ID | ID [ expression ]== 注意修改 -
operand
$\rightarrow$ operand || operand | operand && operand | operand | operand |operand ^ operand | operand & operand | operand = operand | operand != operand| operand < operand | operand > operand | operand <= operand | operand >= operand | operand << operand | operand >> operand | operand + operand | operand - operand | operand * operand | operand / operand | operand % operand | prefix ( operand ) | ( operand ) | prefix single | single -
prefix
$\rightarrow$ ! | ~ | - -
single
$\rightarrow$ var | call | NUM| DOUBLE | CHAR | TURE | FALSE -
call
$\rightarrow$ ID ( args ) -
args
$\rightarrow$ arg-list |$\boldsymbol{\epsilon}$ -
arg-list
$\rightarrow$ arg-list , expression | expression
以下下均为注释: