doc: paulchen beispiele {code{a,b},gesamt} entpackt (jedes mal entpacken nervt langsa...
[uebersetzerbau-ss10.git] / aus_sammelwut / paulchen / ublu / ss08 / abgabe / codeb / scanner.lex
1         #include <stdio.h>
2         #include <stdlib.h>
3         #include <string.h>
4         #include "parser.h"
5         #include "tree.h"
6
7 KEYWORD         func|end|struct|var|if|then|else|while|do|return|or|not
8 IDENTIFIER      [[:alpha:]_][[:alnum:]_]*
9 NUMBER_HEX      [0-9][0-9A-Fa-f]*H
10 NUMBER_DEC      [0-9]+
11 WHITESPACE      [\t\n\r ]
12 COMMENT_START   \(\*
13 COMMENT_END     \*\)
14
15 %x COMMENT
16 %option yylineno
17 %%
18
19 {COMMENT_START}                 BEGIN(COMMENT);
20
21 <COMMENT>{COMMENT_END}          BEGIN(INITIAL);
22
23 <COMMENT>{COMMENT_START}        fprintf(stderr, "Possibly nested comment on line %i\n", yylineno);
24
25 <COMMENT><<EOF>>                { fprintf(stderr, "Unterminated comment.\n"); exit(1); }
26
27 <COMMENT>{WHITESPACE}           /* ignore */
28
29 <COMMENT>.                      /* ignore everything inside comment */
30
31 func                            return(FUNC);
32 end                             return(END);
33 struct                          return(STRUCT);
34 var                             return(VAR);
35 if                              return(IF);
36 then                            return(THEN);
37 else                            return(ELSE);
38 while                           return(WHILE);
39 do                              return(DO);
40 return                          return(RETURN);
41 or                              return(OR);
42 not                             return(NOT);
43
44 {IDENTIFIER}                    return(ID); @{ @ID.name@=strdup(yytext); @}
45
46 {NUMBER_DEC}                    return(NUM); @{ @NUM.value@=strtol(yytext,(char **)NULL,10); @}
47 {NUMBER_HEX}                    return(NUM); @{ yytext[strlen(yytext)-1]='\0'; @NUM.value@=strtol(yytext,(char **)NULL,16); @}
48                                 
49 \:=                             return(ASSIGN);
50 >=                              return(GREATER);
51 \;                              return(';');
52 \.                              return('.');
53 \(                              return('(');
54 \)                              return(')');
55 \,                              return(',');
56 \-                              return('-');
57 \+                              return('+');
58 \*                              return('*');
59 =                               return('=');
60
61 {WHITESPACE}                    /* ignore */
62
63 .                               { fprintf(stderr, "Lexical error on line %i\n", yylineno); exit(1); }
64
65 %%
66
67