规范

每个步骤结尾的 规范 一节都会对这个步骤中的新特性给出规范,方便大家查阅。

step12 语法规范

灰色部分表示相对上一节的修改。


program
    : (function | declaration)*

function
    : type Identifier '(' parameter_list ')' ( compound_statement | ; )

type
    : 'int'

parameter_list : (type Identifier ('[' ']')?(('['Integer']')*)? (',' type Identifier ('[' ']')?(('['Integer']')*)?)*)?
compound_statement : '{' block_item* '}' block_item : statement | declaration statement : 'return' expression ';' | expression? ';' | 'if' '(' expression ')' statement ('else' statement)? | compound_statement | 'for' '(' expression? ';' expression? ';' expression? ')' statement | 'for' '(' declaration expression? ';' expression? ')' statement | 'while' '(' expression ')' statement | 'break' ';' | 'continue' ';' declaration
: type Identifier ('=' expression)? ';' | type Identifier ('[' Integer ']')+ ('=' '{' (Integer (',' Integer)*)? '}')? ';'
expression_list : (expression (',' expression)*)? expression : assignment assignment : conditional | unary '=' expression conditional : logical_or | logical_or '?' expression ':' conditional logical_or : logical_and | logical_or '||' logical_and logical_and : equality | logical_and '&&' equality equality : relational | equality ('=='|'!=') relational relational : additive | relational ('<'|'>'|'<='|'>=') additive additive : multiplicative | additive ('+'|'-') multiplicative multiplicative : unary | multiplicative ('*'|'/'|'%') unary unary : postfix | ('-'|'~'|'!') unary postfix : primary | Identifier '(' expression_list ')' | postfix '[' expression ']' primary : Integer | '(' expression ')' | Identifier

step12 语义规范

12.1 多维数组按照类似一维数组的初始化方法,不要求实现内部嵌套括号

int a[2][2] = {1, 2, 3, 4};

会将数组变为

a[0][0] = 1;

a[0][1] = 2;

a[1][0] = 3;

a[1][1] = 4;

12.2 数组传参是支持不定长度的

int fun(int a[]) 是被支持的,由于传参不需要申请完整的数组的空间,不会产生需要计算数组空间的问题

results matching ""

    No results matching ""

    results matching ""

      No results matching ""