source: trunk/test/sandbox/lex/lolfx.l @ 1410

Last change on this file since 1410 was 1410, checked in by sam, 9 years ago

test: some grammar tweaks.

File size: 835 bytes
Line 
1%{
2#include <iostream>
3#define YY_DECL extern "C" int yylex()
4#include "lolfx.tab.h"
5%}
6
7%x C_COMMENT
8%x CPP_COMMENT
9
10%%
11
12 /*
13  * Our language's keywords
14  */
15
16"technique"    { return TECHNIQUE; }
17"pass"         { return PASS; }
18
19 /*
20  * Various tokens
21  */
22
23[0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; }
24[0-9]+         { yylval.ival = atoi(yytext); return INT; }
25[a-zA-Z][a-zA-Z0-9_]*  {
26    /* Copy token for now */
27    yylval.sval = strdup(yytext);
28    return NAME;
29}
30[ \t\n]+       ;
31.              { return *yytext; }
32
33 /*
34  * Ignore C comments
35  */
36
37"/*"              { BEGIN(C_COMMENT); }
38<C_COMMENT>"*/"   { BEGIN(INITIAL); }
39<C_COMMENT>[^*]*  { }
40<C_COMMENT>.      { }
41
42 /*
43  * Ignore C++ comments
44  */
45
46"//"              { BEGIN(CPP_COMMENT); }
47<CPP_COMMENT>\n   { BEGIN(INITIAL); }
48<CPP_COMMENT>.*   { }
49
50%%
51
Note: See TracBrowser for help on using the repository browser.