forked from tierney/compass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.ll
66 lines (54 loc) · 1.73 KB
/
lexer.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%{
/*
* Lexer.l file
* To generate the lexical analyzer run: "flex Lexer.l"
*/
#include <cstdio>
#include <string>
#include "norms.h"
// #include "expression.h"
#include "parser.hh"
#define SAVE_TOKEN yylval->string = new std::string(yytext, yyleng)
#define TOKEN(t) (yylval->token = t)
%}
%option outfile="lexer.cc" header-file="lexer.hh"
%option warn nodefault
%option reentrant noyywrap never-interactive nounistd
%option bison-bridge
LPAREN "("
RPAREN ")"
PLUS "+"
MULTIPLY "*"
AND "&&"
OR "||"
NUMBER [0-9]+
WS [ \r\n\t]*
STRING [a-zA-Z0-9]+
%%
[ \t\n] ;
[a-zA-Z_][a-zA-Z0-9_]* SAVE_TOKEN; return TIDENTIFIER;
"=" return TOKEN(TEQUAL);
"==" return TOKEN(TCEQ);
"!=" return TOKEN(TCNE);
"<" return TOKEN(TCLT);
"<=" return TOKEN(TCLE);
">" return TOKEN(TCGT);
">=" return TOKEN(TCGE);
"(" return TOKEN(TLPAREN);
")" return TOKEN(TRPAREN);
"{" return TOKEN(TLBRACE);
"}" return TOKEN(TRBRACE);
"." return TOKEN(TDOT);
"," return TOKEN(TCOMMA);
"+" return TOKEN(TPLUS);
"-" return TOKEN(TMINUS);
"*" return TOKEN(TMUL);
"/" return TOKEN(TDIV);
"&&" return TOKEN(TAND);
"||" return TOKEN(TOR);
"!" return TOKEN(TNEG);
. printf("Unknown token!\n"); yyterminate();
%%
/* int yyerror(const char *msg) { */
/* fprintf(stderr,"Error:%s\n",msg); return 0; */
/* } */