push up calltip_ignore_arg.patch
[nedit-bw.git] / parseEnhance2.diff
blob2f3742a25ef09c8ea8d732f1c72c56ae12b4b6a0
1 diff -u nedit_mod/source/parse.y nedit_mod_/source/parse.y
2 --- nedit_mod/source/parse.y 2005-08-16 14:33:52.000000000 -0400
3 +++ nedit_mod_/source/parse.y 2005-08-15 10:41:07.000000000 -0400
4 @@ -62,13 +62,17 @@
5 Symbol *sym;
6 Inst *inst;
7 int nArgs;
8 + enum operations oper;
10 %token <sym> NUMBER STRING SYMBOL FIELD
11 %token DELETE ARG_LOOKUP
12 -%token IF WHILE ELSE FOR BREAK CONTINUE RETURN
13 -%type <nArgs> arglist catlist
14 -%type <inst> cond comastmts for while else and or arrayexpr
15 +%token IF WHILE DO ELSE FOR BREAK CONTINUE RETURN
16 +%type <nArgs> arglistopt arglist catlist
17 +%type <inst> cond comastmts comastmtlst for while do else and or arrayexpr mark
18 %type <sym> evalsym
19 +%type <oper> operassign incrdecr
20 +%token <oper> '=' ADDEQ SUBEQ MULEQ DIVEQ MODEQ ANDEQ OREQ
21 +%token <oper> INCR DECR
23 %nonassoc IF_NO_ELSE
24 %nonassoc ELSE
25 @@ -116,32 +120,38 @@
27 stmtend: '\n' | ';'
29 +mark: /* nothing */ { $$ = GetPC(); } /* record instruction address */
30 + ;
31 stmt: ';' blank
32 | simpstmt stmtend blank
33 - | IF '(' cond ')' blank block %prec IF_NO_ELSE {
34 - SET_BR_OFF($3, GetPC());
35 + | IF blank '(' cond ')' blank block %prec IF_NO_ELSE {
36 + SET_BR_OFF($4, GetPC());
38 - | IF '(' cond ')' blank block else blank block %prec ELSE {
39 - SET_BR_OFF($3, ($7+1)); SET_BR_OFF($7, GetPC());
40 + | IF blank '(' cond ')' blank block else block %prec ELSE {
41 + SET_BR_OFF($4, ($8+1)); SET_BR_OFF($8, GetPC());
43 | while '(' cond ')' blank block {
44 ADD_OP(OP_BRANCH); ADD_BR_OFF($1);
45 SET_BR_OFF($3, GetPC()); FillLoopAddrs(GetPC(), $1);
47 + | do block WHILE blank '(' mark cond ')' stmtend blank {
48 + ADD_OP(OP_BRANCH); ADD_BR_OFF($1);
49 + SET_BR_OFF($7, GetPC()); FillLoopAddrs(GetPC(), $6);
50 + }
51 | for '(' comastmts ';' cond ';' comastmts ')' blank block {
52 FillLoopAddrs(GetPC()+2+($7-($5+1)), GetPC());
53 SwapCode($5+1, $7, GetPC());
54 ADD_OP(OP_BRANCH); ADD_BR_OFF($3); SET_BR_OFF($5, GetPC());
56 - | for '(' SYMBOL IN arrayexpr ')' {
57 + | for '(' blank SYMBOL IN blank arrayexpr blank ')' {
58 Symbol *iterSym = InstallIteratorSymbol();
59 ADD_OP(OP_BEGIN_ARRAY_ITER); ADD_SYM(iterSym);
60 - ADD_OP(OP_ARRAY_ITER); ADD_SYM($3); ADD_SYM(iterSym); ADD_BR_OFF(0);
61 + ADD_OP(OP_ARRAY_ITER); ADD_SYM($4); ADD_SYM(iterSym); ADD_BR_OFF(0);
63 blank block {
64 - ADD_OP(OP_BRANCH); ADD_BR_OFF($5+2);
65 - SET_BR_OFF($5+5, GetPC());
66 - FillLoopAddrs(GetPC(), $5+2);
67 + ADD_OP(OP_BRANCH); ADD_BR_OFF($7+2);
68 + SET_BR_OFF($7+5, GetPC());
69 + FillLoopAddrs(GetPC(), $7+2);
71 | BREAK stmtend blank {
72 ADD_OP(OP_BRANCH); ADD_BR_OFF(0);
73 @@ -162,229 +172,130 @@
74 ADD_OP(OP_RETURN_NO_VAL);
77 -simpstmt: SYMBOL '=' expr {
79 +operassign: ADDEQ { $$ = OP_ADD; }
80 + | SUBEQ { $$ = OP_SUB; }
81 + | MULEQ { $$ = OP_MUL; }
82 + | DIVEQ { $$ = OP_DIV; }
83 + | MODEQ { $$ = OP_MOD; }
84 + | ANDEQ { $$ = OP_BIT_AND; }
85 + | OREQ { $$ = OP_BIT_OR; }
86 + ;
87 +incrdecr: INCR { $$ = OP_INCR; }
88 + | DECR { $$ = OP_DECR; }
89 + ;
91 +simpstmt: /* simple variable assignment, op-assignment, incr/decrement */
92 + SYMBOL '=' blank expr {
93 ADD_OP(OP_ASSIGN); ADD_SYM($1);
95 - | evalsym ADDEQ expr {
96 - ADD_OP(OP_ADD); ADD_OP(OP_ASSIGN); ADD_SYM($1);
97 + | evalsym operassign blank expr {
98 + ADD_OP($2); ADD_OP(OP_ASSIGN); ADD_SYM($1);
100 - | evalsym SUBEQ expr {
101 - ADD_OP(OP_SUB); ADD_OP(OP_ASSIGN); ADD_SYM($1);
102 + | incrdecr blank SYMBOL {
103 + ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1);
104 + ADD_OP(OP_ASSIGN); ADD_SYM($3);
106 - | evalsym MULEQ expr {
107 - ADD_OP(OP_MUL); ADD_OP(OP_ASSIGN); ADD_SYM($1);
109 - | evalsym DIVEQ expr {
110 - ADD_OP(OP_DIV); ADD_OP(OP_ASSIGN); ADD_SYM($1);
112 - | evalsym MODEQ expr {
113 - ADD_OP(OP_MOD); ADD_OP(OP_ASSIGN); ADD_SYM($1);
115 - | evalsym ANDEQ expr {
116 - ADD_OP(OP_BIT_AND); ADD_OP(OP_ASSIGN); ADD_SYM($1);
118 - | evalsym OREQ expr {
119 - ADD_OP(OP_BIT_OR); ADD_OP(OP_ASSIGN); ADD_SYM($1);
120 + | SYMBOL incrdecr {
121 + ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP($2);
122 + ADD_OP(OP_ASSIGN); ADD_SYM($1);
124 - | DELETE arraylv '[' arglist ']' {
125 - ADD_OP(OP_ARRAY_DELETE); ADD_IMMED($4);
126 + /* delete array entry simple statement */
127 + | DELETE arraylv '[' arglistopt ']' {
128 + ADD_OP(OP_ARRAY_DELETE); ADD_IMMED($4);
130 | DELETE arraylv dot field {
131 - ADD_OP(OP_ARRAY_DELETE); ADD_IMMED(1);
132 + ADD_OP(OP_ARRAY_DELETE); ADD_IMMED(1);
134 -/* array[index] assignment */
135 - | initarraylv '[' arglist ']' '=' expr {
136 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
138 - | initarraylv '[' arglist ']' ADDEQ expr {
139 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
140 - ADD_OP(OP_ADD);
141 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
143 - | initarraylv '[' arglist ']' SUBEQ expr {
144 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
145 - ADD_OP(OP_SUB);
146 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
148 - | initarraylv '[' arglist ']' MULEQ expr {
149 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
150 - ADD_OP(OP_MUL);
151 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
153 - | initarraylv '[' arglist ']' DIVEQ expr {
154 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
155 - ADD_OP(OP_DIV);
156 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
158 - | initarraylv '[' arglist ']' MODEQ expr {
159 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
160 - ADD_OP(OP_MOD);
161 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
163 - | initarraylv '[' arglist ']' ANDEQ expr {
164 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
165 - ADD_OP(OP_BIT_AND);
166 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
168 - | initarraylv '[' arglist ']' OREQ expr {
169 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
170 - ADD_OP(OP_BIT_OR);
171 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
173 - | initarraylv '[' arglist ']' INCR {
174 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3);
175 - ADD_OP(OP_INCR);
176 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
178 - | initarraylv '[' arglist ']' DECR {
179 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3);
180 - ADD_OP(OP_DECR);
181 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
183 - | INCR initarraylv '[' arglist ']' {
184 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($4);
185 - ADD_OP(OP_INCR);
186 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($4);
188 - | DECR initarraylv '[' arglist ']' {
189 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($4);
190 - ADD_OP(OP_DECR);
191 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($4);
193 -/* array.field assignment */
194 - | initarraylv dot field '=' expr {
195 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
197 - | initarraylv dot field ADDEQ expr {
198 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
199 - ADD_OP(OP_ADD);
200 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
202 - | initarraylv dot field SUBEQ expr {
203 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
204 - ADD_OP(OP_SUB);
205 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
207 - | initarraylv dot field MULEQ expr {
208 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
209 - ADD_OP(OP_MUL);
210 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
212 - | initarraylv dot field DIVEQ expr {
213 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
214 - ADD_OP(OP_DIV);
215 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
217 - | initarraylv dot field MODEQ expr {
218 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
219 - ADD_OP(OP_MOD);
220 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
222 - | initarraylv dot field ANDEQ expr {
223 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
224 - ADD_OP(OP_BIT_AND);
225 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
227 - | initarraylv dot field OREQ expr {
228 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED(1);
229 - ADD_OP(OP_BIT_OR);
230 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
232 - | initarraylv dot field INCR {
233 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
234 - ADD_OP(OP_INCR);
235 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
237 - | initarraylv dot field DECR {
238 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
239 - ADD_OP(OP_DECR);
240 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
242 - | INCR initarraylv dot field {
243 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
244 - ADD_OP(OP_INCR);
245 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
247 - | DECR initarraylv dot field {
248 - ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
249 - ADD_OP(OP_DECR);
250 - ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
251 + /* array[index] assignment, op-assignment, incr/decrement */
252 + | initarraylv '[' arglistopt ']' '=' blank expr {
253 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
255 + | initarraylv '[' arglistopt ']' operassign blank expr {
256 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1); ADD_IMMED($3);
257 + ADD_OP($5);
258 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
260 + | initarraylv '[' arglistopt ']' incrdecr {
261 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($3);
262 + ADD_OP($5);
263 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($3);
265 + | incrdecr blank initarraylv '[' arglistopt ']' {
266 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED($5);
267 + ADD_OP($1);
268 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED($5);
270 + /* array.field assignment, op-assignment, incr/decrement */
271 + | initarraylv dot field '=' blank expr {
272 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
274 + | initarraylv dot field operassign blank expr {
275 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(1);ADD_IMMED(1);
276 + ADD_OP($4);
277 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
279 + | initarraylv dot field incrdecr {
280 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
281 + ADD_OP($4);
282 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
284 + | incrdecr blank initarraylv dot field {
285 + ADD_OP(OP_ARRAY_REF_ASSIGN_SETUP); ADD_IMMED(0); ADD_IMMED(1);
286 + ADD_OP($1);
287 + ADD_OP(OP_ARRAY_ASSIGN); ADD_IMMED(1);
289 - | SYMBOL '(' arglist ')' {
290 + /* function call */
291 + | SYMBOL '(' arglistopt ')' {
292 ADD_OP(OP_SUBR_CALL);
293 - ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3);
295 - | INCR SYMBOL {
296 - ADD_OP(OP_PUSH_SYM); ADD_SYM($2); ADD_OP(OP_INCR);
297 - ADD_OP(OP_ASSIGN); ADD_SYM($2);
299 - | SYMBOL INCR {
300 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP(OP_INCR);
301 - ADD_OP(OP_ASSIGN); ADD_SYM($1);
303 - | DECR SYMBOL {
304 - ADD_OP(OP_PUSH_SYM); ADD_SYM($2); ADD_OP(OP_DECR);
305 - ADD_OP(OP_ASSIGN); ADD_SYM($2);
307 - | SYMBOL DECR {
308 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP(OP_DECR);
309 - ADD_OP(OP_ASSIGN); ADD_SYM($1);
310 + ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3);
314 evalsym: SYMBOL {
315 $$ = $1; ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
318 -comastmts: /* nothing */ {
319 - $$ = GetPC();
321 - | simpstmt {
322 - $$ = GetPC();
324 - | comastmts ',' simpstmt {
325 - $$ = GetPC();
327 +comastmts: blank { $$ = GetPC(); }
328 + | blank comastmtlst { $$ = $2; }
330 -arglist: /* nothing */ {
331 - $$ = 0;
333 - | expr {
334 - $$ = 1;
336 - | arglist ',' expr {
337 - $$ = $1 + 1;
339 +comastmtlst: simpstmt blank { $$ = GetPC(); }
340 + | comastmtlst ',' blank simpstmt blank { $$ = GetPC(); }
343 +arglistopt: blank { $$ = 0; }
344 + | arglist { $$ = $1; }
346 +arglist: blank expr blank { $$ = 1; }
347 + | arglist ',' blank expr blank { $$ = $1 + 1; }
349 +catlist: numexpr %prec CONCAT { $$ = 1; }
350 + | catlist numexpr %prec CONCAT { $$ = $1 + 1; }
352 -catlist: numexpr %prec CONCAT {
353 - $$ = 1;
355 - | catlist numexpr %prec CONCAT {
356 - $$ = $1 + 1;
358 expr: catlist {
359 if ($1 > 1) {
360 - ADD_OP(OP_CONCAT); ADD_IMMED($1);
361 + ADD_OP(OP_CONCAT); ADD_IMMED($1);
365 initarraylv: SYMBOL {
366 - ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(1);
367 + ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(1);
369 - | initarraylv '[' arglist ']' {
370 - ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
371 + | initarraylv '[' arglistopt ']' {
372 + ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
374 | initarraylv dot field {
375 - ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
376 + ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
379 arraylv: SYMBOL {
380 - ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(0);
381 + ADD_OP(OP_PUSH_ARRAY_SYM); ADD_SYM($1); ADD_IMMED(0);
383 - | arraylv '[' arglist ']' {
384 - ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
385 + | arraylv '[' arglistopt ']' {
386 + ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
388 | arraylv dot field {
389 - ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
390 + ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
393 field: FIELD {
394 @@ -400,130 +311,82 @@
395 $$ = GetPC();
398 -numexpr: NUMBER {
399 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
401 - | STRING {
402 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
404 - | SYMBOL {
405 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1);
407 - | SYMBOL '(' arglist ')' {
408 +numexpr: '(' blank expr blank ')'
409 + | NUMBER { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); }
410 + | STRING { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); }
411 + | SYMBOL { ADD_OP(OP_PUSH_SYM); ADD_SYM($1); }
412 + | SYMBOL '(' arglistopt ')' {
413 ADD_OP(OP_SUBR_CALL);
414 - ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3);
415 + ADD_SYM(PromoteToGlobal($1)); ADD_IMMED($3);
416 ADD_OP(OP_FETCH_RET_VAL);
418 - | '(' expr ')'
419 - | ARG_LOOKUP '[' numexpr ']' {
420 - ADD_OP(OP_PUSH_ARG);
422 - | ARG_LOOKUP '[' ']' {
423 - ADD_OP(OP_PUSH_ARG_COUNT);
425 - | ARG_LOOKUP {
426 - ADD_OP(OP_PUSH_ARG_ARRAY);
428 - | numexpr '[' arglist ']' {
429 - ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
430 + | ARG_LOOKUP '[' blank numexpr blank ']' { ADD_OP(OP_PUSH_ARG); }
431 + | ARG_LOOKUP '[' blank ']' { ADD_OP(OP_PUSH_ARG_COUNT); }
432 + | ARG_LOOKUP { ADD_OP(OP_PUSH_ARG_ARRAY); }
433 + | numexpr '[' arglistopt ']' {
434 + ADD_OP(OP_ARRAY_REF); ADD_IMMED($3);
436 | numexpr dot field {
437 - ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
439 - | numexpr '+' numexpr {
440 - ADD_OP(OP_ADD);
442 - | numexpr '-' numexpr {
443 - ADD_OP(OP_SUB);
445 - | numexpr '*' numexpr {
446 - ADD_OP(OP_MUL);
448 - | numexpr '/' numexpr {
449 - ADD_OP(OP_DIV);
451 - | numexpr '%' numexpr {
452 - ADD_OP(OP_MOD);
454 - | numexpr POW numexpr {
455 - ADD_OP(OP_POWER);
456 + ADD_OP(OP_ARRAY_REF); ADD_IMMED(1);
458 - | '-' numexpr %prec UNARY_MINUS {
459 - ADD_OP(OP_NEGATE);
461 - | numexpr GT numexpr {
462 - ADD_OP(OP_GT);
464 - | numexpr GE numexpr {
465 - ADD_OP(OP_GE);
467 - | numexpr LT numexpr {
468 - ADD_OP(OP_LT);
470 - | numexpr LE numexpr {
471 - ADD_OP(OP_LE);
473 - | numexpr EQ numexpr {
474 - ADD_OP(OP_EQ);
476 - | numexpr NE numexpr {
477 - ADD_OP(OP_NE);
479 - | numexpr '&' numexpr {
480 - ADD_OP(OP_BIT_AND);
482 - | numexpr '|' numexpr {
483 - ADD_OP(OP_BIT_OR);
485 - | numexpr and numexpr %prec AND {
486 + | '-' blank numexpr %prec UNARY_MINUS { ADD_OP(OP_NEGATE); }
487 + | NOT blank numexpr { ADD_OP(OP_NOT); }
488 + | numexpr '+' blank numexpr { ADD_OP(OP_ADD); }
489 + | numexpr '-' blank numexpr { ADD_OP(OP_SUB); }
490 + | numexpr '*' blank numexpr { ADD_OP(OP_MUL); }
491 + | numexpr '/' blank numexpr { ADD_OP(OP_DIV); }
492 + | numexpr '%' blank numexpr { ADD_OP(OP_MOD); }
493 + | numexpr POW blank numexpr { ADD_OP(OP_POWER); }
494 + | numexpr GT blank numexpr { ADD_OP(OP_GT); }
495 + | numexpr GE blank numexpr { ADD_OP(OP_GE); }
496 + | numexpr LT blank numexpr { ADD_OP(OP_LT); }
497 + | numexpr LE blank numexpr { ADD_OP(OP_LE); }
498 + | numexpr EQ blank numexpr { ADD_OP(OP_EQ); }
499 + | numexpr NE blank numexpr { ADD_OP(OP_NE); }
500 + | numexpr '&' blank numexpr { ADD_OP(OP_BIT_AND); }
501 + | numexpr '|' blank numexpr { ADD_OP(OP_BIT_OR); }
502 + | numexpr and blank numexpr %prec AND {
503 ADD_OP(OP_AND); SET_BR_OFF($2, GetPC());
505 - | numexpr or numexpr %prec OR {
506 + | numexpr or blank numexpr %prec OR {
507 ADD_OP(OP_OR); SET_BR_OFF($2, GetPC());
509 - | NOT numexpr {
510 - ADD_OP(OP_NOT);
512 - | INCR SYMBOL {
513 - ADD_OP(OP_PUSH_SYM); ADD_SYM($2); ADD_OP(OP_INCR);
514 - ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM($2);
516 - | SYMBOL INCR {
517 - ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP(OP_DUP);
518 - ADD_OP(OP_INCR); ADD_OP(OP_ASSIGN); ADD_SYM($1);
520 - | DECR SYMBOL {
521 - ADD_OP(OP_PUSH_SYM); ADD_SYM($2); ADD_OP(OP_DECR);
522 - ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM($2);
523 + | incrdecr blank SYMBOL %prec INCR {
524 + ADD_OP(OP_PUSH_SYM); ADD_SYM($3); ADD_OP($1);
525 + ADD_OP(OP_DUP); ADD_OP(OP_ASSIGN); ADD_SYM($3);
527 - | SYMBOL DECR {
528 + | SYMBOL incrdecr %prec INCR {
529 ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP(OP_DUP);
530 - ADD_OP(OP_DECR); ADD_OP(OP_ASSIGN); ADD_SYM($1);
531 + ADD_OP($2); ADD_OP(OP_ASSIGN); ADD_SYM($1);
533 - | numexpr IN numexpr {
534 + | numexpr IN blank numexpr {
535 ADD_OP(OP_IN_ARRAY);
537 - | numexpr NOT IN numexpr {
538 + | numexpr NOT IN blank numexpr %prec IN {
539 ADD_OP(OP_IN_ARRAY);
540 ADD_OP(OP_NOT);
543 -while: WHILE {
544 +while: WHILE blank {
545 + $$ = GetPC(); StartLoopAddrList();
548 +do: DO blank {
549 $$ = GetPC(); StartLoopAddrList();
552 -for: FOR {
553 +for: FOR blank {
554 StartLoopAddrList(); $$ = GetPC();
557 -else: ELSE {
558 +else: ELSE blank {
559 ADD_OP(OP_BRANCH); $$ = GetPC(); ADD_BR_OFF(0);
562 -cond: /* nothing */ {
563 +cond: blank {
564 ADD_OP(OP_BRANCH_NEVER); $$ = GetPC(); ADD_BR_OFF(0);
566 - | numexpr {
567 + | blank numexpr blank {
568 ADD_OP(OP_BRANCH_FALSE); $$ = GetPC(); ADD_BR_OFF(0);
571 @@ -547,7 +410,6 @@
573 %% /* User Subroutines Section */
577 ** Parse a null terminated string and create a program from it (this is the
578 ** parser entry point). The program created by this routine can be
579 @@ -589,19 +451,8 @@
580 return prog;
584 -static int yylex(void)
586 - int i, len;
587 - Symbol *s;
588 - static DataValue value = {NO_TAG, {0}};
589 - static char escape[] = "\\\"ntbrfave";
590 -#ifdef EBCDIC_CHARSET
591 - static char replace[] = "\\\"\n\t\b\r\f\a\v\x27"; /* EBCDIC escape */
592 -#else
593 - static char replace[] = "\\\"\n\t\b\r\f\a\v\x1B"; /* ASCII escape */
594 -#endif
596 +static char skipWhitespace(void)
598 /* skip whitespace, backslash-newline combinations, and comments, which are
599 all considered whitespace */
600 for (;;) {
601 @@ -609,7 +460,8 @@
602 InPtr += 2;
603 else if (*InPtr == ' ' || *InPtr == '\t')
604 InPtr++;
605 - else if (*InPtr == '#')
606 + else if (*InPtr == '#') {
607 + InPtr++;
608 while (*InPtr != '\n' && *InPtr != '\0') {
609 /* Comments stop at escaped newlines */
610 if (*InPtr == '\\' && *(InPtr + 1) == '\n') {
611 @@ -617,10 +469,28 @@
612 break;
614 InPtr++;
615 - } else
618 + else
619 break;
621 + return *InPtr;
624 +static int yylex(void)
626 + int len;
627 + Symbol *s;
628 + static DataValue value = {NO_TAG, {0}};
629 + static char escape[] = "\\\"ntbrfave";
630 +#ifdef EBCDIC_CHARSET
631 + static char replace[] = "\\\"\n\t\b\r\f\a\v\x27"; /* EBCDIC escape */
632 +#else
633 + static char replace[] = "\\\"\n\t\b\r\f\a\v\x1B"; /* ASCII escape */
634 +#endif
635 + int result;
637 + skipWhitespace();
639 /* return end of input at the end of the string */
640 if (*InPtr == '\0') {
641 @@ -655,6 +525,7 @@
643 *p = '\0';
644 if (!strcmp(symName, "while")) return WHILE;
645 + if (!strcmp(symName, "do")) return DO;
646 if (!strcmp(symName, "if")) return IF;
647 if (!strcmp(symName, "else")) return ELSE;
648 if (!strcmp(symName, "for")) return FOR;
649 @@ -796,7 +667,8 @@
652 /* process remaining two character tokens or return single char as token */
653 - switch(*InPtr++) {
654 + result = *InPtr++;
655 + switch (result) {
656 case '>': return follow('=', GE, GT);
657 case '<': return follow('=', LE, LT);
658 case '=': return follow('=', EQ, '=');
659 @@ -809,6 +681,14 @@
660 case '/': return follow('=', DIVEQ, '/');
661 case '%': return follow('=', MODEQ, '%');
662 case '^': return POW;
663 + case '\n':
664 + case '(':
665 + case '[': {
666 + /* skip newline ( whitespace* newline )* */
667 + while (skipWhitespace() == '\n')
668 + ++InPtr;
669 + return result; /* but return what we started with */
671 default: return *(InPtr-1);