-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexp.l
More file actions
71 lines (47 loc) · 1.12 KB
/
exp.l
File metadata and controls
71 lines (47 loc) · 1.12 KB
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
%{
#define YYSTYPE double
#include "exp.tab.h"
#include <cstdlib>
int yyparse(void);
extern "C" int yylex();
float scanit(char s[], int indx)
{
YY_BUFFER_STATE ybs;
extern float yyanswer;
extern int yy_indx;
yy_indx = indx;
ybs = yy_scan_string(s);
yyparse();
yy_delete_buffer(ybs);
return(yyanswer);
}
%}
white [ \t]+
digit [0-9]
integer {digit}+
exponant [eE][+-]?{integer}
real {integer}("."{integer})?{exponant}?
%%
{white} { /* We ignore white characters */ }
{real} {
yylval=atof(yytext);
return(NUMBER);
}
[A-P] { yylval = yytext[0] - 'A'; return(VARIABLE); }
"+" return(PLUS);
"-" return(MINUS);
"*" return(TIMES);
"/" return(DIVIDE);
"^" return(POWER);
"(" return(LEFT_PARENTHESIS);
")" return(RIGHT_PARENTHESIS);
sqrt return SQRT;
ln return LN;
log return LOG;
exp return EXP;
sin return SIN;
cos return COS;
tan return TAN;
abs return ABS;
"\0" return(END);
"\n" return(END);