types and 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 -> return ARROW;
34 = return ASSIGN;
35 ! return INVERSE;
36 \|\| return BINOR;
37 && return BINAND;
38 == return EQ;
39 != return NEQ;
40 \<= return GEQ;
41 \< return GE;
42 >= return LEQ;
43 > return LE;
44 : return CONS;
45 \+ return PLUS;
46 - return MINUS;
47 \* return TIMES;
48 \/ return DIVIDE;
49 % return MODULO;
50 \^ return POWER;
51 \( return BOPEN;
52 \) return BCLOSE;
53 \{ return COPEN;
54 \} return CCLOSE;
55 \; return SEMICOLON;
56 \[ return SOPEN;
57 \] return SCLOSE;
58 \[\] return NIL;
59 \. return DOT;
60 , return COMMA;
61 '([^']|\\[abtnvfr]|\\x[0-9a-fA-F]{2})' {
62 yylval.expr = expr_char(yytext); return CHAR; }
63 [0-9]+ {
64 yylval.expr = expr_int(atoi(yytext)); return INTEGER; }
65 [_a-zA-Z][_a-zA-Z0-9]* {
66 yylval.ident = safe_strdup(yytext); return IDENT; }
67 [ \n\t] ;
68
69 %%