arm64: codea/abgabe_aa.0
[uebersetzerbau-ss10.git] / scanner / scanner.lex
1         #include <stdio.h>
2         #include <stdlib.h>
3         #include <string.h>
4
5 KEYWORD struct|end|method|var|if|then|else|while|do|return|not|or|this
6 SPECIAL_CHAR \;|\(|\)|\:=|\.|\-|\*|\<|\=|\,
7 IDENTIFIER [a-zA-Z_][0-9a-zA-Z_]*
8 NUMBER_HEX 0x[0-9A-Fa-f]+
9 NUMBER_DEC [0-9]+
10 WHITESPACE [\t\n\r ]
11 COMMENT_START \/\*
12 COMMENT_END     \*\/
13
14 /* x ist unsere zustandsvariable! */
15 %x COMMENT
16 %option yylineno
17 %%
18
19 {COMMENT_START} BEGIN(COMMENT);
20
21 <COMMENT>{COMMENT_END} BEGIN(INITIAL);
22
23 <COMMENT><<EOF>> {
24         fprintf(stderr, "Kommentar nicht geschlossen\n");
25         exit(1);
26 }
27
28 <COMMENT>(.|\n) /* alles im kommentar wird ignoriert */
29
30 {KEYWORD} printf("%s\n", yytext);
31
32 {SPECIAL_CHAR} printf("%s\n", yytext);
33
34 {IDENTIFIER} printf("ident %s\n", yytext);
35
36 {NUMBER_DEC} printf("num %lx\n", strtol(yytext, (char **)NULL, 10));
37
38 {NUMBER_HEX} printf("num %lx\n", strtol(yytext, (char **)NULL, 16));
39
40 {WHITESPACE} /* ignorieren */
41
42 . {
43         fprintf(stderr, "Lexikalischer Fehler auf Zeile %i\n", yylineno);
44         exit(1);
45 }
46
47 %%
48
49 int main(int argc, char **argv) {
50         yylex();
51         return 0;
52 }
53