-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua.lexer
executable file
·73 lines (67 loc) · 1.69 KB
/
lua.lexer
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
%lexer
%declare{ public string str; }
%token LITERAL {
public string s;
public LITERAL( string a ){ s = a; }
}
%token COMMENT {}
%token NAME { public string s; }
%token NUMBER { public double n; }
\n|\r|\t|" " ;
"," %COMMA
":" %COLON
";" %SEMICOLON
"(" %LPAREN
")" %RPAREN
"[" %LBRACK
"]" %RBRACK
"{" %LBRACE
"}" %RBRACE
"." %DOT
"+" %PLUS
"-" %MINUS
"*" %MULT
"#" %POUND
"%" %MOD
"/" %DIVIDE
"^" %EXP
"==" %EQ
"~=" %NEQ
"<" %LT
"<=" %LE
">" %GT
">=" %GE
"and" %AND
"or" %OR
"not" %NOT
"=" %ASSIGN
"if" %IF
"then" %THEN
"else" %ELSE
"elseif" %ELSEIF
"end" %END
"while" %WHILE
"for" %FOR
"do" %DO
"in" %IN
"break" %BREAK
"nil" %NIL
"function" %FUNCTION
"repeat" %REPEAT
"until" %UNTIL
"return" %RETURN
"local" %LOCAL
"true" %TRUE
"false" %FALSE
".." %CONCAT
"..." %ELIPSE
[a-zA-Z_][A-Za-z0-9_]* %NAME { s = yytext; }
[0-9]+([.][0-9])?[0-9]* %NUMBER { n = Convert.ToDouble(yytext); }
\" { yybegin("LITERAL"); yyl.str = "\"";}
<LITERAL> \\\" { yyl.str += yytext; }
<LITERAL> \\\\ { yyl.str += yytext; }
<LITERAL> [^\"] { yyl.str += yytext; }
<LITERAL> \" { yybegin("YYINITIAL"); yyl.yytext = yyl.str + "\""; return new LITERAL(yyl.yytext); }
"--" { yybegin("COMMENT"); }
<COMMENT> [^\n] { }
<COMMENT> "\n" { yybegin("YYINITIAL"); }