-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
68 lines (66 loc) · 1.73 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
%{
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include "types.hpp"
#include "syntax.tab.hpp"
#include <string>
#include <readline/readline.h>
static char* residue_string=NULL;
static char* input_line=NULL;
extern std::string begin_line;
#define YY_INPUT(buf,result,max_size) \
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
if(!residue_string)\
{\
input_line=readline(begin_line.c_str());\
residue_string=input_line;\
}\
size_t n; \
if(input_line)\
for ( n = 0; n < max_size-1 && residue_string[n]!='\0'; ++n ) \
{\
buf[n] = residue_string[n]; \
}\
buf[n++]='\n';\
if(n==max_size && (input_line[n]!='\0' || input_line[n]!=EOF))\
residue_string=&input_line[n+1];\
else \
{\
residue_string=NULL;\
free(input_line);\
}\
result = n; \
} \
else \
{ \
errno=0; \
while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
YY_FATAL_ERROR( "input in flex scanner failed" ); \
break; \
} \
errno=0; \
clearerr(yyin); \
} \
}
%}
%%
[a-zA-Z_\-/][a-zA-Z0-9_\-/]* yylval.str=strdup(yytext); return WORD;
[0-9]+ yylval.num=atoi(yytext); return NUM;
[0-9]+"."[0-9]* yylval.num=atof(yytext); return NUM;
\. return DOT;
[ \t]+ return ' ';/* пропускаем пробелы и табы, возвращаем 1 пробел*/;
[ \t]*\([ \t]* return '(';
[ \t]*\)[ \t]* return ')';
[ \t]*\,[ \t]* return ',';
[ \t]*\;[ \t]* return ';';
\n return '\n';
\| return CONVEY;
&& return AND;
\|\| return OR;
\'.*\' return ANYTHING;
%%