实验指导 step9:函数

step9 开始,我们要支持多函数了。

  1. 我们需要支持函数的声明和定义:

    program : function* function : type Identifier '(' parameter_list ')' (compound_statement | ';')
    parameter_list : (type Identifier (',' type Identifier)*)?
  2. 我们还需要支持函数调用:

    expression_list : (expression (',' expression)*)?
    unary : postfix | ('-'|'~'|'!') unary postfix : primary | Identifier '(' expression_list ')'

语义检查部分,我们需要检查函数的重复定义、检查调用函数的实参(argment)和形参(parameter)的个数类型一致。 我们不支持 void 返回值,直接忽略 int 返回值即可。

results matching ""

    No results matching ""

    results matching ""

      No results matching ""