1 %option reentrant noyywrap batch
2 %option bison-bridge bison-locations yylineno
9 #include <ozulis/core/assert.hh>
10 #include <ozulis/ast/ast.hh>
11 #include <ozulis/ast/node-factory.hh>
14 #define YY_USER_ACTION \
15 yylloc->first_line = yylineno; \
16 yylloc->last_line = yylineno; \
17 yylloc->first_column = yylloc->last_column; \
18 yylloc->last_column += yyleng;
20 #define MAKE_BOOL(Value) \
22 yylval->nbExp = new ozulis::ast::NumberExp(); \
23 yylval->nbExp->type = ozulis::ast::NodeFactory::createBoolType(); \
24 yylval->nbExp->number = Value; \
28 static ozulis::ast::NumberExp *
29 makeInteger(double value, int size, bool isSigned);
31 static ozulis::ast::NumberExp *
32 makeFloat(double value);
38 \n /* ignore end of line */yylloc->last_column = 0;
39 [ \t]+ /* ignore whitespace */;
40 \/\/.*$ /* line comment */
41 #.*$ /* line comment */
86 \"[^\"]*\" return STRING;
100 [a-zA-Z][a-zA-Z0-9_]* yylval->string = strdup(yytext); return ID;
103 yylval->nbExp = makeFloat(strtod(yytext, 0));
108 yylval->nbExp = makeInteger(strtod(yytext, 0), 32, true);
113 yylval->nbExp = makeInteger(strtod(yytext, 0), 32, false);
118 yylval->nbExp = makeInteger(strtod(yytext, 0), 64, true);
123 yylval->nbExp = makeInteger(strtod(yytext, 0), 64, false);
131 static ozulis::ast::NumberExp *
132 makeInteger(double value, int size, bool isSigned)
134 ozulis::ast::NumberExp * nbExp = new ozulis::ast::NumberExp();
135 ozulis::ast::IntegerType * nbType = new ozulis::ast::IntegerType();
137 nbType->isSigned = isSigned;
138 nbExp->type = nbType;
139 nbExp->number = value;
143 static ozulis::ast::NumberExp *
144 makeFloat(double value)
146 ozulis::ast::NumberExp * nbExp = new ozulis::ast::NumberExp();
147 ozulis::ast::FloatType * nbType = new ozulis::ast::FloatType();
148 nbExp->type = nbType;
149 nbExp->number = value;