-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLexer.l
153 lines (114 loc) · 3.15 KB
/
Lexer.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
%{
/*
* Lexer.l file
* To generate the lexical analyzer run: "flex Lexer.l"
*/
#define YY_DECL int yylex (YYSTYPE * yylval_param, yyscan_t yyscanner, struct roman *p)
#include "expr.h"
#include "rpsc.h"
#include "Parser.h"
#include <stdio.h>
#include <ctype.h>
//extern struct Sheet *cur_sh;
%}
%option outfile="Lexer.c" header-file="Lexer.h"
%option warn nodefault
%option reentrant noyywrap never-interactive nounistd
%option bison-bridge
LPAREN "("
RPAREN ")"
PLUS "+"
MINUS "-"
MULTIPLY "*"
DIVIDE "/"
SUM "@sum"
IF "IF"
NUMBER [0-9]+
WS [ \r\n\t]*
%%
{WS} { /* Skip blanks. */ }
{NUMBER}|([0-9]*[.][0-9]+) {
//sscanf(yytext, "%lf", &yylval->value);
yylval->value=atof(yytext);
//printf("Found NUMBER %s %lg\n",yytext,yylval->value);
return TOKEN_NUMBER; }
{IF} { return TOKEN_IF; }
\".*\" {
yylval->dstr = (char *) calloc(strlen(yytext)-1, sizeof(char));
strncpy(yylval->dstr, &yytext[1], strlen(yytext)-2);
return TOKEN_DSTRING;
}
[a-zA-Z]{1,2}[0-9]+:[a-zA-Z]{1,2}[0-9]+ {
yylval->sym = strdup(yytext);
return TOKEN_TEXT;
}
[a-zA-Z]{1,2}[0-9]+ {
char tmp[4];
int tmpi;
int len;
int col;
int ret;
len = strlen(yytext);
convert(&col, &tmpi, yytext, len);
//printf("FOUND tbl ref. %d %d -> %d %s\n",len,col,tmpi,yytext);
yylval->ent = lookat(p->cur_sh, tmpi, col);
// yylval->ent->col=col;
// yylval->ent->row=tmpi;
return TOKEN_TBL;
}
[a-zA-Z0-9 ]+![a-zA-Z]{1,2}[0-9]+ {
char tbl[32];
char ref[32];
char tmp[4];
int tmpi;
int len;
int col;
int ret;
sscanf(yytext,"%32[a-z|A-Z|0-9]!%s",tbl,ref);
printf("FOUND tbl ref %s %s %s\n", yytext, tbl, ref);
len = strlen(ref);
convert(&col,&tmpi,ref,len);
printf("FOUND tbl ref. %d %d -> %d %s\n", len, col, tmpi, ref);
yylval->ent = lookat(Search_sheet(p,tbl), tmpi, col);
return TOKEN_TBL;
}
'[a-zA-Z0-9 ]+'![a-zA-Z]{1,2}[0-9]+ {
char tbl[32];
char ref[32];
char tmp[4];
int tmpi;
int len;
int col;
int ret;
sscanf(yytext,"\'%32[^\']\'!%s",tbl,ref);
printf("FOUND tbl ref %s %s %s\n",yytext,tbl,ref);
len=strlen(ref);
convert(&col, &tmpi, ref, len);
printf("FOUND tbl ref. %d %d -> %d %s\n",len,col,tmpi,ref);
yylval->ent = lookat(Search_sheet(p,tbl),tmpi,col);
return TOKEN_TBL;
}
[a-zA-Z_]+ { int type;
yylval->sym=search_func(yytext,&type);
if(yylval->sym != 0) {
if(type==FUNC_RANGE)
return TOKEN_FUNCR;
if(type==FUNC_MATH1)
return TOKEN_FUNCM1;
}
yylval->sym=find_symbol(yytext);
if(yylval->sym !=0 ) return TOKEN_VAR;
yylval->sym=strdup(yytext);
return TOKEN_TEXT;
}
{MULTIPLY} { return TOKEN_MULTIPLY; }
{DIVIDE} { return TOKEN_DIVIDE; }
{PLUS} { return TOKEN_PLUS; }
{MINUS} { return TOKEN_MINUS; }
{LPAREN} { return TOKEN_LPAREN; }
{RPAREN} { return TOKEN_RPAREN; }
. { return yytext[0]; }
%%
//int yyerror(void *p1, void *p2 , void *p3, const char *msg) {
// fprintf(stderr,"YY Error: %s \n",msg); return 0;
//}