forked from MorganBauer/COP-6726-Databases-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LexerFunc.l
83 lines (55 loc) · 1.93 KB
/
LexerFunc.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
/***********************************************************************
* SECTION 1
***********************************************************************/
/* The code in %{ %} is included as it is in lex.yy.c file
* it has C global variables, prototypes, and comments
*/
%{
#include <string.h> // For strdup()
#include <stdlib.h> // For malloc()
#include "ParseTree.h"
#include "yyfunc.tab.h"
//int yyfunclineno = 1;
void yyfuncerror(char*s);
static YY_BUFFER_STATE yyfunc_buf_state;
void init_lexical_parser_func (char *src) { yyfunc_buf_state = yyfunc_scan_string (src); }
void close_lexical_parser_func () { yyfunc_delete_buffer (yyfunc_buf_state); }
%}
/******************************************************************************
* SECTION 2
******************************************************************************/
/* This is the DEFINITION section which contains substitutions, code, and
* start stats; will be copied into lex.yy.c
*/
/******************************************************************************
* SECTION 3
******************************************************************************/
/* This is the RULES section which defines how to "scan" and what action
* to take for each token
*/
%%
"(" return('(');
")" return(')');
"+" return('+');
"-" return('-');
"/" return('/');
"*" return('*');
-?[0-9]+ {yyfunclval.actualChars = strdup(yyfunctext);
return(Int);
}
-?[0-9]+\.[0-9]* {yyfunclval.actualChars = strdup(yyfunctext);
return(Float);
}
[A-Za-z][A-Za-z0-9_-]* {yyfunclval.actualChars = strdup(yyfunctext);
return(Name);
}
\n yyfunclineno++;
[ \t] ;
. yyfuncerror("LEX_ERROR: invalid character");
%%
void yyfuncerror(char *s) {
printf("%d: %s at %s\n", yyfunclineno, s, yyfunctext);
}
int yyfuncwrap(void){
return 1;
}