10 #define YY_SKIP_YYWRAP
15 //#define YYSTYPE long long int
16 //extern YYSTYPE yylval;
22 #include "regname_tok.c"
26 #define STRDUP(X) strdup(X)
31 #define IRET(X) do{yylval.i = X; return X;}while(0)
32 #define SRET(X) do{yylval.s = STRDUP(yytext); return X;}while(0)
33 #define NRET(X) do{yylval.i = atoi(yytext); return X;}while(0)
37 const char *yyfilename;
43 \"([^\n"\\]|\\['"?\\abfnrtv]|\\[0-7]{1,3}|\\[Xx][0-9a-fA-F]+)*\" SRET(STRING);
47 [#;].*\n { /* ignore comments */ goto newline; }
49 \n { newline:; ++yylineno; return 10; }
51 "label"{ANU}+ SRET(LABEL);
54 {AU}{ANU}*"::"{ANU}+"$"{D}+ { SRET(FN_I); }
56 {AU}{ANU}*("::"{ANU}+)?"^"{D}+ |
57 {AU}{ANU}*"::"{ANU}+ { SRET(FN_E); }
59 -?{D}+ { NRET(NUMBER);}
63 [=:@,\.\[\]] return yytext[0];
65 . { yyerror("unknown character/token"); }
70 static int section = 0;
72 static int last_mnemonic = 0;
81 } else if (ltok==0 && ret == '.') goto set_section;
83 case 0: if(ret != '.') yyerror("expected section start symbol '.'!");
86 if(ret != ID) yyerror("expected section name!");
87 if(!strcmp(yytext, "data")) section = SECTION_DATA;
88 else if(!strcmp(yytext, "text")) section = SECTION_TEXT;
89 else if(!strcmp(yytext, "imports")) section = SECTION_IMPORTS;
90 else if(!strcmp(yytext, "exports")) section = SECTION_EXPORTS;
91 else if(!strcmp(yytext, "strings")) section = SECTION_STRINGS;
92 else if(!strcmp(yytext, "sections")) section = SECTION_SECTIONS;
93 else if(!strcmp(yytext, "fixups")) section = SECTION_FIXUPS;
94 if(!section) yyerror("unknown section name!");
97 /* FIXME variable names here can't be one of the 4 keywords */
99 if(!strcmp(yytext, "export")) IRET(D_EXPORT);
100 else if(!strcmp(yytext, "int")) IRET(D_INT);
101 else if(!strcmp(yytext, "short")) IRET(D_SHORT);
102 else if(!strcmp(yytext, "char")) IRET(D_CHAR);
106 if(ret == ',') break;
111 if((tmp = KW_SCMD_find_keyword(yytext, yyleng)))
113 last_mnemonic = tok2scmd(tmp);
117 const struct opcode_info *i = &opcodes[last_mnemonic];
118 if(i->regcount >= ltok-1) {
120 if((tmp = RN_find_keyword(yytext, yyleng)))
125 } else if (ret == LABEL) {
126 /* user may haven chosen a variable name matching a label */
127 if(ltok == 1 || last_mnemonic == SCMD_JMP ||
128 last_mnemonic == SCMD_JZ || last_mnemonic == SCMD_JNZ)
136 void yyerror(char *s) {
137 printf("%s:%d %s at `%s`\n",
138 yyfilename==0?"stdin":yyfilename,
141 yytext[0] == 10 ? "<newline>" : yytext);
142 if(yyfatalerrors) abort();
145 void yylex_reset(FILE *f, const char *fn) {
148 #ifdef YY_FLUSH_BUFFER
152 if(yytext) yytext[0] = 0;
164 if(feof(yyin)) break;