#include #include #include KEYWORD struct|end|method|var|if|then|else|while|do|return|not|or|this SPECIAL_CHAR \;|\(|\)|\:=|\.|\-|\*|\<|\=|\, IDENTIFIER [a-zA-Z_][0-9a-zA-Z_]* NUMBER_HEX 0x[0-9A-Fa-f]+ NUMBER_DEC [0-9]+ WHITESPACE [\t\n\r ] COMMENT_START \/\* COMMENT_END \*\/ /* x ist unsere zustandsvariable! */ %x COMMENT %option yylineno %% {COMMENT_START} BEGIN(COMMENT); {COMMENT_END} BEGIN(INITIAL); <> { fprintf(stderr, "Kommentar nicht geschlossen\n"); exit(1); } (.|\n) /* alles im kommentar wird ignoriert */ {KEYWORD} printf("%s\n", yytext); {SPECIAL_CHAR} printf("%s\n", yytext); {IDENTIFIER} printf("ident %s\n", yytext); {NUMBER_DEC} printf("num %lx\n", strtol(yytext, (char **)NULL, 10)); {NUMBER_HEX} printf("num %lx\n", strtol(yytext, (char **)NULL, 16)); {WHITESPACE} /* ignorieren */ . { fprintf(stderr, "Lexikalischer Fehler auf Zeile %i\n", yylineno); exit(1); } %% int main(int argc, char **argv) { yylex(); return 0; }