locations
[ccc.git] / scan.l
1 %option noinput
2 %option nounput
3 %{
4
5 #include <stdio.h>
6 #define YY_USER_ACTION \
7 yylloc.first_line = yylloc.last_line; \
8 yylloc.first_column = yylloc.last_column; \
9 for(int i = 0; yytext[i] != '\0'; i++) { \
10 if(yytext[i] == '\n') { \
11 yylloc.last_line++; \
12 yylloc.last_column = 0; \
13 } \
14 else { \
15 yylloc.last_column++; \
16 } \
17 }
18
19 #include "ast.h"
20 #include "y.tab.h"
21
22 %}
23
24 %%
25
26 if return IF;
27 else return ELSE;
28 while return WHILE;
29 var return VAR;
30 true { yylval.expr = expr_bool(true); return BOOL; }
31 false { yylval.expr = expr_bool(false); return BOOL; }
32 return return RETURN;
33 Int return TINT;
34 Bool return TBOOL;
35 Char return TCHAR;
36 Void return TVOID;
37 -> return ARROW;
38 = return ASSIGN;
39 ! return INVERSE;
40 \|\| return BINOR;
41 && return BINAND;
42 == return EQ;
43 != return NEQ;
44 \<= return GEQ;
45 \< return GE;
46 >= return LEQ;
47 > return LE;
48 : return CONS;
49 \+ return PLUS;
50 - return MINUS;
51 \* return TIMES;
52 \/ return DIVIDE;
53 % return MODULO;
54 \^ return POWER;
55 \( return BOPEN;
56 \) return BCLOSE;
57 \{ return COPEN;
58 \} return CCLOSE;
59 \; return SEMICOLON;
60 \[ return SOPEN;
61 \] return SCLOSE;
62 \[\] return NIL;
63 \. return DOT;
64 , return COMMA;
65 '([^']|\\[abtnvfr]|\\x[0-9a-fA-F]{2})' {
66 yylval.expr = expr_char(yytext); return CHAR; }
67 [0-9]+ {
68 yylval.expr = expr_int(atoi(yytext)); return INTEGER; }
69 [_a-zA-Z][_a-zA-Z0-9]* {
70 yylval.ident = safe_strdup(yytext); return IDENT; }
71 [ \n\t] ;
72
73 %%