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).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 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 ] | loop_stmt | update_stmt ';' | callret_stmt ';' | '{' { stmt } '}' | ';' loop_stmt : while '(' expr ')' stmt | for '(' [ update_stmt ] ';' [ expr ] ';' [ update_stmt ] ')' stmt update_stmt : id '=' expr | incdec_expr callret_stmt : id '(' [expr { ',' expr } ] ')' | return [ expr ] expr : '–' expr | '!' expr | expr arithop expr | expr relop expr | expr logical_op expr | incdec_expr | id | id '(' [expr { ',' expr } ] ')' | '(' expr ')' | intcon | charcon incdec_expr : id ++ | id -- arithop : + | – | * | / relop : == | != | <= | < | >= | > logical_op : && | ||
Operator Associativity ++, -- none !, – (unary) right to left *, / left to right +, – (binary) left to right <, <=, >, >= left to right ==, != left to right && left to right || left to right
If an object of type char is part of an expression, its value must be converted (sign extended) to a value of type int before the expression is evaluated.
A value of type char is converted (sign extended) to a 32-bit quantity before it is assigned to an object of type int.
A value of type int is converted (truncated) to an 8-bit quantity, by discarding the top 24 bits, before it is assigned to an object of type char.
The order in which the actual parameters in a function call are evaluated is unspecified.
Arguments are passed by value. An argument of type char is converted (sign extended) to a 32-bit quantity before it is passed as an actual parameter to a function. Since a function that has a formal parameter of type char will, in any case, be passed a 32-bit quantity as an actual, it must convert (truncate) the actual to an 8-bit quantity before using it.
Execution returns from a function if either an explicit return statement is executed, or if execution "falls off" the end of the function body. In the latter case, no value is returned.
Execution begins at a procedure named main().