diff options
-rw-r--r-- | examples/echo.lyn | 1 | ||||
-rw-r--r-- | src/parser.y | 33 |
2 files changed, 16 insertions, 18 deletions
diff --git a/examples/echo.lyn b/examples/echo.lyn index bfaa9ae..2b22cc5 100644 --- a/examples/echo.lyn +++ b/examples/echo.lyn @@ -1,2 +1,3 @@ use-modules (ice-9 readline) display (readline "Type something: ") +newline diff --git a/src/parser.y b/src/parser.y index edf71c1..2cf2a84 100644 --- a/src/parser.y +++ b/src/parser.y @@ -48,8 +48,8 @@ %token BACKSLASH "\\" %token NL "nl" -%nterm <ast> arg args rev_args -%nterm <ast> cmd cmds rev_cmds +%nterm <ast> arg args +%nterm <ast> cmd cmds cmd_list %{ @@ -95,8 +95,8 @@ static void yyerror(YYLTYPE *yylloc, void *lexer, %% arg - : "(" cmds ")" {$$ = $2; $$.kind = LYN_APPLY;} - | "{" cmds "}" {$$ = $2; $$.kind = LYN_GROUP;} + : "(" cmd_list ")" {$$ = $2; $$.kind = LYN_APPLY;} + | "{" cmd_list "}" {$$ = $2; $$.kind = LYN_GROUP;} | ID {$$ = gen_id($1);} | STRING {$$ = gen_str($1);} | INT {$$ = gen_int($1);} @@ -105,13 +105,10 @@ arg cont : BACKSLASH NL -rev_args - : rev_args cont arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} - | rev_args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} - | arg {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} - args - : rev_args + : args cont arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} + | args arg {$$ = $1; vect_append(struct lyn_value, $$.args, &$2);} + | arg {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} sep : sep ";" @@ -122,19 +119,19 @@ sep cmd : args {$$ = $1; $$.kind = LYN_CMD;} -rev_cmds - : rev_cmds sep cmd {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} +cmds + : cmds sep cmd {$$ = $1; vect_append(struct lyn_value, $$.args, &$3);} | cmd {$$ = gen_list(); vect_append(struct lyn_value, $$.args, &$1);} -cmds - : rev_cmds - | rev_cmds sep - | sep rev_cmds {$$ = $2;} - | sep rev_cmds sep {$$ = $2;} +cmd_list + : cmds + | cmds sep + | sep cmds {$$ = $2;} + | sep cmds sep {$$ = $2;} | {$$ = gen_list();} input - : cmds {$1.kind = LYN_GROUP; parser->tree = $1;} + : cmd_list {$1.kind = LYN_GROUP; parser->tree = $1;} | error {parser->failed = true;} %% |