summaryrefslogtreecommitdiff
path: root/lua.lex
blob: 23a1d7b17301e65caebae05ea5c2236a6a13b7c6 (plain)
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
82
83
84
85
%{

char *rcs_lualex = "$Id: $";

#include <stdlib.h>
#include <string.h>

#include "opcode.h"
#include "hash.h"
#include "inout.h"
#include "table.h"
#include "y.tab.h"

#undef input
#undef unput

static Input input;
static Unput unput;

void lua_setinput (Input fn)
{
 input = fn;
}

void lua_setunput (Unput fn)
{
 unput = fn;
}

char *lua_lasttext (void)
{
 return yytext;
}

%}


%%
[ \t]*					;
^"$debug"				{yylval.vInt = 1; return DEBUG;}
^"$nodebug"				{yylval.vInt = 0; return DEBUG;}
\n					lua_linenumber++;
"--".*					;
"local"					return LOCAL;
"if"					return IF;
"then"					return THEN;
"else"					return ELSE;
"elseif"				return ELSEIF;
"while"					return WHILE;
"do"					return DO;
"repeat"				return REPEAT;
"until"					return UNTIL;
"function"				{
                                         yylval.vWord = lua_nfile-1;
                                         return FUNCTION;
					}
"end"					return END;
"return" 				return RETURN;
"local" 				return LOCAL;
"nil"					return NIL;
"and"					return AND;
"or"					return OR;
"not"					return NOT;
"~="					return NE;
"<="					return LE;
">="					return GE;
".."					return CONC;
\"[^\"]*\" 			| 
\'[^\']*\'			      {
				       yylval.vWord = lua_findenclosedconstant (yytext);
				       return STRING;
				      }
[0-9]+("."[0-9]*)?	|
([0-9]+)?"."[0-9]+	|
[0-9]+("."[0-9]*)?[dDeEgG][+-]?[0-9]+ |
([0-9]+)?"."[0-9]+[dDeEgG][+-]?[0-9]+ {
				        yylval.vFloat = atof(yytext);
				        return NUMBER;
				       }
[a-zA-Z_][a-zA-Z0-9_]*  	       {
					yylval.vWord = lua_findsymbol (yytext);
					return NAME;
				       }
.					return  *yytext;