Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/contrib/bug-I158.syn @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 | |
2 { | |
3 | |
4 /* | |
5 YABASIC --- a tiny integrated Basic Compiler/Interpreter | |
6 | |
7 BISON - part | |
8 | |
9 this Program is subject to the GNU General Public License; | |
10 see the file yabasic.c for details. | |
11 */ | |
12 | |
13 | |
14 #undef WINDOWS | |
15 #include "yabasic.h" /* definitions of yabasic */ | |
16 #include <malloc.h> | |
17 | |
18 #if HAVE_ALLOCA_H | |
19 #include <alloca.h> | |
20 #endif | |
21 | |
22 void __yy_bcopy(char *,char *,int); /* prototype missing */ | |
23 | |
24 int yylineno=1; | |
25 int yylex(void); | |
26 | |
27 } | |
28 | |
29 /* float number *//* integer number *//* token of command *//* number of newlines *//* quoted string *//* general symbol *//* string of digits *//* string symbol */ | |
30 (double ) step_part | |
31 | |
32 (double ) const | |
33 | |
34 (double ) number | |
35 | |
36 (int ) intnum | |
37 | |
38 (char *) symbol_or_lineno | |
39 | |
40 (int ) hashed_number | |
41 | |
42 (int ) SEP | |
43 | |
44 (int ) EOFILE | |
45 | |
46 | |
47 FNUM | |
48 -> simple real | |
49 -> simple real:x, 'e'+'E', '+'?,exponent:e =x*pow(10,e); | |
50 -> simple real:x, 'e'+'E', '-',exponent:e =x*pow(10,-e); | |
51 | |
52 simple real | |
53 -> integer part:i, '.', fraction part:f = i+f; | |
54 -> integer part, '.'? | |
55 -> '.', fraction part:f = f; | |
56 | |
57 integer part | |
58 -> digit:d = d-'0'; | |
59 -> integer part:x, digit:d = 10*x + d-'0'; | |
60 | |
61 fraction part | |
62 -> digit:d =(d-'0')/10.; | |
63 -> digit:d, fraction part:f =(d-'0' + f)/10.; | |
64 | |
65 (int) exponent | |
66 -> digit:d = d-'0'; | |
67 -> exponent:x, digit:d = 10*x + d-'0'; | |
68 | |
69 (int) name //value of name token is length of name string | |
70 -> letter: c =pushChar(c), 1; | |
71 -> name:k, letter+digit: c =pushChar(c), k+1; | |
72 | |
73 | |
74 (char *) SYMBOL | |
75 -> name:k =strdup(popString(k)); | |
76 | |
77 (char *) STRSYM | |
78 -> name:k, '$' =pushChar('$'), strdup(popString(k+1)); | |
79 | |
80 (char *) DIGITS | |
81 -> digit string:k =strdup(popString(k)); | |
82 | |
83 (int) digit string | |
84 -> digit:d =pushChar(d), 1; | |
85 -> digit string:k, digit:d =pushChar(d), k+1; | |
86 | |
87 (char *) STRING | |
88 -> '"', string text:k, '"' =strdup(popString(k)); | |
89 -> '"', string text:k, '\n' =strdup(popString(k)); | |
90 | |
91 GOSUB, LABEL, ON | |
92 | |
93 INTERRUPT, BREAK, CONTINUE, SEP, EOFILE | |
94 | |
95 IF, THEN, ELSE, ENDIF | |
96 | |
97 PRINT, INPUT, LINE, RETURN, DIM, END, AT, SCREEN, REVERSE | |
98 | |
99 AND, OR, NOT | |
100 | |
101 NE, LE, GE, LT, GT, EQ | |
102 | |
103 READ, DATA, RESTORE | |
104 | |
105 OPEN, CLOSE | |
106 | |
107 WINDOW, DOT, LINE, CIRCLE, TEXT, CLEAR, PRINTER | |
108 | |
109 WAIT, BELL, MAP, XMAP, YMAP, ARROW, XTICK, YTICK | |
110 | |
111 | |
112 SIN, ASIN, COS, ACOS, TAN, ATAN, EXP, LOG, SQRT, MYEOF | |
113 | |
114 INT, FRAC, MOD, RAN, LEN, VAL, LEFT, RIGHT, MID, LEN, MIN, MAX | |
115 | |
116 STR, INKEY, CHR, ASC, UPPER, LOWER, TRIM, LTRIM, RTRIM, INSTR | |
117 | |
118 SYSTEM, SYSTEM2, PEEK, PEEK2, POKE, DATE, TIME | |
119 | |
120 | |
121 | |
122 [ | |
123 left {OR} | |
124 left {AND} | |
125 left {NOT} | |
126 left {'-', '+'} | |
127 left {'*', '/'} | |
128 left {'^'} | |
129 nonassoc {UMINUS} | |
130 ] | |
131 | |
132 letter = 'a-z' + 'A-Z' | |
133 digit = '0-9' | |
134 eof = 0 + -1 | |
135 | |
136 NAME | |
137 -> letter | |
138 -> NAME, letter+digit | |
139 | |
140 | |
141 program $ | |
142 -> statement list, eof | |
143 | |
144 statement list | |
145 -> | |
146 -> statement_list, !{ | |
147 if (errorlevel<=ERROR) {YYABORT;}}, | |
148 SEP, !{ | |
149 yylineno+=$3;}, | |
150 statement | |
151 | |
152 statement /* empty */ | |
153 -> | |
154 -> string_assignment | |
155 -> assignment | |
156 -> for_loop | |
157 -> if_clause | |
158 -> "GOTO", symbol_or_lineno ={create_goto($2);} | |
159 -> "GOSUB", symbol_or_lineno ={create_gosub($2);} | |
160 -> ON, INTERRUPT, BREAK ={create_exception(TRUE);} | |
161 -> ON, INTERRUPT, CONTINUE ={create_exception(FALSE);} | |
162 -> ON, expression, "GOTO", !{create_skipper();}, goto_list ={create_nop();} | |
163 -> ON, expression, "GOSUB", !{create_skipper();}, gosub_list ={create_nop();} | |
164 -> LABEL, symbol_or_lineno ={create_label($2);} | |
165 -> OPEN, hashed_number, ',', string_expression, ',', string_expression ={create_myopen($2,'+');} | |
166 -> OPEN, hashed_number, ',', string_expression ={create_myopen($2,'-');} | |
167 -> CLOSE, hashed_number ={create_myclose($2);} | |
168 -> PRINT, printintro, printlist, !{ | |
169 create_revert(FALSE);}, | |
170 semicolon | |
171 -> INPUT, inputintro, inputlist ={lastinput->args=0;} | |
172 -> READ, readlist | |
173 -> DATA, datalist | |
174 -> RESTORE ={create_restore("");} | |
175 -> RESTORE, symbol_or_lineno ={create_restore($2);} | |
176 -> RETURN ={create_return();} | |
177 -> DIM, dimlist | |
178 -> OPEN, WINDOW, expression, ',', expression ={create_openwin(FALSE);} | |
179 -> OPEN, WINDOW, expression, ',', expression, ',', string_expression ={create_openwin(TRUE);} | |
180 -> DOT, mapping ={create_dot();} | |
181 -> LINE, mapping, "TO", mapping ={create_line('l');} | |
182 -> CIRCLE, mapping, ',', expression ={create_circle()} | |
183 -> TEXT, string_expression, ',', mapping ={create_text(TRUE);} | |
184 -> TEXT, mapping, ',', string_expression ={create_text(FALSE);} | |
185 -> MAP, expression, ',', expression, ',', expression, ',', expression, "TO", expression, ',', expression, ',', expression, ',', expression ={create_makemap();} | |
186 -> ARROW, mapping, "TO", mapping ={create_line('a');} | |
187 -> XTICK, mapping, ',', string_expression ={create_tick(1);} | |
188 -> YTICK, mapping, ',', string_expression ={create_tick(3);} | |
189 -> XTICK, mapping ={create_tick(0);} | |
190 -> YTICK, mapping ={create_tick(2);} | |
191 -> CLOSE, WINDOW ={create_closewin();} | |
192 -> CLEAR, WINDOW ={create_clearwin();} | |
193 -> CLEAR, SCREEN ={create_clearscreen();} | |
194 -> OPEN, PRINTER ={create_openprinter(0);} | |
195 -> OPEN, PRINTER, string_expression ={create_openprinter(1);} | |
196 -> CLOSE, PRINTER ={create_closeprinter();} | |
197 -> WAIT, expression ={create_mywait();} | |
198 -> BELL ={create_bell();} | |
199 -> INKEY ={create_function(MYINKEY); create_popstrsym(NULL);} | |
200 -> SYSTEM2, '(', string_expression, ')' ={create_function(MYSYSTEM2); | |
201 create_popdblsym(NULL);} | |
202 -> POKE, string_expression, ',', string_expression ={create_poke('s');} | |
203 -> POKE, string_expression, ',', expression ={create_poke('d');} | |
204 -> END ={create_myend();} | |
205 | |
206 string_assignment | |
207 -> STRSYM, EQ, string_expression ={create_popstrsym($1);} | |
208 -> MID, '(', STRSYM, !{ | |
209 create_pushstrptr($3);}, | |
210 ',', expression, ',', expression, ')', EQ, string_expression ={create_changestring(MYMID);} | |
211 -> LEFT, '(', STRSYM, !{ | |
212 create_pushstrptr($3);}, | |
213 ',', expression, ')', EQ, string_expression ={create_changestring(MYLEFT);} | |
214 -> RIGHT, '(', STRSYM, !{ | |
215 create_pushstrptr($3);}, | |
216 ',', expression, ')', EQ, string_expression ={create_changestring(MYRIGHT);} | |
217 -> STRSYM, '(', !{ | |
218 pushcounter();}, | |
219 indexlist, ')', EQ, string_expression ={create_doarray($1,ASSIGNSTRINGARRAY);} | |
220 -> MID, '(', STRSYM, '(', !{ | |
221 pushcounter();}, | |
222 indexlist, ')', !{ | |
223 create_doarray($3,GETSTRINGPOINTER);}, | |
224 ',', expression, ',', expression, ')', EQ, string_expression ={create_changestring(MYMID);} | |
225 -> LEFT, '(', STRSYM, '(', !{ | |
226 pushcounter();}, | |
227 indexlist, ')', !{ | |
228 create_doarray($3,GETSTRINGPOINTER);}, | |
229 ',', expression, ')', EQ, string_expression ={create_changestring(MYLEFT);} | |
230 -> RIGHT, '(', STRSYM, '(', !{ | |
231 pushcounter();}, | |
232 indexlist, ')', !{ | |
233 create_doarray($3,GETSTRINGPOINTER);}, | |
234 ',', expression, ')', EQ, string_expression ={create_changestring(MYRIGHT);} | |
235 | |
236 string_expression | |
237 -> STRSYM ={create_pushstrsym($1);} | |
238 -> string_function | |
239 -> STRING ={if ($1==NULL) {error(ERROR,"String not terminated");create_pushstr("");} else {create_pushstr($1);}} | |
240 -> string_expression, '+', string_expression ={create_concat();} | |
241 -> STRSYM, '(', !{ | |
242 pushcounter();}, | |
243 indexlist, ')' ={create_doarray($1,CALLSTRINGARRAY);} | |
244 -> '(', string_expression, ')' | |
245 | |
246 string_function | |
247 -> LEFT, '(', string_expression, ',', expression, ')' ={create_function(MYLEFT);} | |
248 -> RIGHT, '(', string_expression, ',', expression, ')' ={create_function(MYRIGHT);} | |
249 -> MID, '(', string_expression, ',', expression, ',', expression, ')' ={create_function(MYMID);} | |
250 -> STR, '(', expression, ')' ={create_function(MYSTR);} | |
251 -> STR, '(', expression, ',', string_expression, ')' ={create_function(MYSTR2);} | |
252 -> INKEY ={create_function(MYINKEY);} | |
253 -> CHR, '(', expression, ')' ={create_function(MYCHR);} | |
254 -> UPPER, '(', string_expression, ')' ={create_function(MYUPPER);} | |
255 -> LOWER, '(', string_expression, ')' ={create_function(MYLOWER);} | |
256 -> LTRIM, '(', string_expression, ')' ={create_function(MYLTRIM);} | |
257 -> RTRIM, '(', string_expression, ')' ={create_function(MYRTRIM);} | |
258 -> TRIM, '(', string_expression, ')' ={create_function(MYTRIM);} | |
259 -> SYSTEM, '(', string_expression, ')' ={create_function(MYSYSTEM);} | |
260 -> DATE ={create_function(MYDATE);} | |
261 -> TIME ={create_function(MYTIME);} | |
262 -> PEEK2, '(', string_expression, ')' ={create_function(MYPEEK2);} | |
263 | |
264 assignment | |
265 -> SYMBOL, EQ, expression ={create_popdblsym($1);} | |
266 -> SYMBOL, '(', !{ | |
267 pushcounter();}, | |
268 indexlist, ')', EQ, expression ={create_doarray($1,ASSIGNARRAY);} | |
269 | |
270 expression | |
271 -> number ={create_pushdbl($1);} | |
272 -> function | |
273 -> SYMBOL ={create_pushdblsym($1);} | |
274 -> SYMBOL, '(', !{ | |
275 pushcounter();}, | |
276 indexlist, ')' ={create_doarray($1,CALLARRAY);} | |
277 -> '(', expression, ')' | |
278 -> expression, '+', expression ={create_dblbin('+');} | |
279 -> expression, '-', expression ={create_dblbin('-');} | |
280 -> expression, '*', expression ={create_dblbin('*');} | |
281 -> expression, '/', expression ={create_dblbin('/');} | |
282 -> expression, '^', expression ={create_dblbin('^');} | |
283 -> '-', expression /* 1ef4:fa2arec <֠ */ ={create_negate();} | |
284 | |
285 mapping | |
286 -> expression, ',', expression | |
287 -> MAP, '(', expression, ',', expression, ')' ={create_map();} | |
288 | |
289 function | |
290 -> SIN, '(', expression, ')' ={create_function(MYSIN);} | |
291 -> ASIN, '(', expression, ')' ={create_function(MYASIN);} | |
292 -> COS, '(', expression, ')' ={create_function(MYCOS);} | |
293 -> ACOS, '(', expression, ')' ={create_function(MYACOS);} | |
294 -> TAN, '(', expression, ')' ={create_function(MYTAN);} | |
295 -> ATAN, '(', expression, ')' ={create_function(MYATAN);} | |
296 -> ATAN, '(', expression, ',', expression, ')' ={create_function(MYATAN2);} | |
297 -> EXP, '(', expression, ')' ={create_function(MYEXP);} | |
298 -> LOG, '(', expression, ')' ={create_function(MYLOG);} | |
299 -> SQRT, '(', expression, ')' ={create_function(MYSQRT);} | |
300 -> INT, '(', expression, ')' ={create_function(MYINT);} | |
301 -> FRAC, '(', expression, ')' ={create_function(MYFRAC);} | |
302 -> MOD, '(', expression, ',', expression, ')' ={create_function(MYMOD);} | |
303 -> RAN, '(', expression, ')' ={create_function(MYRAN);} | |
304 -> RAN, '(', ')' ={create_function(MYRAN2);} | |
305 -> MIN, '(', expression, ',', expression, ')' ={create_function(MYMIN);} | |
306 -> MAX, '(', expression, ',', expression, ')' ={create_function(MYMAX);} | |
307 -> XMAP, '(', expression, ')' ={create_function(MYXMAP);} | |
308 -> YMAP, '(', expression, ')' ={create_function(MYYMAP);} | |
309 -> LEN, '(', string_expression, ')' ={create_function(MYLEN);} | |
310 -> VAL, '(', string_expression, ')' ={create_function(MYVAL);} | |
311 -> ASC, '(', string_expression, ')' ={create_function(MYASC);} | |
312 -> INSTR, '(', string_expression, ',', string_expression, ')' ={create_function(MYINSTR);} | |
313 -> SYSTEM2, '(', string_expression, ')' ={create_function(MYSYSTEM2);} | |
314 -> PEEK, '(', string_expression, ')' ={create_function(MYPEEK);} | |
315 | |
316 const | |
317 -> number ={$$=$1;} | |
318 -> '+', number ={$$=$2;} | |
319 -> '-', number ={$$=-$2;} | |
320 | |
321 number | |
322 -> FNUM ={$$=$1;} | |
323 -> DIGITS ={$$=atoi($1);} | |
324 | |
325 intnum | |
326 -> DIGITS ={$$=atoi($1);} | |
327 | |
328 symbol_or_lineno | |
329 -> DIGITS ={$$=$1;} | |
330 -> SYMBOL ={$$=$1;} | |
331 | |
332 dimlist | |
333 -> SYMBOL, '(', !{ | |
334 pushcounter();}, | |
335 indexlist, ')' ={create_dim($1,'d');} | |
336 -> dimlist, ',', SYMBOL, '(', !{ | |
337 pushcounter();}, | |
338 indexlist, ')' ={create_dim($3,'d');} | |
339 -> STRSYM, '(', !{ | |
340 pushcounter();}, | |
341 indexlist, ')' ={create_dim($1,'s');} | |
342 -> dimlist, ',', STRSYM, '(', !{ | |
343 pushcounter();}, | |
344 indexlist, ')' ={create_dim($3,'s');} | |
345 | |
346 indexlist | |
347 -> expression ={inccounter();} | |
348 -> indexlist, ',', expression ={inccounter();} | |
349 | |
350 for_loop | |
351 -> "FOR", SYMBOL, EQ, expression, !{ | |
352 pushname($2);create_popdblsym($2);pushgoto(); | |
353 create_pushdblsym($2);}, | |
354 "TO", expression, step_part, !{ | |
355 | |
356 create_dblrelop(($8>0)?'{':'}'); | |
357 create_decide(); | |
358 pushlabel();}, | |
359 SEP, !{ | |
360 yylineno+=$10;}, | |
361 statement_list, !{ | |
362 | |
363 create_pushdbl($8); | |
364 create_pushdblsym($2); | |
365 create_dblbin('+'); | |
366 create_popdblsym($2); | |
367 swap();popgoto();poplabel();}, | |
368 next_or_eofile, next_symbol | |
369 | |
370 next_or_eofile | |
371 -> "NEXT" | |
372 -> EOFILE ={end_of_file=TRUE; | |
373 error(ERROR,"'next'-statement is missing"); YYABORT;} | |
374 step_part | |
375 -> /* can be omitted */ ={$$=1.0;} | |
376 -> "STEP", const ={$$=$2;} | |
377 | |
378 next_symbol | |
379 -> /* can be omitted */ ={pop();} | |
380 -> SYMBOL ={if (strcmp(pop()->pointer,$1)) | |
381 {error(ERROR,"'for' and 'next' do not match"); YYABORT;} | |
382 } | |
383 | |
384 if_clause | |
385 -> IF, condition, !{ | |
386 create_decide();pushlabel();}, | |
387 THEN, statement_list, !{ | |
388 pushlabel();swap();poplabel();}, | |
389 else_part, !{ | |
390 poplabel();}, | |
391 endif_or_eof | |
392 | |
393 endif_or_eof | |
394 -> ENDIF | |
395 -> EOFILE ={end_of_file=TRUE; | |
396 error(ERROR,"'endif'-statement is missing"); YYABORT;} | |
397 | |
398 condition | |
399 -> '(', condition, ')' | |
400 -> condition, OR, condition ={create_boole('|');} | |
401 -> condition, AND, condition ={create_boole('&');} | |
402 -> NOT, condition ={create_boole('!');} | |
403 -> string_expression, EQ, string_expression ={create_strrelop('=');} | |
404 -> string_expression, NE, string_expression ={create_strrelop('!');} | |
405 -> string_expression, LT, string_expression ={create_strrelop('<');} | |
406 -> string_expression, LE, string_expression ={create_strrelop('{');} | |
407 -> string_expression, GT, string_expression ={create_strrelop('>');} | |
408 -> string_expression, GE, string_expression ={create_strrelop('}');} | |
409 -> expression, EQ, expression ={create_dblrelop('=');} | |
410 -> expression, NE, expression ={create_dblrelop('!');} | |
411 -> expression, LT, expression ={create_dblrelop('<');} | |
412 -> expression, LE, expression ={create_dblrelop('{');} | |
413 -> expression, GT, expression ={create_dblrelop('>');} | |
414 -> expression, GE, expression ={create_dblrelop('}');} | |
415 -> MYEOF, '(', hashed_number, ')' ={create_testeof($3);} | |
416 | |
417 else_part /* can be omitted */ | |
418 -> | |
419 -> ELSE, statement_list | |
420 | |
421 inputlist | |
422 -> input | |
423 -> input, ',', inputlist | |
424 | |
425 input | |
426 -> SYMBOL ={create_myread('d');create_popdblsym($1);} | |
427 -> SYMBOL, '(', !{ | |
428 pushcounter();}, | |
429 indexlist, ')' ={create_myread('d');create_doarray($1,ASSIGNARRAY);} | |
430 -> STRSYM ={create_myread('s');create_popstrsym($1);} | |
431 -> STRSYM, '(', !{ | |
432 pushcounter();}, | |
433 indexlist, ')' ={create_myread('s');create_doarray($1,ASSIGNSTRINGARRAY);} | |
434 | |
435 readlist | |
436 -> readitem | |
437 -> readlist, ',', readitem | |
438 | |
439 readitem | |
440 -> SYMBOL ={create_readdata('d');create_popdblsym($1);} | |
441 -> SYMBOL, '(', !{ | |
442 pushcounter();}, | |
443 indexlist, ')' ={create_readdata('d');create_doarray($1,ASSIGNARRAY);} | |
444 -> STRSYM ={create_readdata('s');create_popstrsym($1);} | |
445 -> STRSYM, '(', !{ | |
446 pushcounter();}, | |
447 indexlist, ')' ={create_readdata('s');create_doarray($1,ASSIGNSTRINGARRAY);} | |
448 | |
449 datalist | |
450 -> STRING ={create_strdata($1);} | |
451 -> const ={create_dbldata($1);} | |
452 -> datalist, ',', STRING ={create_strdata($3);} | |
453 -> datalist, ',', const ={create_dbldata($3);} | |
454 | |
455 printlist /* possible empty */ | |
456 -> | |
457 -> expression ={create_print('d');} | |
458 -> printlist, ',', expression ={create_print('d');} | |
459 -> string_expression ={create_print('s');} | |
460 -> printlist, ',', string_expression ={create_print('s');} | |
461 | |
462 inputintro | |
463 -> ={create_myswitch(0);create_readline(NULL);} | |
464 -> stream | |
465 -> position ={create_myswitch(0);create_readline(NULL);} | |
466 -> !{ | |
467 create_myswitch(0);}, | |
468 prompt | |
469 -> position, !{ | |
470 create_myswitch(0);}, | |
471 prompt | |
472 | |
473 printintro | |
474 -> /* can be empty */ ={create_myswitch(0);} | |
475 -> stream | |
476 -> REVERSE ={create_revert(TRUE);create_myswitch(0);} | |
477 -> position ={create_myswitch(0);} | |
478 -> REVERSE, position ={create_revert(TRUE);create_myswitch(0);} | |
479 | |
480 prompt | |
481 -> STRING ={create_readline($1);} | |
482 | |
483 position | |
484 -> AT, '(', expression, ',', expression, ')' ={create_mymove();} | |
485 | |
486 stream | |
487 -> '#', intnum ={create_myswitch($2);} | |
488 | |
489 hashed_number | |
490 -> '#', intnum ={$$=$2;} | |
491 -> intnum /* need not contain hash */ ={$$=$1;} | |
492 | |
493 semicolon /* can be left out */ | |
494 -> ={create_print('n');} | |
495 -> ';' | |
496 | |
497 goto_list | |
498 -> symbol_or_lineno ={create_goto($1);create_findnop();} | |
499 -> goto_list, ',', symbol_or_lineno ={create_goto($3);create_findnop();} | |
500 | |
501 gosub_list | |
502 -> symbol_or_lineno ={create_gosub($1);create_findnop();} | |
503 -> gosub_list, ',', symbol_or_lineno ={create_gosub($3);create_findnop();} |