Line data Source code
1 : %{
2 : #include "lang.h"
3 : #include "parser.h"
4 :
5 : #define EXTRA ((struct lgfs2_lang_state *)yyextra)
6 :
7 : #define P(token, type, text) do {\
8 : *(yylval) = ast_new(type, text);\
9 : if (*(yylval) == NULL) {\
10 : EXTRA->ls_errnum = errno;\
11 : return 1;\
12 : }\
13 : return (TOK_##token);\
14 : } while(0)
15 :
16 : #define COLNUM EXTRA->ls_colnum
17 : #define YY_USER_ACTION COLNUM += yyleng;
18 :
19 : %}
20 : %option bison-bridge reentrant
21 : %option warn debug
22 : %option nounput noinput
23 : %option noyywrap
24 : %option extra-type="struct lgfs2_lang_state *"
25 :
26 : letter [a-zA-Z_]
27 : decdigit [0-9]
28 : decnumber -?{decdigit}+
29 : hexdigit [0-9a-fA-F]
30 : hexnumber -?0x{hexdigit}+
31 : number ({decnumber}|{hexnumber})
32 : offset \+{number}
33 : id {letter}({letter}|{decdigit}|\.)*
34 : string \'([^\']|\\\')*\'
35 : path \'\/([^\']|\\\')*\'
36 : ccomment \/\/.*\n
37 : shcomment \#.*\n
38 : comment ({ccomment}|{shcomment})
39 : whitespace [ \t\r]+
40 :
41 : %%
42 :
43 : \{ {
44 8 : return TOK_LBRACE;
45 : }
46 : \} {
47 8 : return TOK_RBRACE;
48 8 : }
49 : \[ {
50 0 : return TOK_LBRACKET;
51 0 : }
52 : \] {
53 0 : P(RBRACKET, AST_EX_SUBSCRIPT, "[ ]");
54 0 : }
55 : \, {
56 0 : return TOK_COMMA;
57 0 : }
58 : \: {
59 8 : P(COLON, AST_EX_FIELDSPEC, yytext);
60 8 : }
61 : \; {
62 0 : return TOK_SEMI;
63 0 : }
64 : set {
65 8 : P(SET, AST_ST_SET, yytext);
66 8 : }
67 : get {
68 0 : P(GET, AST_ST_GET, yytext);
69 0 : }
70 : state {
71 0 : P(STATE, AST_KW_STATE, yytext);
72 0 : }
73 : {path} {
74 1 : yytext[yyleng-1] = '\0';
75 1 : P(PATH, AST_EX_PATH, yytext + 1);
76 1 : }
77 : {string} {
78 0 : yytext[yyleng-1] = '\0';
79 0 : P(STRING, AST_EX_STRING, yytext + 1);
80 0 : }
81 : {offset} {
82 0 : P(OFFSET, AST_EX_OFFSET, yytext);
83 0 : }
84 : {number} {
85 8 : P(NUMBER, AST_EX_NUMBER, yytext);
86 8 : }
87 : {id} {
88 15 : P(ID, AST_EX_ID, yytext);
89 15 : }
90 : {comment} {
91 0 : COLNUM = 0;
92 0 : EXTRA->ls_linenum++;
93 0 : }
94 0 : <<EOF>> {
95 8 : return 0;
96 : }
97 : \n {
98 8 : COLNUM = 0;
99 8 : EXTRA->ls_linenum++;
100 8 : }
101 8 : {whitespace} ;
102 40 : . {
103 40 : printf("Unexpected character '%s' on line %d column %d\n",
104 0 : yytext, yylineno, COLNUM);
105 0 : return 1;
106 : }
107 :
108 0 : %%
|