ref: a0d30aba763788d63e47878756cbd4e5cc6f6798
dir: /spirva.y/
%{
#include <u.h>
#include "sym.h"
#include "asm.h"
int debug;
extern int yylex(void);
extern int yyparse(void);
%}
%union {
uint op;
double f;
int i;
Symbol *sym;
char *str;
}
%token <sym> SYM
%token <op> OP
%token <f> FLOAT
%token <i> INT
%token <str> STR
%right '='
%%
list: /* nothing */
| list '\n'
| list SYM '=' oplist '\n' { a_result($2); asm(); }
| list oplist '\n' { asm(); }
;
oplist: OP arglist { a_op($1); }
;
arglist: /* nothing */
| arglist arg
;
arg: SYM { a_var($1); }
| INT { a_int($1); }
| FLOAT { a_float($1); }
| str
| STR { a_keyword($1); }
;
str: '"' STR '"' { a_str($2); }
%%
/* end of grammar */
#include <libc.h>
#include <bio.h>
void
init(void) {
a_init();
}
void
asm(void) {
assemble();
}
void
main(int argc, char **argv)
{
ARGBEGIN{
case 'd':
debug++;
break;
}ARGEND;
u32int magic = 0x07230203;
write(1, &magic, sizeof(u32int));
for (init(); yyparse(); init())
asm();
}
void
yyerror(char *s)
{
fprint(2, "error: %s\n", s);
}