]> git.bts.cx Git - sun.git/blob - runtime/src/sun/compiler/sun.l
Fixed syntax for definitions
[sun.git] / runtime / src / sun / compiler / sun.l
1 %{
2 #define YYSTYPE SLTNode *
3 #define YY_USER_ACTION yyadvancelocation(yylloc, yyleng, yytext);
4
5 #include <sun/compiler/compiler_internal.h>
6 #include <sun/tree/node.h>
7 #include "sun_parser.h"
8
9 #include <stdbool.h>
10 #include <stdio.h>
11
12 static void yyadvancelocation(YYLTYPE *location, long length, const char *text);
13
14 #define YY_INPUT(buf, result, max_size) result = yyextra->readCallback(buf, max_size, yyextra->readCallbackParameter);
15
16 //#define YY_DECL int yylex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner, SunSourceReadCallback readCallback)
17 %}
18
19 %option bison-bridge
20 %option bison-locations
21 %option never-interactive
22 %option noyywrap
23 %option nounput
24 %option noinput
25 %option reentrant
26 %option extra-type="SLCLexerExtra *"
27
28 %x SL_COMMENT
29 %x ML_COMMENT
30
31 %%
32
33 "//" { BEGIN(SL_COMMENT); }
34 <SL_COMMENT>\n { BEGIN(INITIAL); }
35 <SL_COMMENT>. ; /* Eat comments */
36
37 "/*" { BEGIN(ML_COMMENT); }
38 <ML_COMMENT>"*/" { BEGIN(INITIAL); }
39 <ML_COMMENT>\n ; /* Eat comments */
40 <ML_COMMENT>. ; /* Eat comments */
41
42 [ \t\n] ; /* Eat whitespace */
43
44 "if" { return IF; }
45 "else" { return ELSE; }
46 "for" { return FOR; }
47 "do" { return DO; }
48 "while" { return WHILE; }
49 "break" { return BREAK; }
50 "struct" { return TYPE; }
51
52 "return" { return RETURN; }
53 "sleep" { return SLEEP; }
54
55 "false" { *yylval = sltNodeMakeBoolean(false); return BOOL_FALSE; }
56 "true" { *yylval = sltNodeMakeBoolean(true); return BOOL_TRUE; }
57
58 "+=" { return ADD_ASSIGN; }
59 "-=" { return SUBTRACT_ASSIGN; }
60 "*=" { return MULTIPLY_ASSIGN; }
61 "/=" { return DIVIDE_ASSIGN; }
62 "%=" { return MOD_ASSIGN; }
63
64 "&&" { return LOGICAL_AND; }
65 "||" { return LOGICAL_OR; }
66
67 "==" { return EQUAL; }
68 "!=" { return NOT_EQUAL; }
69 "<=" { return LT_EQUAL; }
70 ">=" { return GT_EQUAL; }
71
72 /*"++" { return INCREMENT; }
73 "--" { return DECREMENT; }*/
74
75 [0-9]+\.[0-9]+ { *yylval = sltNodeMakeFloat(atof(yytext)); return FLOAT; }
76 [0-9]+ { *yylval = sltNodeMakeInteger(atoi(yytext)); return INT; }
77 i[0-9]+ { *yylval = sltNodeMakeRawInteger(atoi(&yytext[1])); return INT; }
78
79 @\"[^\"\n]*\" { *yylval = sltNodeMakeKey(yytext); return STRING; }
80 \"[^\"\n]*\" { *yylval = sltNodeMakeString(yytext); return STRING; }
81
82 [a-zA-Z0-9_]+ { *yylval = sltNodeMakeIdentifier(yytext); return IDENTIFIER; }
83
84 . { return yytext[0]; }
85
86 %%
87
88 static void yyadvancelocation(YYLTYPE *location, long length, const char *text) {
89 location->first_column = location->last_column;
90 location->first_line = location->last_line;
91
92 for (long i = 0; i < length; ++i) {
93 if (text[i] == '\n') {
94 ++location->last_line;
95 location->last_column = 0;
96 } else {
97 ++location->last_column;
98 }
99 }
100 }