l = alloc_label(yytext, current_offset);
append_label(l, label_head);
break;
+
+ case T_DB:
+ yylex();
+ t = yylex();
+
+ if (t != T_TIMES)
+ fail("Expected a times keyword after db directive");
+
+ t = yylex();
+
+ if (t != NUMBER)
+ fail("Expected a number after times");
+
+ current_offset += atoi(yytext);
+ break;
+
+
default:
current_offset++;
break;
int parse() {
int t;
int current_offset = 0; /* the offset in the generated binary file */
+ int val;
+ int i, max_iter;
int s;
struct label *l;
writeint(l->offset, outfp);
break;
+ case T_DB:
+ yylex();
+ val = atoi(yytext);
+ t = yylex();
+
+ if (t != T_TIMES)
+ fail("Expected a times keyword after db directive");
+
+ t = yylex();
+
+ if (t != NUMBER)
+ fail("Expected a number after times");
+
+ max_iter = atoi(yytext);
+
+ for(i = 1; i <= max_iter; i++)
+ writeint(val, outfp);
+ break;
+
+
+
default:
fail("unexpected %s in input at line %d", yytext, yylineno);
break;
; BEGIN(in_comment);
<in_comment>\n BEGIN(INITIAL);
<in_comment>[^\n]+ // eat comment
-<in_comment>; // eat the lone ';'
"call" { return T_CALL; }
"ret" { return T_RET; }
"jmp" { return T_JMP; }
+"db" { return T_DB; }
+"times" { return T_TIMES; }
[ \t\n]+ /* ignore whitespace */
[0-9]+ { return NUMBER; }
};
struct vm* alloc_vm(int memsize, int stacksize);
+int load_file(struct vm *v, FILE *fd);
+int run(struct vm *v);
#endif