Debian Codegraph @

xo/res_y.y

raw
1 %{
2 /* res_y.y
3 $Id: res_y.y,v 1.7 1997/10/18 04:57:42 elf Exp $
4
5 This file is part of the project XO. See the file README for
6 more information.
7
8 Copyright (C) 1997 Marc Singer
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 in a file called COPYING along with this program; if not, write to
22 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
23 02139, USA.
24
25 -----------
26 DESCRIPTION
27 -----------
28
29 Grammar for dialog parser.
30
31 */
32
33 #include "standard.h"
34 #define IS_PARSER
35 #include "lres.h"
36 #include <string.h>
37
38 #if defined (__cplusplus)
39 extern "C" int yylex (void);
40 #else
41 int yylex (void);
42 #endif
43
44 int yyerror (const char* sz);
45 extern FILE* yyout;
46
47 int g_cBraceOpen; /* Count of open braces */
48 int g_cParenOpen; /* Count of open parentheses */
49 int g_cConst; /* Count of open constant expressions */
50
51 //#define DPRINTF(a) printf a
52 #define DPRINTF(a)
53 //#define _in(p) ((char*) p - (char*) g_pvNodeAlloc)
54
55 %}
56
57 %token PO PC /* Parenthesis Open and Close */
58 %token BO BC /* Brace Open and Close */
59 %token QUOTE /* Quote mark to inhibit lambda binding */
60
61 %union {
62 long l; /* Constant numeric value */
63 float r; /* Real number value */
64 char* sz; /* String literal */
65 int er; /* Error value */
66 NODE* pNode;
67 }
68 %token <l> INTEGER
69 %token <r> REAL
70 %token <sz> STRING
71 %token <sz> KEYWORD
72 %token <er> ERROR
73 %token <pNode> RESOURCE
74 %token <pNode> INVOCATION
75 %token <pNode> ARGLIST
76
77 %type <pNode> keyword
78 %type <pNode> argument argument_list argument_list_d
79 %type <pNode> invocation invocation_list invocation_list_d
80 %type <pNode> resource_file
81
82 %%
83
84
85 resource_file:
86 invocation_list
87 {
88 LResNode::fixup ((LResNode*) $$);
89 LResNode::generate ((LResNode*) $$);
90 }
91 ;
92
93 invocation_list:
94 invocation
95 {
96 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
97 DPRINTF (("RESOURCE 0x%x -> 0x%x\n", _in ($$), _in ($1)));
98 $$->type = RESOURCE;
99 $$->v.pNode = $1;
100 }
101 | invocation_list invocation
102 {
103 DPRINTF (("RESOURCE+ 0x%x -> 0x%x\n", _in ($1), _in ($2)));
104 $2->pNode = $1->v.pNode;
105 $1->v.pNode = $2;
106 $$ = $1;
107 }
108 ;
109
110 invocation:
111 keyword
112 {
113 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
114 DPRINTF (("INVOCATION <%s> @0x%x\n", $1->v.sz, _in ($$)));
115 $$->type = INVOCATION;
116 $$->v.pNode = $1;
117 }
118 | keyword argument_list_d
119 {
120 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
121 DPRINTF (("INVOCATION <%s> @0x%x a 0x%x\n",
122 $1->v.sz, _in ($$), _in ($2)));
123 $$->type = INVOCATION;
124 $$->v.pNode = $1;
125 $1->pNode = $2;
126 }
127 | keyword invocation_list_d
128 {
129 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
130 DPRINTF (("INVOCATION <%s> @0x%x i 0x%x\n",
131 $1->v.sz, _in ($$), _in ($2)));
132 $$->type = INVOCATION;
133 $$->v.pNode = $1;
134 $1->pNode = $2;
135 }
136 | keyword argument_list_d invocation_list_d
137 {
138 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
139 DPRINTF (("INVOCATION <%s> @0x%x a 0x%x i 0x%x\n",
140 $1->v.sz, _in ($$), _in ($2), _in ($3)));
141 $$->type = INVOCATION;
142 $$->v.pNode = $1;
143 $1->pNode = $2;
144 $2->pNode = $3;
145 }
146 ;
147
148 invocation_list_d:
149 BO invocation_list BC { $$ = $2; }
150 | BO BC
151 {
152 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
153 DPRINTF (("invocation_list @0x%x\n", _in ($$)));
154 $$->type = INVOCATION;
155 }
156 ;
157
158 argument_list_d:
159 PO argument_list PC { $$ = $2; }
160 | PO PC
161 {
162 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
163 DPRINTF (("argument_list @0x%x\n", _in ($$)));
164 $$->type = ARGLIST;
165 }
166 ;
167
168 argument_list:
169 argument
170 {
171 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
172 DPRINTF (("argument_list @0x%x => @0x%x\n",
173 _in ($$), _in ($1)));
174 $$->type = ARGLIST;
175 $$->v.pNode = $1;
176 }
177 | argument_list ',' argument
178 {
179 DPRINTF ((" 0x%x => 0x%x\n", _in ($1), _in ($3)));
180 $3->pNode = $1->v.pNode;
181 $1->v.pNode = $3;
182 $$ = $1;
183 }
184 ;
185
186 keyword:
187 KEYWORD
188 {
189 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
190 DPRINTF (("KEYWORD @0x%x\n", _in ($$)));
191 $$->type = KEYWORD;
192 $$->v.sz = $1;
193 }
194 ;
195
196 argument:
197 STRING
198 {
199 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
200 DPRINTF (("STRING @0x%x\n", _in ($$)));
201 $$->type = STRING;
202 $$->v.sz = $1;
203 }
204 | INTEGER
205 {
206 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
207 DPRINTF (("INTEGER @0x%x\n", _in ($$)));
208 $$->type = INTEGER;
209 $$->v.l = $1;
210 }
211 | REAL
212 {
213 $$ = (NODE*) LResNode::alloc (sizeof (NODE), NULL);
214 DPRINTF (("REAL @0x%x\n", _in ($$)));
215 $$->type = REAL;
216 $$->v.r = $1;
217 }
218 ;
219
220 %%
221
222 int yyerror (const char* sz)
223 {
224 extern int g_iLineParse;
225 extern char *yytext;
226 /* printf ("%d: %s at '%s'\n", yylineno, sz, yytext); */
227 printf("error: line %d, %s at '%s'\n", g_iLineParse, sz, yytext);
228 // printf ("yyerror: %s\n", sz);
229 return 0;
230 }
231