-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinguo.l
More file actions
64 lines (59 loc) · 2.74 KB
/
linguo.l
File metadata and controls
64 lines (59 loc) · 2.74 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
%{
#include <string>
#include "ast.h"
#include "linguo.tab.hpp"
#define SAVE_TOKEN yylval.string = new std::string(yytext, yyleng)
#define TOKEN(t) (yylval.token = t)
%}
%option noyywrap
%%
[ \t\r\n]+ { /* Skip whitespace */ }
"//".* { /* Skip comments */ }
"remember" return TOKEN(TREMEMBER);
"as" return TOKEN(TAS);
"say" return TOKEN(TSAY);
"when" return TOKEN(TWHEN);
"or" return TOKEN(TOR);
"done" return TOKEN(TDONE);
"end" return TOKEN(TEND);
"becomes" return TOKEN(TASSIGN);
"do" return TOKEN(TDO);
"this" return TOKEN(TTHIS);
"times" return TOKEN(TTIMES);
"create" return TOKEN(TCREATE);
"call" return TOKEN(TCALL);
"increase" return TOKEN(TINCREASE);
"decrease" return TOKEN(TDECREASE);
"multiply" return TOKEN(TMULTIPLY);
"divide" return TOKEN(TDIVIDE);
"by" return TOKEN(TBY);
"is" return TOKEN(TIS);
"equal" return TOKEN(TEQUAL);
"to" return TOKEN(TTO);
"not" return TOKEN(TNOT);
"more" return TOKEN(TMORE);
"than" return TOKEN(TTHAN);
"less" return TOKEN(TLESS);
"and" return TOKEN(TAND);
"or" return TOKEN(TOR_OP);
"give" return TOKEN(TGIVE);
"back" return TOKEN(TBACK);
"true" { yylval.boolean = true; return TBOOL; }
"false" { yylval.boolean = false; return TBOOL; }
"with" return TOKEN(TWITH); // New token for parameter lists
[a-zA-Z_][a-zA-Z0-9_]* SAVE_TOKEN; return TIDENTIFIER;
[0-9]+ { yylval.integer = atoi(yytext); return TINTEGER; }
\"([^\"]|\\\")*\" {
std::string str(yytext + 1, yyleng - 2);
yylval.string = new std::string(str);
return TSTRING;
}
"+" return TOKEN(TPLUS);
"-" return TOKEN(TMINUS);
"*" return TOKEN(TMUL);
"/" return TOKEN(TDIV);
"(" return TOKEN(TLPAREN);
")" return TOKEN(TRPAREN);
"," return TOKEN(TCOMMA); // New token for separating parameters
. printf("Invalid character: %s\n", yytext);
%%