/* * TCC - TRD Configuration Compiler * Author: Jan de Cuveland * Kirchhoff-Institut fuer Physik * Date: December 15, 2003 */ %option yylineno %{ #include "tcc.h" #include "tcc.tab.h" int yyparse(); #if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) static void __attribute__ ((__unused__)) yyunput(); #endif symrec *s; %} DIGIT [0-9] ID [a-zA-Z][a-zA-Z0-9_]* %x comment incl asm %% "/*" BEGIN(comment); [^*\n]* /* eat anything that's not a '*' */ "*"+[^*/\n]* /* eat up '*'s not followed by '/'s */ \n /* ++line_num; */ "*"+"/" BEGIN(INITIAL); "//".*\n /* strip c++-style comment */ include BEGIN(incl); [ \t]* /* eat the whitespace */ [^ \t\n\015]+ { if (active) { yyin = fopen(yytext, "r"); if (!yyin) { fprintf(stderr, "ERROR: cannot open tcs-include file '%s'" " on line %d\n", yytext, yylineno); exit(1); } yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE)); /* VA */ /* Hier muss man auch den config.inc irgendwie einschliessen! ifiles_line[ifiles]=yylineno; ifiles++; ifiles_name[ifiles]=yytext;*/ /* Das ist immer noch besser als frueher */ yylineno=0; } BEGIN(INITIAL); } <> { yypop_buffer_state(); /* VA */ /* ifiles--; yylineno=ifiles_line[ifiles]; */ if (!YY_CURRENT_BUFFER) yyterminate(); } assemble BEGIN(asm); [ \t]* /* eat the whitespace */ [^ \t\n\015]+ { if (active) assemble_file(127, yytext); BEGIN(INITIAL); } {DIGIT}+ { sscanf(yytext, "%d", &yylval.val); return NUM; } 0[Xx][0-9A-Fa-f]+ { sscanf(yytext, "%x", &yylval.val); return NUM; } [01]+b { yylval.val = 0; while (*yytext != 'b') yylval.val = yylval.val * 2 + (*yytext++ - '0'); return NUM; } [0-7]+o { sscanf(yytext, "%o", &yylval.val); return NUM; } const { return CONST; } send { return WRITE; } write { return WRITE; } reset { return RESET; } nop { return NOP; } read { return READ; } expect { return EXPECT; } readseq { return READSEQ; } pretrigger { return PRETRIGGER; } wait { return WAIT; } bridge { return BRIDGE; } restrict { return RESTRICT; } "==" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return GT; } ">=" { return GE; } "||" { return OR; } "&&" { return AND; } "<<" { return SHL; } ">>" { return SHR; } "++" { return INC; } "--" { return DEC; } {ID} { s = getsym(yytext); if (s == 0) s = putsym(yytext, VAR); yylval.tptr = s; return s->type; } [ \t]* { ; } .|\n { return yytext[0]; } %%