arm64: codea/abgabe_aa.0
[uebersetzerbau-ss10.git] / gesamt_arm / scanner.lex
1         #include <stdio.h>
2         #include <stdlib.h>
3         #include <string.h>
4         #include "parser.h"
5
6 KEYWORD struct|end|method|var|if|then|else|while|do|return|not|or|this
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 COMMENT
15 %option yylineno
16 %%
17
18 {COMMENT_START} BEGIN(COMMENT);
19
20 <COMMENT>{COMMENT_END} BEGIN(INITIAL);
21
22 <COMMENT><<EOF>> {
23         fprintf(stderr, "Kommentar nicht geschlossen\n");
24         exit(1);
25 }
26
27 <COMMENT>(.|\n) /* alles im kommentar wird ignoriert */
28
29 struct return(STRUCT);
30 end return(END);
31 method return(METHOD);
32 var return(VAR);
33 if return(IF);
34 then return(THEN);
35 else return(ELSE);
36 while return(WHILE);
37 do return(DO);
38 return return(RETURN);
39 not return(NOT);
40 or return(OR);
41 this return(THIS);
42
43 {IDENTIFIER} return(IDENT); @{ @IDENT.name@ = strdup(yytext); @}
44
45 {NUMBER_DEC} return(NUM); @{ @NUM.val@ = strtol(yytext, (char **)NULL, 10); @}
46 {NUMBER_HEX} return(NUM); @{ @NUM.val@ = strtol(yytext, (char **)NULL, 16); @}
47
48 \:= return(ASSIGN);
49 \; return(';');
50 \( return('(');
51 \) return(')');
52 \. return('.');
53 \- return('-');
54 \* return('*');
55 \< return('<');
56 \= return('=');
57 \, return(',');
58
59 {WHITESPACE} /* ignore */
60
61 . {
62                 fprintf(stderr, "Lexical error on line %i\n", yylineno);
63                 exit(1);
64 }
65
66 %%
67