| letter |
::= |
a | b |
... | z | A
| B |
... | Z |
| digit |
::= |
0 | 1 |
... | 9 |
| id |
::= |
letter { letter | digit
| _ } |
| intcon |
::= |
digit { digit } |
| charcon |
::= |
'ch'
| '\n'
| '\0',
where ch denotes any printable ASCII character,
as specified by isprint(), other than \
(backslash) and ' (single quote). |
| stringcon |
::= |
"{ch}",
where ch denotes any printable ASCII character
(as specified by isprint()) other than
" (double quotes) and the newline character. |
| Comments |
|
Comments are as in C, i.e. a sequence
of characters preceded by /* and followed by */, and not
containing any occurrence of */. |
| prog |
: |
{ dcl
';' | func } |
| dcl |
: |
type var_decl {
',' var_decl } |
| | | |
[ extern ] type id
'(' parm_types ')'
{ ',' id '(' parm_types
')' } |
| | | |
[ extern ] void id
'(' parm_types ')'
{ ',' id '(' parm_types
')' } |
| var_decl |
: |
id [ '[' intcon
']' ] |
| type |
: |
char |
| | | | int |
| parm_types |
: |
void |
| | | | type id [ '[' ']' ]
{ ',' type id
[ '[' ']'
] } |
| func |
: |
type id '('
parm_types ')' '{'
{ type
var_decl {
',' var_decl
}
';' } { stmt
} '}' |
| |
| |
void id '('
parm_types ')' '{'
{ type var_decl { ',' var_decl }
';' } { stmt
} '}' |
| stmt |
: |
if '(' expr ')'
stmt [ else stmt
] |
| | | |
while '(' expr
')' stmt |
| | | |
for
'(' [ assg ] ';'
[ expr ] ';'
[ assg ]
')' stmt |
| | | |
return [ expr ] ';' |
| | | |
assg ';' |
| | | |
id
'(' [expr {
',' expr }
]
')' ';' |
| | | |
'{' { stmt } '}' |
| | | |
';' |
| assg |
: |
id [
'[' expr ']' ]
= expr |
| expr |
: |
'–' expr |
| | | |
'!' expr |
| | | |
expr binop expr |
| | | |
expr relop expr |
| | | |
expr logical_op expr |
| | | |
id [ '(' [expr
{
',' expr }
] ')'
|
'[' expr
']'
] |
| | | |
'(' expr ')' |
| | | |
intcon |
| | | | charcon |
| | | | stringcon |
| binop |
: |
+ |
| | | | – |
| | | | * |
| | | | / |
| relop |
: |
== |
| | | | != |
| | | | <= |
| | | | < |
| | | | >= |
| | | | > |
| logical_op |
: |
&& |
| | | | || |