From dff4dfd0e361418775bfeffaab71f9e83ff4cb20 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Tue, 26 Mar 2024 22:45:55 +0100 Subject: [PATCH] grammar new rules --- src/ram.y | 29 +++++++++++++++++++++++++---- src/test.1 | 1 + 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/test.1 diff --git a/src/ram.y b/src/ram.y index 102bb1d..7cf9b38 100644 --- a/src/ram.y +++ b/src/ram.y @@ -14,15 +14,36 @@ int yyerror(char* s); %} %token REGISTER REGISTER_REF OP OP_CTRL VALUE -%token PAR_O PAR_F +%token PAR_O PAR_C %left COMMA %right SEPARATION %% +program: + input SEPARATION instruction { + } + | instruction { + } +; + +input: + PAR_O content PAR_C { + $$ = $2; + } +; + +content: + VALUE COMMA content { + asprintf(&$$, "%s, %s ", $1, $3); + } + | VALUE { + $$ = $1; + } +; instruction: line SEPARATION instruction { - asprintf(&$$, "%s\n%s", $1, $3); + asprintf(&$$, "%s%s", $1, $3); } | line SEPARATION { $$ = $1; @@ -33,10 +54,10 @@ instruction: ; line: - OP_CTRL PAR_O args_ctrl PAR_F { + OP_CTRL PAR_O args_ctrl PAR_C { asprintf(&$$, "{\"op\": Ram.op, \"args\": (%s, %s)}, ", $1, $2); } - | OP PAR_O args PAR_F { + | OP PAR_O args PAR_C { asprintf(&$$, "{\"op\": Ram.op_ctrl, \"args\": (%s, %s)}, ", $1, $2); } ; diff --git a/src/test.1 b/src/test.1 new file mode 100644 index 0000000..68ecfd0 --- /dev/null +++ b/src/test.1 @@ -0,0 +1 @@ +(10,5,1)