-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.l
83 lines (70 loc) · 2.56 KB
/
expr.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
%option noyywrap
%option prefix="exp"
%option yylineno
%{
#include <stdio.h>
#include <stdlib.h>
#include "expr.tab.h"
char *expp;
extern int expwrap(void);
int expcolumn = 1;
#define explineno yylineno
#define expleng yyleng
#define YY_USER_ACTION explloc.first_line = explloc.last_line = explineno; \
explloc.first_column = expcolumn; explloc.last_column = expcolumn+expleng-1; \
expcolumn += expleng;
%}
NUM [0-9]+
NOVAR_WORD (\$[-a-zA-Z0-9"_/.!\*\+@:\<\>#$}\[\]]|\{[-a-zA-Z0-9"_/.!\*\+@:\<\>#\$\{}\[\]]|[-a-zA-Z0-9"_/.!\*\+@:\<\>#}\[\]])*
VAR \$\{[^\$\}]*(\$\{[^\$\}]*\})*[^\$\}]*\}
%%
= { /*printf("EQ\n");*/ return EQ; }
\) { /*printf("RPAREN\n");*/ return RPAREN; }
\( { /*printf("LPAREN\n");*/ return LPAREN; }
\} { /*printf("KET\n");*/ return KET; }
\{ { /*printf("BRA\n");*/ return BRA; }
"]" { /*printf("RSBRA\n");*/return RSBRA; }
: { /*printf("COLON\n");*/ return COLON; }
; { /*printf("SEMICOLON\n");*/ return SEMICOLON; }
, { /*printf("COMMA\n");*/ return COMMA; }
"=>" { /*printf("ARROW\n");*/ return ARROW; }
\| { /*printf("PIPE\n");*/return PIPE; }
@ { /*printf("AT\n");*/return AT; }
& { /*printf("AND\n");*/return AND; }
"$[" { /*printf("EXPRINIT\n");*/return EXPRINIT;}
"!=" { /*printf("NOTEQ\n");*/return NOTEQ; }
"==" { /*printf("EQUAL\n");*/return EQUAL;}
">" { /*printf("GT\n");*/return GT; }
"<" { /*printf("LT\n");*/return LT; }
">=" { /*printf("GTEQ\n");*/return GTEQ; }
"<=" { /*printf("LTEQ\n");*/return LTEQ; }
"+" { /*printf("PLUS\n");*/return PLUS; }
"-" { /*printf("MINUS\n");*/return MINUS; }
"*" { /*printf("MULT\n");*/return MULT; }
"/" { /*printf("DIV\n");*/return DIV; }
"%" { /*printf("MOD\n");*/return MOD; }
"!" { /*printf("LOGNOT\n");*/return LOGNOT; }
"=~" { /*printf("LIKEOP\n");*/return LIKEOP; }
"?" { /*printf("CONDQUEST\n");*/return CONDQUEST; }
{NUM} {
/*printf("VARNAME (%s)\n",yytext);*/
expp = (char*)calloc(strlen(yytext)+1,sizeof(char));
strcpy(expp,yytext);
explval = (YYSTYPE)expp;
return NUM;
}
{VAR} {
/*printf("VARNAME (%s)\n",yytext);*/
expp = (char*)calloc(strlen(yytext)+1,sizeof(char));
strcpy(expp,yytext);
explval = (YYSTYPE)expp;
return VAR;
}
{NOVAR_WORD} {
/*printf("VARNAME (%s)\n",yytext);*/
expp = (char*)calloc(strlen(yytext)+1,sizeof(char));
strcpy(expp,yytext);
explval = (YYSTYPE)expp;
return NOVAR_WORD;
}
%%