2 #define YYSTYPE SLTNode *
3 #define YY_USER_ACTION yyadvancelocation(yylloc, yyleng, yytext);
5 #include <sun/compiler/compiler_internal.h>
6 #include <sun/tree/node.h>
7 #include "sun_parser.h"
12 static void yyadvancelocation(YYLTYPE *location, long length, const char *text);
14 #define YY_INPUT(buf, result, max_size) result = yyextra->readCallback(buf, max_size, yyextra->readCallbackParameter);
16 //#define YY_DECL int yylex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner, SunSourceReadCallback readCallback)
20 %option bison-locations
21 %option never-interactive
26 %option extra-type="SLCLexerExtra *"
33 "//" { BEGIN(SL_COMMENT); }
34 <SL_COMMENT>\n { BEGIN(INITIAL); }
35 <SL_COMMENT>. ; /* Eat comments */
37 "/*" { BEGIN(ML_COMMENT); }
38 <ML_COMMENT>"*/" { BEGIN(INITIAL); }
39 <ML_COMMENT>\n ; /* Eat comments */
40 <ML_COMMENT>. ; /* Eat comments */
42 [ \t\n] ; /* Eat whitespace */
45 "else" { return ELSE; }
48 "while" { return WHILE; }
49 "break" { return BREAK; }
50 "struct" { return TYPE; }
52 "return" { return RETURN; }
53 "sleep" { return SLEEP; }
55 "false" { *yylval = sltNodeMakeBoolean(false); return BOOL_FALSE; }
56 "true" { *yylval = sltNodeMakeBoolean(true); return BOOL_TRUE; }
58 "+=" { return ADD_ASSIGN; }
59 "-=" { return SUBTRACT_ASSIGN; }
60 "*=" { return MULTIPLY_ASSIGN; }
61 "/=" { return DIVIDE_ASSIGN; }
62 "%=" { return MOD_ASSIGN; }
64 "&&" { return LOGICAL_AND; }
65 "||" { return LOGICAL_OR; }
67 "==" { return EQUAL; }
68 "!=" { return NOT_EQUAL; }
69 "<=" { return LT_EQUAL; }
70 ">=" { return GT_EQUAL; }
72 /*"++" { return INCREMENT; }
73 "--" { return DECREMENT; }*/
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; }
79 @\"[^\"\n]*\" { *yylval = sltNodeMakeKey(yytext); return STRING; }
80 \"[^\"\n]*\" { *yylval = sltNodeMakeString(yytext); return STRING; }
82 [a-zA-Z0-9_]+ { *yylval = sltNodeMakeIdentifier(yytext); return IDENTIFIER; }
84 . { return yytext[0]; }
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;
92 for (long i = 0; i < length; ++i) {
93 if (text[i] == '\n') {
94 ++location->last_line;
95 location->last_column = 0;
97 ++location->last_column;