grammar new rules

This commit is contained in:
Sam Hadow 2024-03-26 22:45:55 +01:00
parent 4ba1dbb9d4
commit dff4dfd0e3
2 changed files with 26 additions and 4 deletions

View File

@ -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);
}
;

1
src/test.1 Normal file
View File

@ -0,0 +1 @@
(10,5,1)