grammar new rules
This commit is contained in:
parent
4ba1dbb9d4
commit
dff4dfd0e3
29
src/ram.y
29
src/ram.y
@ -14,15 +14,36 @@ int yyerror(char* s);
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
%token REGISTER REGISTER_REF OP OP_CTRL VALUE
|
%token REGISTER REGISTER_REF OP OP_CTRL VALUE
|
||||||
%token PAR_O PAR_F
|
%token PAR_O PAR_C
|
||||||
%left COMMA
|
%left COMMA
|
||||||
%right SEPARATION
|
%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:
|
instruction:
|
||||||
line SEPARATION instruction {
|
line SEPARATION instruction {
|
||||||
asprintf(&$$, "%s\n%s", $1, $3);
|
asprintf(&$$, "%s%s", $1, $3);
|
||||||
}
|
}
|
||||||
| line SEPARATION {
|
| line SEPARATION {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
@ -33,10 +54,10 @@ instruction:
|
|||||||
;
|
;
|
||||||
|
|
||||||
line:
|
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);
|
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);
|
asprintf(&$$, "{\"op\": Ram.op_ctrl, \"args\": (%s, %s)}, ", $1, $2);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
1
src/test.1
Normal file
1
src/test.1
Normal file
@ -0,0 +1 @@
|
|||||||
|
(10,5,1)
|
Loading…
x
Reference in New Issue
Block a user