-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalc.l
83 lines (76 loc) · 2.99 KB
/
Calc.l
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* This FLex file was machine-generated by the BNF converter */
%{
#include <string.h>
#include "Parser.H"
#define YY_BUFFER_LENGTH 4096
extern int yy_mylinenumber ;
static char YY_PARSED_STRING[YY_BUFFER_LENGTH];
static void YY_BUFFER_APPEND(char *s)
{
strcat(YY_PARSED_STRING, s); //Do something better here!
}
static void YY_BUFFER_RESET(void)
{
for(int x = 0; x < YY_BUFFER_LENGTH; x++)
YY_PARSED_STRING[x] = 0;
}
%}
LETTER [a-zA-Z]
CAPITAL [A-Z]
SMALL [a-z]
DIGIT [0-9]
IDENT [a-zA-Z0-9'_]
%START YYINITIAL COMMENT CHAR CHARESC CHAREND STRING ESCAPED
%%
<YYINITIAL>"(" return _SYMB_0;
<YYINITIAL>")" return _SYMB_1;
<YYINITIAL>"{" return _SYMB_2;
<YYINITIAL>"}" return _SYMB_3;
<YYINITIAL>":" return _SYMB_4;
<YYINITIAL>";" return _SYMB_5;
<YYINITIAL>"," return _SYMB_6;
<YYINITIAL>"=" return _SYMB_7;
<YYINITIAL>"." return _SYMB_8;
<YYINITIAL>"this." return _SYMB_9;
<YYINITIAL>"*" return _SYMB_10;
<YYINITIAL>"/" return _SYMB_11;
<YYINITIAL>"+" return _SYMB_12;
<YYINITIAL>"-" return _SYMB_13;
<YYINITIAL>"<" return _SYMB_14;
<YYINITIAL>">" return _SYMB_15;
<YYINITIAL>"==" return _SYMB_16;
<YYINITIAL>"!=" return _SYMB_17;
<YYINITIAL>"catch" return _SYMB_18;
<YYINITIAL>"class" return _SYMB_19;
<YYINITIAL>"else" return _SYMB_20;
<YYINITIAL>"function" return _SYMB_21;
<YYINITIAL>"if" return _SYMB_22;
<YYINITIAL>"new" return _SYMB_23;
<YYINITIAL>"return" return _SYMB_24;
<YYINITIAL>"throw" return _SYMB_25;
<YYINITIAL>"try" return _SYMB_26;
<YYINITIAL>"while" return _SYMB_27;
<YYINITIAL>"#"[^\n]*\n ++yy_mylinenumber ; /* BNFC single-line comment */;
<YYINITIAL>"//"[^\n]*\n ++yy_mylinenumber ; /* BNFC single-line comment */;
<YYINITIAL>"/*" BEGIN COMMENT;
<COMMENT>"*/" BEGIN YYINITIAL;
<COMMENT>. /* BNFC multi-line comment */;
<COMMENT>[\n] ++yy_mylinenumber ; /* BNFC multi-line comment */;
<YYINITIAL>{LETTER}({LETTER}|{DIGIT}|\_)* yylval.string_ = strdup(yytext); return _SYMB_28;
<YYINITIAL>"\"" BEGIN STRING;
<STRING>\\ BEGIN ESCAPED;
<STRING>\" yylval.string_ = strdup(YY_PARSED_STRING); YY_BUFFER_RESET(); BEGIN YYINITIAL; return _STRING_;
<STRING>. YY_BUFFER_APPEND(yytext);
<ESCAPED>n YY_BUFFER_APPEND("\n"); BEGIN STRING;
<ESCAPED>\" YY_BUFFER_APPEND("\""); BEGIN STRING ;
<ESCAPED>\\ YY_BUFFER_APPEND("\\"); BEGIN STRING;
<ESCAPED>t YY_BUFFER_APPEND("\t"); BEGIN STRING;
<ESCAPED>. YY_BUFFER_APPEND(yytext); BEGIN STRING;
<YYINITIAL>{DIGIT}+"."{DIGIT}+("e"(\-)?{DIGIT}+)? yylval.double_ = atof(yytext); return _DOUBLE_;
<YYINITIAL>{DIGIT}+ yylval.int_ = atoi(yytext); return _INTEGER_;
\n ++yy_mylinenumber ;
<YYINITIAL>[ \t\r\n\f] /* ignore white space. */;
<YYINITIAL>. return _ERROR_;
%%
int initialize_lexer(FILE *inp) { yyrestart(inp); BEGIN YYINITIAL; }
int yywrap(void) { return 1; }