1.3.8 Functions
The ParameterList
rule contains a parameter declaration. A parameter declaration is syntactically similar to a variable declaration but lacks the var
keyword.
The ParameterList
rule is "called" in the Function
rule with the function
argument.
export module minilang.parser.function;
...
parser FunctionParser
{
...
Function(var std::unique_ptr<minilang::ast::FunctionNode> function) : minilang::ast::FunctionNode*
::=
(
Type:returnType
Identifier:functionName!
LPAREN!{ function.reset(new minilang::ast::FunctionNode(returnType, functionName)); }
ParameterList(function.get()):params?
RPAREN!
CompoundStatement:functionBody!{ function->SetBody(functionBody); }
)
{
return function.release();
}
;
ParameterList(minilang::ast::FunctionNode* function)
::=
(
Parameter:left{ function->AddParam(left); }
(
COMMA Parameter:right!{ function->AddParam(right); }
)*
)
;
...
}