[mugiwara] using @ and $ to say it's a pointer or get the address, and to unreference...
[ozulis.git] / src / lang / mugiwara / bison-parser / lexer.l
blob9c47c0f09fd610ea379fa1307e47f4aaebeb6aae
1 %option reentrant noyywrap batch
2 %option bison-bridge bison-locations yylineno
3 %option warn
5 %{
6 #include <stdio.h>
7 #include <stdlib.h>
9 #include <ast/ast.hh>
10 #include <ast/node-factory.hh>
11 #include "parser.hh"
13 #define YY_USER_ACTION                                  \
14   yylloc->first_line = yylineno;                        \
15   yylloc->last_line = yylineno;                         \
16   yylloc->first_column = yylloc->last_column;           \
17   yylloc->last_column += yyleng;
19 #define MAKE_BOOL(Value)                                        \
20   do {                                                          \
21     yylval->nbExp = new ast::NumberExp();                       \
22     yylval->nbExp->type = ast::NodeFactory::createBoolType();   \
23     yylval->nbExp->number = Value;                              \
24     return NUMBER;                                              \
25   } while (0)
27 static ast::NumberExp *
28 makeInteger(double value, int size, bool isSigned);
30 static ast::NumberExp *
31 makeFloat(double value);
37 \n                      /* ignore end of line */yylloc->last_column = 0;
38 [ \t]+                  /* ignore whitespace */;
39 \/\/.*$                 /* line comment */
40 #.*$                 /* line comment */
42 ;                       return SEMICOL;
43 \.                      return DOT;
44 :                       return DDOT;
45 ,                       return COMMA;
47 =                       return EQ;
48 ==                      return EQEQ;
49 !=                      return NEQ;
50 \<                      return LT;
51 \<=                     return LTEQ;
52 >                       return GT;
53 >=                      return GTEQ;
55 \(                      return LPAR;
56 \)                      return RPAR;
58 \[                      return LSB;
59 \]                      return RSB;
61 \{                      return LBR;
62 \}                      return RBR;
64 \+                      return ADD;
65 -                       return SUB;
66 \*                      return STAR;
67 \/                      return DIV;
68 %                       return MOD;
70 \|                      return OR;
71 &                       return AND;
72 \^                      return XOR;
73 \<\<                    return SHL;
74 >>                      return LSHR;
75 >>>                     return ASHR;
76 ~                       return NOT;
78 !                       return BANG;
79 \|\|                    return OROR;
80 &&                      return ANDAND;
82 @                       return AT;
83 \$                      return DOLLAR;
85 \"[^\"]*\"              return STRING;
87 const                   return CONST;
88 goto                    return GOTO;
89 cast                    return CAST;
90 if                      return IF;
91 else                    return ELSE;
92 while                   return WHILE;
93 do                      return DO;
94 for                     return FOR;
95 return                  return RETURN;
96 true                    MAKE_BOOL(1);
97 false                   MAKE_BOOL(0);
99 [a-zA-Z][a-zA-Z0-9_]*   yylval->string = strdup(yytext); return ID;
101 ([0-9]+)?\.[0-9]+    {
102   yylval->nbExp = makeFloat(strtod(yytext, 0));
103   return NUMBER;
106 [0-9]+    {
107   yylval->nbExp = makeInteger(strtod(yytext, 0), 32, true);
108   return NUMBER;
111 [0-9]+U    {
112   yylval->nbExp = makeInteger(strtod(yytext, 0), 32, false);
113   return NUMBER;
116 [0-9]+L    {
117   yylval->nbExp = makeInteger(strtod(yytext, 0), 64, true);
118   return NUMBER;
121 [0-9]+UL    {
122   yylval->nbExp = makeInteger(strtod(yytext, 0), 64, false);
123   return NUMBER;
128 static ast::NumberExp *
129 makeInteger(double value, int size, bool isSigned)
131   ast::NumberExp * nbExp = new ast::NumberExp();
132   ast::IntegerType * nbType = new ast::IntegerType();
133   nbType->size = size;
134   nbType->isSigned = isSigned;
135   nbExp->type = nbType;
136   nbExp->number = value;
137   return nbExp;
140 static ast::NumberExp *
141 makeFloat(double value)
143   ast::NumberExp * nbExp = new ast::NumberExp();
144   ast::FloatType * nbType = new ast::FloatType();
145   nbExp->type = nbType;
146   nbExp->number = value;
147   return nbExp;