Mercurial > audlegacy-plugins
comparison src/paranormal-ng/libcalc/parser.c @ 2078:1fa3c8cd366a
paranormal-ng: a GL visualiser. lots to do, most stuff won't work, but hey, this will do cool stuff too soon
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Mon, 15 Oct 2007 06:20:13 -0500 |
parents | |
children | f1b6f1b2cdb3 |
comparison
equal
deleted
inserted
replaced
2077:e5b639ab62b0 | 2078:1fa3c8cd366a |
---|---|
1 /* A Bison parser, made by GNU Bison 1.875d. */ | |
2 | |
3 /* Skeleton parser for Yacc-like parsing with Bison, | |
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. | |
5 | |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software | |
18 Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* As a special exception, when this file is copied by Bison into a | |
22 Bison output file, you may use that output file without restriction. | |
23 This special exception was added by the Free Software Foundation | |
24 in version 1.24 of Bison. */ | |
25 | |
26 /* Written by Richard Stallman by simplifying the original so called | |
27 ``semantic'' parser. */ | |
28 | |
29 /* All symbols defined below should begin with yy or YY, to avoid | |
30 infringing on user name space. This should be done even for local | |
31 variables, as they might otherwise be expanded by user macros. | |
32 There are some unavoidable exceptions within include files to | |
33 define necessary library symbols; they are noted "INFRINGES ON | |
34 USER NAME SPACE" below. */ | |
35 | |
36 /* Identify Bison output. */ | |
37 #define YYBISON 1 | |
38 | |
39 /* Skeleton name. */ | |
40 #define YYSKELETON_NAME "yacc.c" | |
41 | |
42 /* Pure parsers. */ | |
43 #define YYPURE 1 | |
44 | |
45 /* Using locations. */ | |
46 #define YYLSP_NEEDED 0 | |
47 | |
48 | |
49 | |
50 /* Tokens. */ | |
51 #ifndef YYTOKENTYPE | |
52 # define YYTOKENTYPE | |
53 /* Put the tokens into the symbol table, so that GDB and other debuggers | |
54 know about them. */ | |
55 enum yytokentype { | |
56 NAME = 258, | |
57 NUMBER = 259, | |
58 NEG = 260 | |
59 }; | |
60 #endif | |
61 #define NAME 258 | |
62 #define NUMBER 259 | |
63 #define NEG 260 | |
64 | |
65 | |
66 | |
67 | |
68 /* Copy the first part of user declarations. */ | |
69 #line 26 "parser.y" | |
70 | |
71 #include <ctype.h> | |
72 #include <glib.h> | |
73 #include <locale.h> | |
74 #include <math.h> | |
75 #include <stdio.h> | |
76 #include <string.h> | |
77 | |
78 #include "dict.h" | |
79 #include "execute.h" | |
80 #include "function.h" | |
81 #include "parser.h" | |
82 #include "storage.h" | |
83 | |
84 #define YYPARSE_PARAM yyparam | |
85 #define YYLEX_PARAM yyparam | |
86 | |
87 static gboolean expr_add_compile (expression_t *expr, symbol_dict_t *dict, | |
88 char *str); | |
89 | |
90 #define GENERATE(str) if (!expr_add_compile (((parser_control *)yyparam)->expr, \ | |
91 ((parser_control *)yyparam)->dict, str)) \ | |
92 YYABORT; | |
93 | |
94 | |
95 /* Enabling traces. */ | |
96 #ifndef YYDEBUG | |
97 # define YYDEBUG 0 | |
98 #endif | |
99 | |
100 /* Enabling verbose error messages. */ | |
101 #ifdef YYERROR_VERBOSE | |
102 # undef YYERROR_VERBOSE | |
103 # define YYERROR_VERBOSE 1 | |
104 #else | |
105 # define YYERROR_VERBOSE 0 | |
106 #endif | |
107 | |
108 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) | |
109 #line 54 "parser.y" | |
110 typedef union YYSTYPE { | |
111 char *s_value; | |
112 char c_value; | |
113 double d_value; | |
114 int i_value; | |
115 } YYSTYPE; | |
116 /* Line 191 of yacc.c. */ | |
117 #line 118 "parser.c" | |
118 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ | |
119 # define YYSTYPE_IS_DECLARED 1 | |
120 # define YYSTYPE_IS_TRIVIAL 1 | |
121 #endif | |
122 | |
123 | |
124 | |
125 /* Copy the second part of user declarations. */ | |
126 | |
127 | |
128 /* Line 214 of yacc.c. */ | |
129 #line 130 "parser.c" | |
130 | |
131 #if ! defined (yyoverflow) || YYERROR_VERBOSE | |
132 | |
133 # ifndef YYFREE | |
134 # define YYFREE free | |
135 # endif | |
136 # ifndef YYMALLOC | |
137 # define YYMALLOC malloc | |
138 # endif | |
139 | |
140 /* The parser invokes alloca or malloc; define the necessary symbols. */ | |
141 | |
142 # ifdef YYSTACK_USE_ALLOCA | |
143 # if YYSTACK_USE_ALLOCA | |
144 # define YYSTACK_ALLOC alloca | |
145 # endif | |
146 # else | |
147 # if defined (alloca) || defined (_ALLOCA_H) | |
148 # define YYSTACK_ALLOC alloca | |
149 # else | |
150 # ifdef __GNUC__ | |
151 # define YYSTACK_ALLOC __builtin_alloca | |
152 # endif | |
153 # endif | |
154 # endif | |
155 | |
156 # ifdef YYSTACK_ALLOC | |
157 /* Pacify GCC's `empty if-body' warning. */ | |
158 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) | |
159 # else | |
160 # if defined (__STDC__) || defined (__cplusplus) | |
161 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ | |
162 # define YYSIZE_T size_t | |
163 # endif | |
164 # define YYSTACK_ALLOC YYMALLOC | |
165 # define YYSTACK_FREE YYFREE | |
166 # endif | |
167 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ | |
168 | |
169 | |
170 #if (! defined (yyoverflow) \ | |
171 && (! defined (__cplusplus) \ | |
172 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) | |
173 | |
174 /* A type that is properly aligned for any stack member. */ | |
175 union yyalloc | |
176 { | |
177 short int yyss; | |
178 YYSTYPE yyvs; | |
179 }; | |
180 | |
181 /* The size of the maximum gap between one aligned stack and the next. */ | |
182 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) | |
183 | |
184 /* The size of an array large to enough to hold all stacks, each with | |
185 N elements. */ | |
186 # define YYSTACK_BYTES(N) \ | |
187 ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \ | |
188 + YYSTACK_GAP_MAXIMUM) | |
189 | |
190 /* Copy COUNT objects from FROM to TO. The source and destination do | |
191 not overlap. */ | |
192 # ifndef YYCOPY | |
193 # if defined (__GNUC__) && 1 < __GNUC__ | |
194 # define YYCOPY(To, From, Count) \ | |
195 __builtin_memcpy (To, From, (Count) * sizeof (*(From))) | |
196 # else | |
197 # define YYCOPY(To, From, Count) \ | |
198 do \ | |
199 { \ | |
200 register YYSIZE_T yyi; \ | |
201 for (yyi = 0; yyi < (Count); yyi++) \ | |
202 (To)[yyi] = (From)[yyi]; \ | |
203 } \ | |
204 while (0) | |
205 # endif | |
206 # endif | |
207 | |
208 /* Relocate STACK from its old location to the new one. The | |
209 local variables YYSIZE and YYSTACKSIZE give the old and new number of | |
210 elements in the stack, and YYPTR gives the new location of the | |
211 stack. Advance YYPTR to a properly aligned location for the next | |
212 stack. */ | |
213 # define YYSTACK_RELOCATE(Stack) \ | |
214 do \ | |
215 { \ | |
216 YYSIZE_T yynewbytes; \ | |
217 YYCOPY (&yyptr->Stack, Stack, yysize); \ | |
218 Stack = &yyptr->Stack; \ | |
219 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ | |
220 yyptr += yynewbytes / sizeof (*yyptr); \ | |
221 } \ | |
222 while (0) | |
223 | |
224 #endif | |
225 | |
226 #if defined (__STDC__) || defined (__cplusplus) | |
227 typedef signed char yysigned_char; | |
228 #else | |
229 typedef short int yysigned_char; | |
230 #endif | |
231 | |
232 /* YYFINAL -- State number of the termination state. */ | |
233 #define YYFINAL 2 | |
234 /* YYLAST -- Last index in YYTABLE. */ | |
235 #define YYLAST 65 | |
236 | |
237 /* YYNTOKENS -- Number of terminals. */ | |
238 #define YYNTOKENS 18 | |
239 /* YYNNTS -- Number of nonterminals. */ | |
240 #define YYNNTS 5 | |
241 /* YYNRULES -- Number of rules. */ | |
242 #define YYNRULES 22 | |
243 /* YYNRULES -- Number of states. */ | |
244 #define YYNSTATES 37 | |
245 | |
246 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ | |
247 #define YYUNDEFTOK 2 | |
248 #define YYMAXUTOK 260 | |
249 | |
250 #define YYTRANSLATE(YYX) \ | |
251 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) | |
252 | |
253 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ | |
254 static const unsigned char yytranslate[] = | |
255 { | |
256 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
257 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
258 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
259 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
260 14, 15, 8, 7, 13, 6, 2, 9, 2, 2, | |
261 2, 2, 2, 2, 2, 2, 2, 2, 2, 12, | |
262 17, 5, 16, 2, 2, 2, 2, 2, 2, 2, | |
263 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
264 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
265 2, 2, 2, 2, 11, 2, 2, 2, 2, 2, | |
266 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
267 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
268 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
269 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
270 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
271 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
272 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
273 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
274 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
275 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
276 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
277 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
278 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
279 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
280 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
281 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, | |
282 10 | |
283 }; | |
284 | |
285 #if YYDEBUG | |
286 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in | |
287 YYRHS. */ | |
288 static const unsigned char yyprhs[] = | |
289 { | |
290 0, 0, 3, 4, 7, 8, 10, 13, 16, 18, | |
291 22, 24, 26, 30, 35, 39, 43, 47, 51, 55, | |
292 59, 62, 66 | |
293 }; | |
294 | |
295 /* YYRHS -- A `-1'-separated list of the rules' RHS. */ | |
296 static const yysigned_char yyrhs[] = | |
297 { | |
298 19, 0, -1, -1, 19, 20, -1, -1, 22, -1, | |
299 20, 12, -1, 1, 12, -1, 22, -1, 21, 13, | |
300 22, -1, 4, -1, 3, -1, 3, 5, 22, -1, | |
301 3, 14, 21, 15, -1, 22, 16, 22, -1, 22, | |
302 17, 22, -1, 22, 7, 22, -1, 22, 6, 22, | |
303 -1, 22, 8, 22, -1, 22, 9, 22, -1, 6, | |
304 22, -1, 22, 11, 22, -1, 14, 22, 15, -1 | |
305 }; | |
306 | |
307 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ | |
308 static const unsigned char yyrline[] = | |
309 { | |
310 0, 76, 76, 77, 81, 82, 84, 85, 90, 93, | |
311 98, 104, 110, 116, 123, 125, 128, 130, 132, 134, | |
312 136, 138, 140 | |
313 }; | |
314 #endif | |
315 | |
316 #if YYDEBUG || YYERROR_VERBOSE | |
317 /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. | |
318 First, the terminals, then, starting at YYNTOKENS, nonterminals. */ | |
319 static const char *const yytname[] = | |
320 { | |
321 "$end", "error", "$undefined", "NAME", "NUMBER", "'='", "'-'", "'+'", | |
322 "'*'", "'/'", "NEG", "'^'", "';'", "','", "'('", "')'", "'>'", "'<'", | |
323 "$accept", "input", "expression_list", "argument_list", "expression", 0 | |
324 }; | |
325 #endif | |
326 | |
327 # ifdef YYPRINT | |
328 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to | |
329 token YYLEX-NUM. */ | |
330 static const unsigned short int yytoknum[] = | |
331 { | |
332 0, 256, 257, 258, 259, 61, 45, 43, 42, 47, | |
333 260, 94, 59, 44, 40, 41, 62, 60 | |
334 }; | |
335 # endif | |
336 | |
337 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ | |
338 static const unsigned char yyr1[] = | |
339 { | |
340 0, 18, 19, 19, 20, 20, 20, 20, 21, 21, | |
341 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
342 22, 22, 22 | |
343 }; | |
344 | |
345 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ | |
346 static const unsigned char yyr2[] = | |
347 { | |
348 0, 2, 0, 2, 0, 1, 2, 2, 1, 3, | |
349 1, 1, 3, 4, 3, 3, 3, 3, 3, 3, | |
350 2, 3, 3 | |
351 }; | |
352 | |
353 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state | |
354 STATE-NUM when YYTABLE doesn't specify something else to do. Zero | |
355 means the default is an error. */ | |
356 static const unsigned char yydefact[] = | |
357 { | |
358 2, 0, 1, 0, 11, 10, 0, 0, 3, 5, | |
359 7, 0, 0, 20, 0, 6, 0, 0, 0, 0, | |
360 0, 0, 0, 12, 0, 8, 22, 17, 16, 18, | |
361 19, 21, 14, 15, 0, 13, 9 | |
362 }; | |
363 | |
364 /* YYDEFGOTO[NTERM-NUM]. */ | |
365 static const yysigned_char yydefgoto[] = | |
366 { | |
367 -1, 1, 8, 24, 9 | |
368 }; | |
369 | |
370 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing | |
371 STATE-NUM. */ | |
372 #define YYPACT_NINF -10 | |
373 static const yysigned_char yypact[] = | |
374 { | |
375 -10, 17, -10, -8, 22, -10, 47, 47, -3, 38, | |
376 -10, 47, 47, -9, 26, -10, 47, 47, 47, 47, | |
377 47, 47, 47, 38, 9, 38, -10, 48, 48, -9, | |
378 -9, -9, 38, 38, 47, -10, 38 | |
379 }; | |
380 | |
381 /* YYPGOTO[NTERM-NUM]. */ | |
382 static const yysigned_char yypgoto[] = | |
383 { | |
384 -10, -10, -10, -10, -6 | |
385 }; | |
386 | |
387 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If | |
388 positive, shift that token. If negative, reduce the rule which | |
389 number is the opposite. If zero, do what YYDEFACT says. | |
390 If YYTABLE_NINF, syntax error. */ | |
391 #define YYTABLE_NINF -5 | |
392 static const yysigned_char yytable[] = | |
393 { | |
394 13, 14, 20, 0, 10, 23, 25, 21, 22, 15, | |
395 27, 28, 29, 30, 31, 32, 33, 2, 3, 0, | |
396 4, 5, 34, 6, 35, 0, 0, 11, 36, -4, | |
397 0, 7, 16, 17, 18, 19, 12, 20, 0, 0, | |
398 0, 26, 21, 22, 16, 17, 18, 19, 0, 20, | |
399 4, 5, 0, 6, 21, 22, 18, 19, 0, 20, | |
400 0, 7, 0, 0, 21, 22 | |
401 }; | |
402 | |
403 static const yysigned_char yycheck[] = | |
404 { | |
405 6, 7, 11, -1, 12, 11, 12, 16, 17, 12, | |
406 16, 17, 18, 19, 20, 21, 22, 0, 1, -1, | |
407 3, 4, 13, 6, 15, -1, -1, 5, 34, 12, | |
408 -1, 14, 6, 7, 8, 9, 14, 11, -1, -1, | |
409 -1, 15, 16, 17, 6, 7, 8, 9, -1, 11, | |
410 3, 4, -1, 6, 16, 17, 8, 9, -1, 11, | |
411 -1, 14, -1, -1, 16, 17 | |
412 }; | |
413 | |
414 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing | |
415 symbol of state STATE-NUM. */ | |
416 static const unsigned char yystos[] = | |
417 { | |
418 0, 19, 0, 1, 3, 4, 6, 14, 20, 22, | |
419 12, 5, 14, 22, 22, 12, 6, 7, 8, 9, | |
420 11, 16, 17, 22, 21, 22, 15, 22, 22, 22, | |
421 22, 22, 22, 22, 13, 15, 22 | |
422 }; | |
423 | |
424 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) | |
425 # define YYSIZE_T __SIZE_TYPE__ | |
426 #endif | |
427 #if ! defined (YYSIZE_T) && defined (size_t) | |
428 # define YYSIZE_T size_t | |
429 #endif | |
430 #if ! defined (YYSIZE_T) | |
431 # if defined (__STDC__) || defined (__cplusplus) | |
432 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */ | |
433 # define YYSIZE_T size_t | |
434 # endif | |
435 #endif | |
436 #if ! defined (YYSIZE_T) | |
437 # define YYSIZE_T unsigned int | |
438 #endif | |
439 | |
440 #define yyerrok (yyerrstatus = 0) | |
441 #define yyclearin (yychar = YYEMPTY) | |
442 #define YYEMPTY (-2) | |
443 #define YYEOF 0 | |
444 | |
445 #define YYACCEPT goto yyacceptlab | |
446 #define YYABORT goto yyabortlab | |
447 #define YYERROR goto yyerrorlab | |
448 | |
449 | |
450 /* Like YYERROR except do call yyerror. This remains here temporarily | |
451 to ease the transition to the new meaning of YYERROR, for GCC. | |
452 Once GCC version 2 has supplanted version 1, this can go. */ | |
453 | |
454 #define YYFAIL goto yyerrlab | |
455 | |
456 #define YYRECOVERING() (!!yyerrstatus) | |
457 | |
458 #define YYBACKUP(Token, Value) \ | |
459 do \ | |
460 if (yychar == YYEMPTY && yylen == 1) \ | |
461 { \ | |
462 yychar = (Token); \ | |
463 yylval = (Value); \ | |
464 yytoken = YYTRANSLATE (yychar); \ | |
465 YYPOPSTACK; \ | |
466 goto yybackup; \ | |
467 } \ | |
468 else \ | |
469 { \ | |
470 yyerror ("syntax error: cannot back up");\ | |
471 YYERROR; \ | |
472 } \ | |
473 while (0) | |
474 | |
475 #define YYTERROR 1 | |
476 #define YYERRCODE 256 | |
477 | |
478 /* YYLLOC_DEFAULT -- Compute the default location (before the actions | |
479 are run). */ | |
480 | |
481 #ifndef YYLLOC_DEFAULT | |
482 # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
483 ((Current).first_line = (Rhs)[1].first_line, \ | |
484 (Current).first_column = (Rhs)[1].first_column, \ | |
485 (Current).last_line = (Rhs)[N].last_line, \ | |
486 (Current).last_column = (Rhs)[N].last_column) | |
487 #endif | |
488 | |
489 /* YYLEX -- calling `yylex' with the right arguments. */ | |
490 | |
491 #ifdef YYLEX_PARAM | |
492 # define YYLEX yylex (&yylval, YYLEX_PARAM) | |
493 #else | |
494 # define YYLEX yylex (&yylval) | |
495 #endif | |
496 | |
497 /* Enable debugging if requested. */ | |
498 #if YYDEBUG | |
499 | |
500 # ifndef YYFPRINTF | |
501 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */ | |
502 # define YYFPRINTF fprintf | |
503 # endif | |
504 | |
505 # define YYDPRINTF(Args) \ | |
506 do { \ | |
507 if (yydebug) \ | |
508 YYFPRINTF Args; \ | |
509 } while (0) | |
510 | |
511 # define YYDSYMPRINT(Args) \ | |
512 do { \ | |
513 if (yydebug) \ | |
514 yysymprint Args; \ | |
515 } while (0) | |
516 | |
517 # define YYDSYMPRINTF(Title, Token, Value, Location) \ | |
518 do { \ | |
519 if (yydebug) \ | |
520 { \ | |
521 YYFPRINTF (stderr, "%s ", Title); \ | |
522 yysymprint (stderr, \ | |
523 Token, Value); \ | |
524 YYFPRINTF (stderr, "\n"); \ | |
525 } \ | |
526 } while (0) | |
527 | |
528 /*------------------------------------------------------------------. | |
529 | yy_stack_print -- Print the state stack from its BOTTOM up to its | | |
530 | TOP (included). | | |
531 `------------------------------------------------------------------*/ | |
532 | |
533 #if defined (__STDC__) || defined (__cplusplus) | |
534 static void | |
535 yy_stack_print (short int *bottom, short int *top) | |
536 #else | |
537 static void | |
538 yy_stack_print (bottom, top) | |
539 short int *bottom; | |
540 short int *top; | |
541 #endif | |
542 { | |
543 YYFPRINTF (stderr, "Stack now"); | |
544 for (/* Nothing. */; bottom <= top; ++bottom) | |
545 YYFPRINTF (stderr, " %d", *bottom); | |
546 YYFPRINTF (stderr, "\n"); | |
547 } | |
548 | |
549 # define YY_STACK_PRINT(Bottom, Top) \ | |
550 do { \ | |
551 if (yydebug) \ | |
552 yy_stack_print ((Bottom), (Top)); \ | |
553 } while (0) | |
554 | |
555 | |
556 /*------------------------------------------------. | |
557 | Report that the YYRULE is going to be reduced. | | |
558 `------------------------------------------------*/ | |
559 | |
560 #if defined (__STDC__) || defined (__cplusplus) | |
561 static void | |
562 yy_reduce_print (int yyrule) | |
563 #else | |
564 static void | |
565 yy_reduce_print (yyrule) | |
566 int yyrule; | |
567 #endif | |
568 { | |
569 int yyi; | |
570 unsigned int yylno = yyrline[yyrule]; | |
571 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", | |
572 yyrule - 1, yylno); | |
573 /* Print the symbols being reduced, and their result. */ | |
574 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) | |
575 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); | |
576 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); | |
577 } | |
578 | |
579 # define YY_REDUCE_PRINT(Rule) \ | |
580 do { \ | |
581 if (yydebug) \ | |
582 yy_reduce_print (Rule); \ | |
583 } while (0) | |
584 | |
585 /* Nonzero means print parse trace. It is left uninitialized so that | |
586 multiple parsers can coexist. */ | |
587 int yydebug; | |
588 #else /* !YYDEBUG */ | |
589 # define YYDPRINTF(Args) | |
590 # define YYDSYMPRINT(Args) | |
591 # define YYDSYMPRINTF(Title, Token, Value, Location) | |
592 # define YY_STACK_PRINT(Bottom, Top) | |
593 # define YY_REDUCE_PRINT(Rule) | |
594 #endif /* !YYDEBUG */ | |
595 | |
596 | |
597 /* YYINITDEPTH -- initial size of the parser's stacks. */ | |
598 #ifndef YYINITDEPTH | |
599 # define YYINITDEPTH 200 | |
600 #endif | |
601 | |
602 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only | |
603 if the built-in stack extension method is used). | |
604 | |
605 Do not make this value too large; the results are undefined if | |
606 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) | |
607 evaluated with infinite-precision integer arithmetic. */ | |
608 | |
609 #if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 | |
610 # undef YYMAXDEPTH | |
611 #endif | |
612 | |
613 #ifndef YYMAXDEPTH | |
614 # define YYMAXDEPTH 10000 | |
615 #endif | |
616 | |
617 | |
618 | |
619 #if YYERROR_VERBOSE | |
620 | |
621 # ifndef yystrlen | |
622 # if defined (__GLIBC__) && defined (_STRING_H) | |
623 # define yystrlen strlen | |
624 # else | |
625 /* Return the length of YYSTR. */ | |
626 static YYSIZE_T | |
627 # if defined (__STDC__) || defined (__cplusplus) | |
628 yystrlen (const char *yystr) | |
629 # else | |
630 yystrlen (yystr) | |
631 const char *yystr; | |
632 # endif | |
633 { | |
634 register const char *yys = yystr; | |
635 | |
636 while (*yys++ != '\0') | |
637 continue; | |
638 | |
639 return yys - yystr - 1; | |
640 } | |
641 # endif | |
642 # endif | |
643 | |
644 # ifndef yystpcpy | |
645 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) | |
646 # define yystpcpy stpcpy | |
647 # else | |
648 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in | |
649 YYDEST. */ | |
650 static char * | |
651 # if defined (__STDC__) || defined (__cplusplus) | |
652 yystpcpy (char *yydest, const char *yysrc) | |
653 # else | |
654 yystpcpy (yydest, yysrc) | |
655 char *yydest; | |
656 const char *yysrc; | |
657 # endif | |
658 { | |
659 register char *yyd = yydest; | |
660 register const char *yys = yysrc; | |
661 | |
662 while ((*yyd++ = *yys++) != '\0') | |
663 continue; | |
664 | |
665 return yyd - 1; | |
666 } | |
667 # endif | |
668 # endif | |
669 | |
670 #endif /* !YYERROR_VERBOSE */ | |
671 | |
672 | |
673 | |
674 #if YYDEBUG | |
675 /*--------------------------------. | |
676 | Print this symbol on YYOUTPUT. | | |
677 `--------------------------------*/ | |
678 | |
679 #if defined (__STDC__) || defined (__cplusplus) | |
680 static void | |
681 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) | |
682 #else | |
683 static void | |
684 yysymprint (yyoutput, yytype, yyvaluep) | |
685 FILE *yyoutput; | |
686 int yytype; | |
687 YYSTYPE *yyvaluep; | |
688 #endif | |
689 { | |
690 /* Pacify ``unused variable'' warnings. */ | |
691 (void) yyvaluep; | |
692 | |
693 if (yytype < YYNTOKENS) | |
694 { | |
695 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); | |
696 # ifdef YYPRINT | |
697 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); | |
698 # endif | |
699 } | |
700 else | |
701 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); | |
702 | |
703 switch (yytype) | |
704 { | |
705 default: | |
706 break; | |
707 } | |
708 YYFPRINTF (yyoutput, ")"); | |
709 } | |
710 | |
711 #endif /* ! YYDEBUG */ | |
712 /*-----------------------------------------------. | |
713 | Release the memory associated to this symbol. | | |
714 `-----------------------------------------------*/ | |
715 | |
716 #if defined (__STDC__) || defined (__cplusplus) | |
717 static void | |
718 yydestruct (int yytype, YYSTYPE *yyvaluep) | |
719 #else | |
720 static void | |
721 yydestruct (yytype, yyvaluep) | |
722 int yytype; | |
723 YYSTYPE *yyvaluep; | |
724 #endif | |
725 { | |
726 /* Pacify ``unused variable'' warnings. */ | |
727 (void) yyvaluep; | |
728 | |
729 switch (yytype) | |
730 { | |
731 | |
732 default: | |
733 break; | |
734 } | |
735 } | |
736 | |
737 | |
738 /* Prevent warnings from -Wmissing-prototypes. */ | |
739 | |
740 #ifdef YYPARSE_PARAM | |
741 # if defined (__STDC__) || defined (__cplusplus) | |
742 int yyparse (void *YYPARSE_PARAM); | |
743 # else | |
744 int yyparse (); | |
745 # endif | |
746 #else /* ! YYPARSE_PARAM */ | |
747 #if defined (__STDC__) || defined (__cplusplus) | |
748 int yyparse (void); | |
749 #else | |
750 int yyparse (); | |
751 #endif | |
752 #endif /* ! YYPARSE_PARAM */ | |
753 | |
754 | |
755 | |
756 | |
757 | |
758 | |
759 /*----------. | |
760 | yyparse. | | |
761 `----------*/ | |
762 | |
763 #ifdef YYPARSE_PARAM | |
764 # if defined (__STDC__) || defined (__cplusplus) | |
765 int yyparse (void *YYPARSE_PARAM) | |
766 # else | |
767 int yyparse (YYPARSE_PARAM) | |
768 void *YYPARSE_PARAM; | |
769 # endif | |
770 #else /* ! YYPARSE_PARAM */ | |
771 #if defined (__STDC__) || defined (__cplusplus) | |
772 int | |
773 yyparse (void) | |
774 #else | |
775 int | |
776 yyparse () | |
777 | |
778 #endif | |
779 #endif | |
780 { | |
781 /* The lookahead symbol. */ | |
782 int yychar; | |
783 | |
784 /* The semantic value of the lookahead symbol. */ | |
785 YYSTYPE yylval; | |
786 | |
787 /* Number of syntax errors so far. */ | |
788 int yynerrs; | |
789 | |
790 register int yystate; | |
791 register int yyn; | |
792 int yyresult; | |
793 /* Number of tokens to shift before error messages enabled. */ | |
794 int yyerrstatus; | |
795 /* Lookahead token as an internal (translated) token number. */ | |
796 int yytoken = 0; | |
797 | |
798 /* Three stacks and their tools: | |
799 `yyss': related to states, | |
800 `yyvs': related to semantic values, | |
801 `yyls': related to locations. | |
802 | |
803 Refer to the stacks thru separate pointers, to allow yyoverflow | |
804 to reallocate them elsewhere. */ | |
805 | |
806 /* The state stack. */ | |
807 short int yyssa[YYINITDEPTH]; | |
808 short int *yyss = yyssa; | |
809 register short int *yyssp; | |
810 | |
811 /* The semantic value stack. */ | |
812 YYSTYPE yyvsa[YYINITDEPTH]; | |
813 YYSTYPE *yyvs = yyvsa; | |
814 register YYSTYPE *yyvsp; | |
815 | |
816 | |
817 | |
818 #define YYPOPSTACK (yyvsp--, yyssp--) | |
819 | |
820 YYSIZE_T yystacksize = YYINITDEPTH; | |
821 | |
822 /* The variables used to return semantic value and location from the | |
823 action routines. */ | |
824 YYSTYPE yyval; | |
825 | |
826 | |
827 /* When reducing, the number of symbols on the RHS of the reduced | |
828 rule. */ | |
829 int yylen; | |
830 | |
831 YYDPRINTF ((stderr, "Starting parse\n")); | |
832 | |
833 yystate = 0; | |
834 yyerrstatus = 0; | |
835 yynerrs = 0; | |
836 yychar = YYEMPTY; /* Cause a token to be read. */ | |
837 | |
838 /* Initialize stack pointers. | |
839 Waste one element of value and location stack | |
840 so that they stay on the same level as the state stack. | |
841 The wasted elements are never initialized. */ | |
842 | |
843 yyssp = yyss; | |
844 yyvsp = yyvs; | |
845 | |
846 | |
847 goto yysetstate; | |
848 | |
849 /*------------------------------------------------------------. | |
850 | yynewstate -- Push a new state, which is found in yystate. | | |
851 `------------------------------------------------------------*/ | |
852 yynewstate: | |
853 /* In all cases, when you get here, the value and location stacks | |
854 have just been pushed. so pushing a state here evens the stacks. | |
855 */ | |
856 yyssp++; | |
857 | |
858 yysetstate: | |
859 *yyssp = yystate; | |
860 | |
861 if (yyss + yystacksize - 1 <= yyssp) | |
862 { | |
863 /* Get the current used size of the three stacks, in elements. */ | |
864 YYSIZE_T yysize = yyssp - yyss + 1; | |
865 | |
866 #ifdef yyoverflow | |
867 { | |
868 /* Give user a chance to reallocate the stack. Use copies of | |
869 these so that the &'s don't force the real ones into | |
870 memory. */ | |
871 YYSTYPE *yyvs1 = yyvs; | |
872 short int *yyss1 = yyss; | |
873 | |
874 | |
875 /* Each stack pointer address is followed by the size of the | |
876 data in use in that stack, in bytes. This used to be a | |
877 conditional around just the two extra args, but that might | |
878 be undefined if yyoverflow is a macro. */ | |
879 yyoverflow ("parser stack overflow", | |
880 &yyss1, yysize * sizeof (*yyssp), | |
881 &yyvs1, yysize * sizeof (*yyvsp), | |
882 | |
883 &yystacksize); | |
884 | |
885 yyss = yyss1; | |
886 yyvs = yyvs1; | |
887 } | |
888 #else /* no yyoverflow */ | |
889 # ifndef YYSTACK_RELOCATE | |
890 goto yyoverflowlab; | |
891 # else | |
892 /* Extend the stack our own way. */ | |
893 if (YYMAXDEPTH <= yystacksize) | |
894 goto yyoverflowlab; | |
895 yystacksize *= 2; | |
896 if (YYMAXDEPTH < yystacksize) | |
897 yystacksize = YYMAXDEPTH; | |
898 | |
899 { | |
900 short int *yyss1 = yyss; | |
901 union yyalloc *yyptr = | |
902 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); | |
903 if (! yyptr) | |
904 goto yyoverflowlab; | |
905 YYSTACK_RELOCATE (yyss); | |
906 YYSTACK_RELOCATE (yyvs); | |
907 | |
908 # undef YYSTACK_RELOCATE | |
909 if (yyss1 != yyssa) | |
910 YYSTACK_FREE (yyss1); | |
911 } | |
912 # endif | |
913 #endif /* no yyoverflow */ | |
914 | |
915 yyssp = yyss + yysize - 1; | |
916 yyvsp = yyvs + yysize - 1; | |
917 | |
918 | |
919 YYDPRINTF ((stderr, "Stack size increased to %lu\n", | |
920 (unsigned long int) yystacksize)); | |
921 | |
922 if (yyss + yystacksize - 1 <= yyssp) | |
923 YYABORT; | |
924 } | |
925 | |
926 YYDPRINTF ((stderr, "Entering state %d\n", yystate)); | |
927 | |
928 goto yybackup; | |
929 | |
930 /*-----------. | |
931 | yybackup. | | |
932 `-----------*/ | |
933 yybackup: | |
934 | |
935 /* Do appropriate processing given the current state. */ | |
936 /* Read a lookahead token if we need one and don't already have one. */ | |
937 /* yyresume: */ | |
938 | |
939 /* First try to decide what to do without reference to lookahead token. */ | |
940 | |
941 yyn = yypact[yystate]; | |
942 if (yyn == YYPACT_NINF) | |
943 goto yydefault; | |
944 | |
945 /* Not known => get a lookahead token if don't already have one. */ | |
946 | |
947 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ | |
948 if (yychar == YYEMPTY) | |
949 { | |
950 YYDPRINTF ((stderr, "Reading a token: ")); | |
951 yychar = YYLEX; | |
952 } | |
953 | |
954 if (yychar <= YYEOF) | |
955 { | |
956 yychar = yytoken = YYEOF; | |
957 YYDPRINTF ((stderr, "Now at end of input.\n")); | |
958 } | |
959 else | |
960 { | |
961 yytoken = YYTRANSLATE (yychar); | |
962 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); | |
963 } | |
964 | |
965 /* If the proper action on seeing token YYTOKEN is to reduce or to | |
966 detect an error, take that action. */ | |
967 yyn += yytoken; | |
968 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) | |
969 goto yydefault; | |
970 yyn = yytable[yyn]; | |
971 if (yyn <= 0) | |
972 { | |
973 if (yyn == 0 || yyn == YYTABLE_NINF) | |
974 goto yyerrlab; | |
975 yyn = -yyn; | |
976 goto yyreduce; | |
977 } | |
978 | |
979 if (yyn == YYFINAL) | |
980 YYACCEPT; | |
981 | |
982 /* Shift the lookahead token. */ | |
983 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); | |
984 | |
985 /* Discard the token being shifted unless it is eof. */ | |
986 if (yychar != YYEOF) | |
987 yychar = YYEMPTY; | |
988 | |
989 *++yyvsp = yylval; | |
990 | |
991 | |
992 /* Count tokens shifted since error; after three, turn off error | |
993 status. */ | |
994 if (yyerrstatus) | |
995 yyerrstatus--; | |
996 | |
997 yystate = yyn; | |
998 goto yynewstate; | |
999 | |
1000 | |
1001 /*-----------------------------------------------------------. | |
1002 | yydefault -- do the default action for the current state. | | |
1003 `-----------------------------------------------------------*/ | |
1004 yydefault: | |
1005 yyn = yydefact[yystate]; | |
1006 if (yyn == 0) | |
1007 goto yyerrlab; | |
1008 goto yyreduce; | |
1009 | |
1010 | |
1011 /*-----------------------------. | |
1012 | yyreduce -- Do a reduction. | | |
1013 `-----------------------------*/ | |
1014 yyreduce: | |
1015 /* yyn is the number of a rule to reduce with. */ | |
1016 yylen = yyr2[yyn]; | |
1017 | |
1018 /* If YYLEN is nonzero, implement the default value of the action: | |
1019 `$$ = $1'. | |
1020 | |
1021 Otherwise, the following line sets YYVAL to garbage. | |
1022 This behavior is undocumented and Bison | |
1023 users should not rely upon it. Assigning to YYVAL | |
1024 unconditionally makes the parser a bit smaller, and it avoids a | |
1025 GCC warning that YYVAL may be used uninitialized. */ | |
1026 yyval = yyvsp[1-yylen]; | |
1027 | |
1028 | |
1029 YY_REDUCE_PRINT (yyn); | |
1030 switch (yyn) | |
1031 { | |
1032 case 5: | |
1033 #line 83 "parser.y" | |
1034 { ;} | |
1035 break; | |
1036 | |
1037 case 7: | |
1038 #line 86 "parser.y" | |
1039 { yyerrok; ;} | |
1040 break; | |
1041 | |
1042 case 8: | |
1043 #line 91 "parser.y" | |
1044 { | |
1045 ;} | |
1046 break; | |
1047 | |
1048 case 9: | |
1049 #line 94 "parser.y" | |
1050 { | |
1051 ;} | |
1052 break; | |
1053 | |
1054 case 10: | |
1055 #line 99 "parser.y" | |
1056 { | |
1057 char *buf = g_strdup_printf ("c%f:", yyvsp[0].d_value); | |
1058 GENERATE (buf); | |
1059 g_free (buf); | |
1060 ;} | |
1061 break; | |
1062 | |
1063 case 11: | |
1064 #line 105 "parser.y" | |
1065 { | |
1066 char *buf = g_strdup_printf ("l%s:", yyvsp[0].s_value); | |
1067 GENERATE (buf); | |
1068 g_free (buf); | |
1069 ;} | |
1070 break; | |
1071 | |
1072 case 12: | |
1073 #line 111 "parser.y" | |
1074 { | |
1075 char *buf = g_strdup_printf ("s%s:", yyvsp[-2].s_value); | |
1076 GENERATE (buf); | |
1077 g_free (buf); | |
1078 ;} | |
1079 break; | |
1080 | |
1081 case 13: | |
1082 #line 117 "parser.y" | |
1083 { | |
1084 char *buf = g_strdup_printf ("f%s:", yyvsp[-3].s_value); | |
1085 GENERATE (buf); | |
1086 g_free (buf); | |
1087 ;} | |
1088 break; | |
1089 | |
1090 case 14: | |
1091 #line 124 "parser.y" | |
1092 { GENERATE (">"); ;} | |
1093 break; | |
1094 | |
1095 case 15: | |
1096 #line 126 "parser.y" | |
1097 { GENERATE ("<"); ;} | |
1098 break; | |
1099 | |
1100 case 16: | |
1101 #line 129 "parser.y" | |
1102 { GENERATE ("+"); ;} | |
1103 break; | |
1104 | |
1105 case 17: | |
1106 #line 131 "parser.y" | |
1107 { GENERATE ("-"); ;} | |
1108 break; | |
1109 | |
1110 case 18: | |
1111 #line 133 "parser.y" | |
1112 { GENERATE ("*"); ;} | |
1113 break; | |
1114 | |
1115 case 19: | |
1116 #line 135 "parser.y" | |
1117 { GENERATE ("/"); ;} | |
1118 break; | |
1119 | |
1120 case 20: | |
1121 #line 137 "parser.y" | |
1122 { GENERATE ("n"); ;} | |
1123 break; | |
1124 | |
1125 case 21: | |
1126 #line 139 "parser.y" | |
1127 { GENERATE ("^"); ;} | |
1128 break; | |
1129 | |
1130 case 22: | |
1131 #line 141 "parser.y" | |
1132 { ;} | |
1133 break; | |
1134 | |
1135 | |
1136 } | |
1137 | |
1138 /* Line 1010 of yacc.c. */ | |
1139 #line 1140 "parser.c" | |
1140 | |
1141 yyvsp -= yylen; | |
1142 yyssp -= yylen; | |
1143 | |
1144 | |
1145 YY_STACK_PRINT (yyss, yyssp); | |
1146 | |
1147 *++yyvsp = yyval; | |
1148 | |
1149 | |
1150 /* Now `shift' the result of the reduction. Determine what state | |
1151 that goes to, based on the state we popped back to and the rule | |
1152 number reduced by. */ | |
1153 | |
1154 yyn = yyr1[yyn]; | |
1155 | |
1156 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; | |
1157 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) | |
1158 yystate = yytable[yystate]; | |
1159 else | |
1160 yystate = yydefgoto[yyn - YYNTOKENS]; | |
1161 | |
1162 goto yynewstate; | |
1163 | |
1164 | |
1165 /*------------------------------------. | |
1166 | yyerrlab -- here on detecting error | | |
1167 `------------------------------------*/ | |
1168 yyerrlab: | |
1169 /* If not already recovering from an error, report this error. */ | |
1170 if (!yyerrstatus) | |
1171 { | |
1172 ++yynerrs; | |
1173 #if YYERROR_VERBOSE | |
1174 yyn = yypact[yystate]; | |
1175 | |
1176 if (YYPACT_NINF < yyn && yyn < YYLAST) | |
1177 { | |
1178 YYSIZE_T yysize = 0; | |
1179 int yytype = YYTRANSLATE (yychar); | |
1180 const char* yyprefix; | |
1181 char *yymsg; | |
1182 int yyx; | |
1183 | |
1184 /* Start YYX at -YYN if negative to avoid negative indexes in | |
1185 YYCHECK. */ | |
1186 int yyxbegin = yyn < 0 ? -yyn : 0; | |
1187 | |
1188 /* Stay within bounds of both yycheck and yytname. */ | |
1189 int yychecklim = YYLAST - yyn; | |
1190 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; | |
1191 int yycount = 0; | |
1192 | |
1193 yyprefix = ", expecting "; | |
1194 for (yyx = yyxbegin; yyx < yyxend; ++yyx) | |
1195 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) | |
1196 { | |
1197 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); | |
1198 yycount += 1; | |
1199 if (yycount == 5) | |
1200 { | |
1201 yysize = 0; | |
1202 break; | |
1203 } | |
1204 } | |
1205 yysize += (sizeof ("syntax error, unexpected ") | |
1206 + yystrlen (yytname[yytype])); | |
1207 yymsg = (char *) YYSTACK_ALLOC (yysize); | |
1208 if (yymsg != 0) | |
1209 { | |
1210 char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); | |
1211 yyp = yystpcpy (yyp, yytname[yytype]); | |
1212 | |
1213 if (yycount < 5) | |
1214 { | |
1215 yyprefix = ", expecting "; | |
1216 for (yyx = yyxbegin; yyx < yyxend; ++yyx) | |
1217 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) | |
1218 { | |
1219 yyp = yystpcpy (yyp, yyprefix); | |
1220 yyp = yystpcpy (yyp, yytname[yyx]); | |
1221 yyprefix = " or "; | |
1222 } | |
1223 } | |
1224 yyerror (yymsg); | |
1225 YYSTACK_FREE (yymsg); | |
1226 } | |
1227 else | |
1228 yyerror ("syntax error; also virtual memory exhausted"); | |
1229 } | |
1230 else | |
1231 #endif /* YYERROR_VERBOSE */ | |
1232 yyerror ("syntax error"); | |
1233 } | |
1234 | |
1235 | |
1236 | |
1237 if (yyerrstatus == 3) | |
1238 { | |
1239 /* If just tried and failed to reuse lookahead token after an | |
1240 error, discard it. */ | |
1241 | |
1242 if (yychar <= YYEOF) | |
1243 { | |
1244 /* If at end of input, pop the error token, | |
1245 then the rest of the stack, then return failure. */ | |
1246 if (yychar == YYEOF) | |
1247 for (;;) | |
1248 { | |
1249 YYPOPSTACK; | |
1250 if (yyssp == yyss) | |
1251 YYABORT; | |
1252 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); | |
1253 yydestruct (yystos[*yyssp], yyvsp); | |
1254 } | |
1255 } | |
1256 else | |
1257 { | |
1258 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); | |
1259 yydestruct (yytoken, &yylval); | |
1260 yychar = YYEMPTY; | |
1261 | |
1262 } | |
1263 } | |
1264 | |
1265 /* Else will try to reuse lookahead token after shifting the error | |
1266 token. */ | |
1267 goto yyerrlab1; | |
1268 | |
1269 | |
1270 /*---------------------------------------------------. | |
1271 | yyerrorlab -- error raised explicitly by YYERROR. | | |
1272 `---------------------------------------------------*/ | |
1273 yyerrorlab: | |
1274 | |
1275 #ifdef __GNUC__ | |
1276 /* Pacify GCC when the user code never invokes YYERROR and the label | |
1277 yyerrorlab therefore never appears in user code. */ | |
1278 if (0) | |
1279 goto yyerrorlab; | |
1280 #endif | |
1281 | |
1282 yyvsp -= yylen; | |
1283 yyssp -= yylen; | |
1284 yystate = *yyssp; | |
1285 goto yyerrlab1; | |
1286 | |
1287 | |
1288 /*-------------------------------------------------------------. | |
1289 | yyerrlab1 -- common code for both syntax error and YYERROR. | | |
1290 `-------------------------------------------------------------*/ | |
1291 yyerrlab1: | |
1292 yyerrstatus = 3; /* Each real token shifted decrements this. */ | |
1293 | |
1294 for (;;) | |
1295 { | |
1296 yyn = yypact[yystate]; | |
1297 if (yyn != YYPACT_NINF) | |
1298 { | |
1299 yyn += YYTERROR; | |
1300 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) | |
1301 { | |
1302 yyn = yytable[yyn]; | |
1303 if (0 < yyn) | |
1304 break; | |
1305 } | |
1306 } | |
1307 | |
1308 /* Pop the current state because it cannot handle the error token. */ | |
1309 if (yyssp == yyss) | |
1310 YYABORT; | |
1311 | |
1312 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); | |
1313 yydestruct (yystos[yystate], yyvsp); | |
1314 YYPOPSTACK; | |
1315 yystate = *yyssp; | |
1316 YY_STACK_PRINT (yyss, yyssp); | |
1317 } | |
1318 | |
1319 if (yyn == YYFINAL) | |
1320 YYACCEPT; | |
1321 | |
1322 YYDPRINTF ((stderr, "Shifting error token, ")); | |
1323 | |
1324 *++yyvsp = yylval; | |
1325 | |
1326 | |
1327 yystate = yyn; | |
1328 goto yynewstate; | |
1329 | |
1330 | |
1331 /*-------------------------------------. | |
1332 | yyacceptlab -- YYACCEPT comes here. | | |
1333 `-------------------------------------*/ | |
1334 yyacceptlab: | |
1335 yyresult = 0; | |
1336 goto yyreturn; | |
1337 | |
1338 /*-----------------------------------. | |
1339 | yyabortlab -- YYABORT comes here. | | |
1340 `-----------------------------------*/ | |
1341 yyabortlab: | |
1342 yyresult = 1; | |
1343 goto yyreturn; | |
1344 | |
1345 #ifndef yyoverflow | |
1346 /*----------------------------------------------. | |
1347 | yyoverflowlab -- parser overflow comes here. | | |
1348 `----------------------------------------------*/ | |
1349 yyoverflowlab: | |
1350 yyerror ("parser stack overflow"); | |
1351 yyresult = 2; | |
1352 /* Fall through. */ | |
1353 #endif | |
1354 | |
1355 yyreturn: | |
1356 #ifndef yyoverflow | |
1357 if (yyss != yyssa) | |
1358 YYSTACK_FREE (yyss); | |
1359 #endif | |
1360 return yyresult; | |
1361 } | |
1362 | |
1363 | |
1364 #line 144 "parser.y" | |
1365 | |
1366 /* End of grammar */ | |
1367 | |
1368 /* Called by yyparse on error. */ | |
1369 int yyerror (char *s) { | |
1370 /* Ignore errors, just print a warning. */ | |
1371 g_warning ("%s\n", s); | |
1372 return 0; | |
1373 } | |
1374 | |
1375 int yylex (YYSTYPE *yylval, void *yyparam) { | |
1376 int c; | |
1377 parser_control *pc = (parser_control *) yyparam; | |
1378 | |
1379 /* Ignore whitespace, get first nonwhite character. */ | |
1380 while ((c = aud_vfs_getc (pc->input)) == ' ' || c == '\t' || c == '\n'); | |
1381 | |
1382 /* End of input ? */ | |
1383 if (c == EOF) | |
1384 return 0; | |
1385 | |
1386 /* Char starts a number => parse the number. */ | |
1387 if (isdigit (c)) { | |
1388 aud_vfs_fseek (pc->input, -1, SEEK_CUR); /* Put the char back. */ | |
1389 { | |
1390 char *old_locale, *saved_locale; | |
1391 | |
1392 old_locale = setlocale (LC_ALL, NULL); | |
1393 saved_locale = g_strdup (old_locale); | |
1394 setlocale (LC_ALL, "C"); | |
1395 sscanf (((VFSBuffer *)(pc->input->handle))->iter, "%lf", &yylval->d_value); | |
1396 | |
1397 while (isdigit(c) || c == '.') | |
1398 { | |
1399 c = aud_vfs_getc(pc->input); | |
1400 } | |
1401 | |
1402 aud_vfs_fseek(pc->input, -1, SEEK_CUR); | |
1403 | |
1404 setlocale (LC_ALL, saved_locale); | |
1405 g_free (saved_locale); | |
1406 } | |
1407 return NUMBER; | |
1408 } | |
1409 | |
1410 /* Char starts an identifier => read the name. */ | |
1411 if (isalpha (c)) { | |
1412 GString *sym_name; | |
1413 | |
1414 sym_name = g_string_new (NULL); | |
1415 | |
1416 do { | |
1417 sym_name = g_string_append_c (sym_name, c); | |
1418 | |
1419 /* Get another character. */ | |
1420 c = aud_vfs_getc (pc->input); | |
1421 } while (c != EOF && isalnum (c)); | |
1422 | |
1423 aud_vfs_fseek (pc->input, -1, SEEK_CUR); | |
1424 | |
1425 yylval->s_value = sym_name->str; | |
1426 | |
1427 g_string_free (sym_name, FALSE); | |
1428 | |
1429 return NAME; | |
1430 } | |
1431 | |
1432 /* Any other character is a token by itself. */ | |
1433 return c; | |
1434 } | |
1435 | |
1436 static int load_name (char *str, char **name) { | |
1437 int count = 0; | |
1438 GString *new = g_string_new (NULL); | |
1439 | |
1440 while (*str != 0 && *str != ':') { | |
1441 g_string_append_c (new, *str++); | |
1442 count++; | |
1443 } | |
1444 | |
1445 *name = new->str; | |
1446 g_string_free (new, FALSE); | |
1447 | |
1448 return count; | |
1449 } | |
1450 | |
1451 static gboolean expr_add_compile (expression_t *expr, symbol_dict_t *dict, | |
1452 char *str) { | |
1453 char op; | |
1454 double dval; | |
1455 int i; | |
1456 char *name; | |
1457 | |
1458 while ((op = *str++)) { | |
1459 switch (op) { | |
1460 case 'c': /* A constant. */ | |
1461 store_byte (expr, 'c'); | |
1462 sscanf (str, "%lf%n", &dval, &i); | |
1463 str += i; | |
1464 store_double (expr, dval); | |
1465 str++; /* Skip ';' */ | |
1466 break; | |
1467 | |
1468 case 'f': /* A function call. */ | |
1469 store_byte (expr, 'f'); | |
1470 str += load_name (str, &name); | |
1471 i = function_lookup (name); | |
1472 if (i < 0) return FALSE; /* Fail on error. */ | |
1473 store_int (expr, i); | |
1474 g_free (name); | |
1475 str++; /* Skip ';' */ | |
1476 break; | |
1477 | |
1478 case 'l': /* Load a variable. */ | |
1479 case 's': /* Store a variable. */ | |
1480 store_byte (expr, op); | |
1481 str += load_name (str, &name); | |
1482 i = dict_lookup (dict, name); | |
1483 store_int (expr, i); | |
1484 g_free (name); | |
1485 str++; /* Skip ';' */ | |
1486 break; | |
1487 | |
1488 default: /* Copy verbatim. */ | |
1489 store_byte (expr, op); | |
1490 break; | |
1491 } | |
1492 } | |
1493 | |
1494 return TRUE; | |
1495 } | |
1496 | |
1497 expression_t *expr_compile_string (const char* str, symbol_dict_t *dict) | |
1498 { | |
1499 parser_control pc; | |
1500 VFSFile *stream; | |
1501 | |
1502 g_return_val_if_fail(str != NULL && dict != NULL, NULL); | |
1503 | |
1504 stream = aud_vfs_buffer_new_from_string ( (char *) str ); | |
1505 | |
1506 pc.input = stream; | |
1507 pc.expr = expr_new (); | |
1508 pc.dict = dict; | |
1509 | |
1510 if (yyparse (&pc) != 0) { | |
1511 /* Check for error. */ | |
1512 expr_free (pc.expr); | |
1513 pc.expr = NULL; | |
1514 } | |
1515 | |
1516 aud_vfs_fclose (stream); | |
1517 | |
1518 return pc.expr; | |
1519 } | |
1520 | |
1521 |