From 7d304a4cb618192987a2c4fe4a19470fe2b5c0c7 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 24 Jul 2013 20:59:29 -0500 Subject: [PATCH] Partially revert commit 46c0127 - Being able to omit optional function arguments is not such a nonsensical thing after all. However, the previous grammar was still inadequate for representing this in a useful way. --- src/zscript/zcc-parse.lemon | 40 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/zscript/zcc-parse.lemon b/src/zscript/zcc-parse.lemon index b1420c893..3090125aa 100644 --- a/src/zscript/zcc-parse.lemon +++ b/src/zscript/zcc-parse.lemon @@ -997,26 +997,42 @@ expr_list(X) ::= expr_list(A) COMMA expr(B). * but once you do that, all remaining parameters must also be named. * We let higher-level code handle this to keep this file simpler. */ %type func_expr_list{ZCC_FuncParm *} -%type func_expr_list1{ZCC_FuncParm *} +%type func_expr_item{ZCC_FuncParm *} %type named_expr{ZCC_FuncParm *} -func_expr_list(X) ::= . +func_expr_list(X) ::= func_expr_item(A). +{ + X = A; +} +func_expr_list(X) ::= func_expr_list(A) COMMA func_expr_item(B). +{ + // Omitted parameters still need to appear as nodes in the list. + if (A == NULL) + { + NEW_AST_NODE(FuncParm,nil_a); + nil_a->Value = NULL; + nil_a->Label = NAME_None; + A = nil_a; + } + if (B == NULL) + { + NEW_AST_NODE(FuncParm,nil_b); + nil_b->Value = NULL; + nil_b->Label = NAME_None; + B = nil_b; + } + X = A; + A->AppendSibling(B); +} + +func_expr_item(X) ::= . { X = NULL; } -func_expr_list(X) ::= func_expr_list1(A). +func_expr_item(X) ::= named_expr(A). { X = A; } -func_expr_list1(X) ::= named_expr(A). -{ - X = A; -} -func_expr_list1(X) ::= func_expr_list1(A) COMMA named_expr(B). -{ - X = A; - A->AppendSibling(B); -} named_expr(X) ::= IDENTIFIER(A) COLON expr(B). {