-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokens.l
58 lines (52 loc) · 2.04 KB
/
tokens.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
%{
#include <string>
#include "../Nodes/Node.h"
#include "../Parser/parser.hpp"
#define SAVE_TOKEN yylval.string = new std::string(yytext, yyleng)
#define TOKEN(t) (yylval.token = t)
//typedef struct yy_buffer_state * YY_BUFFER_STATE;
//extern YY_BUFFER_STATE yy_scan_string(char * str);
extern "C" int yywrap() { }
%}
ident [a-zA-Z_][a-zA-Z0-9_]*
whitesp [ \t\n]
text [a-zA-Z._]*[a-zA-Z]+
%%
\/\/.* ;
\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/ ;
[@]+{text} SAVE_TOKEN; return TSPACE;
["#"]{text} SAVE_TOKEN; return TSOURCE;
[p|r|d|l|u|n|c|i|w|e]+ SAVE_TOKEN; return TCMD;
[0-9]+ SAVE_TOKEN; return TINTEGER;
[0-9]+[.][0-9]+ SAVE_TOKEN; return TDOUBLE;
"@" return TOKEN(TATSIGN);
"$" return TOKEN(TDOLLAR);
"#" return TOKEN(TSHARP);
"=" return TOKEN(TEQUAL);
"==" return TOKEN(TCEQ);
"!=" return TOKEN(TCNE);
"!" return TOKEN(TNOT);
"<" return TOKEN(TCLT);
"<=" return TOKEN(TCLE);
">" return TOKEN(TCGT);
">=" return TOKEN(TCGE);
"(" return TOKEN(TLPAREN);
")" return TOKEN(TRPAREN);
"[" return TOKEN(TLBRACK);
"]" return TOKEN(TRBRACK);
"{" return TOKEN(TLBRACE);
"}" return TOKEN(TRBRACE);
"," return TOKEN(TCOMMA);
";" return TOKEN(TSEMCOLN);
"?" return TOKEN(TQUESTION);
"+" return TOKEN(TPLUS);
"-" return TOKEN(TMINUS);
"*" return TOKEN(TMUL);
"/" return TOKEN(TDIV);
"%" return TOKEN(TMOD);
"^" return TOKEN(TPOW);
{text} SAVE_TOKEN; return TTEXT;
{ident} SAVE_TOKEN; return TIDENTIFIER;
{whitesp}+ ;
. yyterminate();
%%