-
Notifications
You must be signed in to change notification settings - Fork 0
/
algol60-indent.c
685 lines (616 loc) · 26.2 KB
/
algol60-indent.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
// This is algol60-indent.c
// This file and algol60.g are the only two files that needed to be
// created manually to create the algol60 formatter - everything else
// is supplied or built automatically. And this file was initially
// generated by gencomp, but subsequently manually edited to implement
// the indentation and symbol canonicalization:
// This module re-outputs the AST parse tree as text, but reindents the
// ALGOL 60 code. It *does not* break lines anywhere or join lines - it
// just adjusts the indentation of the existing line structure. A 'wc'
// of the file before and after should show matching line counts.
// It also canonicalises much of the representation of the source to the
// preferred Unicode characters, except in the few cases where the appropriate
// Unicode character is not well supported at the time of writing this code.
// A run-time option allows for output of 7-bit ascii format (for
// other algol60 compilers such as jff or marst etc.)
int jff = FALSE;
// There are some small infelicities in the indentation algorithm that
// I decided to live with - fixing them looks like too much complexity,
// whereas we already get pretty good results with this simple algorithm.
#define INDENT " "
#define CONTINUATION " "
int ilev = 0; /* nested begin/end for now. Later use a stack */
int delayed_ilev = 0;
int continuation_spaces = 0;
int suppress_spaces = TRUE;
typedef struct text_descriptor {
int start;
int end;
} text_descriptor;
// NOTE! With the simple addition of a flag and a test, re-indentation
// could be made into a run-time option.
void Outch(wint_t wch) {
static wint_t lastwch = -1;
if (suppress_spaces) {
if (wch == ' ' || wch == '\t') return; // remove existing indentation
if (wch != '\n') { // then replace with calculated indentation
// indent here by ilev then go back to 'normal' mode
int i;
for (i = 0; i < ilev; i++) printf(INDENT);
if (continuation_spaces == 2) printf(CONTINUATION);
fprintf(stdout, "%lc", wch);
continuation_spaces = 2;
suppress_spaces = FALSE;
} else {
fprintf(stdout, "\n");
ilev += delayed_ilev; delayed_ilev = 0;
// Continue to suppress leading spaces
}
} else {
if (wch == '\n') {
fprintf(stdout, "\n");
ilev += delayed_ilev; delayed_ilev = 0;
suppress_spaces = TRUE;
} else {
fprintf(stdout, "%lc", wch);
continuation_spaces = 2;
}
}
}
void O(int Leading_spaces, wchar_t *Literal) {
int i;
// leading spaces
for (i = atom(Leading_spaces).start; i < atom(Leading_spaces).end; i++) {
if (source(i) != ' ') break;
Outch(source(i));
}
// replacement text
while (*Literal != '\0') Outch(*Literal++);
i = atom(Leading_spaces).end;
// trailing spaces. Uncommon but can happen from a regex
for (;;) {
if (i <= atom(Leading_spaces).start) break;
--i;
if (source(i) != ' ') break;
Outch(source(i));
}
}
#define PrintIndent(x) PrintIndent_inner(x, __LINE__)
void PrintIndent_inner(int Literal, int line) {
int leading_space = TRUE, stropped = FALSE;
int i;
// fprintf(stderr, "PrintIndent(%d) at line %d\n", Literal, line);
for (i = atom(Literal).start; i < atom(Literal).end; i++) {
if (!jff) {
Outch(source(i));
} else {
if (leading_space && (source(i) == ' ' || source(i) == '\n' || source(i) == '\t' || source(i) == '\f')) {
Outch(source(i));
} else {
if (leading_space) {
if (source(i+1) == 818) {
Outch('\'');
stropped = TRUE;
}
leading_space = FALSE;
}
if (source(i+1) == 818) { // combining low-line post-character underline
Outch(source(i)); i += 1;
} else {
Outch(source(i));
}
}
}
}
if (stropped) Outch('\'');
}
text_descriptor reindent(int P, int depth) {
text_descriptor r = {0,0};
if (P <= 0) return r;
int i;
int AST_type = (int)((unsigned int)P&(((unsigned int)AST_type_mask)<<(unsigned int)AST_type_shift)); // runtime error: left shift of 15 by 28 places cannot be represented in type 'int'
int AST_index = P&AST_idx_mask;
int alt = AST(AST_index+2);
int count = AST(AST_index+3);
//fprintf(stderr, "P=%d AST_type = %d AST_index = %d alt=%d count=%d\n", P, AST_type>>AST_type_shift, AST_index, alt, count);
if (AST_type == AST_PHRASE) {
int i;
int op = AST(AST_index+1);
//fprintf(stderr, "op=%d %ls\n", op, PHRASE(op));
// Let's test modifications to the tree walk by intercepting some phrases.
// If you want to intercept a subset of some phrase (eg <NAME> but only in
// the context of a procedure name, for example) then just add a dummy level
// of indirection such as P<PROCNAME> = <NAME>;
// This test will capitalize all <NAME>s.
switch (op) {
// What in yacc etc would be $1 is referred to here as SubPhrase(P,1)
//\\ P<ldquo> = "“", '{', "‘", "'('", "«", "|<";
case G_ldquo:
O(SubPhrase(P, 1), (jff ? L"\"" : L"“"));
return r;
//\\ P<rdquo> = "”", '}', "’", "')'", "»", "|>";
case G_rdquo:
O(SubPhrase(P, 1), (jff ? L"\"" : L"”"));
return r;
//\\ P<BALANCED_STRING> =
case G_BALANCED_STRING:
{ //\\ <ldquo> <BALANCED_CHAR_SEQUENCE> <rdquo>;
reindent(SubPhraseIdx(P, 1), depth+1 /* G_ldquo */);
reindent(SubPhraseIdx(P, 2), depth+1 /* G_BALANCED_CHAR_SEQUENCE */);
reindent(SubPhraseIdx(P, 3), depth+1 /* G_rdquo */);
}
return r;
//\\ P<C_STRING> =
case G_C_STRING:
{
O(SubPhrase(P, 1), (jff ? L"\"" : L"“"));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_C_CHARS */);
O(SubPhrase(P, 3), (jff ? L"\"" : L"”"));
}
return r;
//\\ P<semi> =
case G_semi:
{ //\\ ";";
PrintIndent(SubPhrase(P, 1));
continuation_spaces = 0;
}
return r;
//\\ P<else> =
case G_else:
{ //\\ "e̲l̲s̲e̲";
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 1));
continuation_spaces = 2;
}
return r;
//\\ P<semi_opt> =
case G_semi_opt:
if (alt == 0) { //\\ ';',
PrintIndent(SubPhrase(P, 1) /*, L';' */);
continuation_spaces = 0;
} else { //\\ ;
}
return r;
//\\ P<MAIN_PROGRAM> =
case G_MAIN_PROGRAM:
{ //\\ <PROGRAM_opt> <COMMENTS_opt> "b̲e̲g̲i̲n̲" <LOCAL_BLOCK> "e̲n̲d̲" <ENDTEXT>;
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROGRAM_opt */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_COMMENTS_opt */);
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 3));
ilev += 1; continuation_spaces = 0;
reindent(SubPhraseIdx(P, 4), depth+1 /* G_LOCAL_BLOCK */);
ilev -= 1; continuation_spaces = 0;
PrintIndent(SubPhrase(P, 5));
reindent(SubPhraseIdx(P, 6), depth+1 /* G_ENDTEXT */);
continuation_spaces = 0;
}
return r;
//\\ P<PROGRAM_opt> =
case G_PROGRAM_opt:
if (alt == 0) { //\\ "p̲r̲o̲g̲r̲a̲m̲" <NAME> ';',
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_NAME */);
PrintIndent(SubPhrase(P, 3) /*, L';' */);
} else { //\\ ;
}
continuation_spaces = 0;
return r;
//\\ P<EXTERNAL_LEVEL_OBJECTS> =
case G_EXTERNAL_LEVEL_OBJECTS:
if (alt == 0) { //\\ <EXTERNAL_LEVEL> <EXTERNAL_LEVEL_OBJECTS>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_EXTERNAL_LEVEL */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_EXTERNAL_LEVEL_OBJECTS */);
} else { //\\ ;
}
return r;
//\\ P<EXTERNAL_LEVEL> =
case G_EXTERNAL_LEVEL:
if (alt == 0) { //\\ "e̲o̲p̲",
PrintIndent(SubPhrase(P, 1));
} else if (alt == 1) { //\\ "c̲o̲d̲e̲" <DIGITS> ';',
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_DIGITS */);
PrintIndent(SubPhrase(P, 3) /*, L';' */);
} else if (alt == 2) { //\\ <COMMENT>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_COMMENT */);
} else if (alt == 3) { //\\ <PROCEDURE> ';',
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROCEDURE */);
PrintIndent(SubPhrase(P, 2) /*, L';' */);
} else { //\\ <OWN_DECLARATION> ';';
reindent(SubPhraseIdx(P, 1), depth+1 /* G_OWN_DECLARATION */);
PrintIndent(SubPhrase(P, 2) /*, L';' */);
}
continuation_spaces = 0;
return r;
//\\ P<BOOLEAN> =
case G_BOOLEAN:
if (alt == 0) { //\\ "B̲o̲o̲l̲e̲a̲n̲",
PrintIndent(SubPhrase(P, 1));
} else { //\\ "b̲o̲o̲l̲e̲a̲n̲";
PrintIndent(SubPhrase(P, 1));
}
return r;
//\\ P<PROCEDURE> =
case G_PROCEDURE:
{ //\\ <PROCTYPE_opt> "p̲r̲o̲c̲e̲d̲u̲r̲e̲" <NAME> <FORMAL_PARAMS_opt> ';' <COMMENTS_opt> <VALUE_opt> <PARAMETER_TYPES_opt> <LABELS_opt> <PROCBODY>;
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROCTYPE_opt */);
PrintIndent(SubPhrase(P, 2));
reindent(SubPhraseIdx(P, 3), depth+1 /* G_NAME */);
reindent(SubPhraseIdx(P, 4), depth+1 /* G_FORMAL_PARAMS_opt */);
PrintIndent(SubPhrase(P, 5) /*, L';' */);
ilev += 1;
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 6), depth+1 /* G_COMMENTS_opt */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 7), depth+1 /* G_VALUE_opt */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 8), depth+1 /* G_PARAMETER_TYPES_opt */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 9), depth+1 /* G_LABELS_opt */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 10), depth+1 /* G_PROCBODY */);
ilev -= 1;
continuation_spaces = 0;
}
return r;
//\\ P<VALUE_opt> =
case G_VALUE_opt:
if (alt == 0) { //\\ "v̲a̲l̲u̲e̲" <ONAMELIST> ';',
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_ONAMELIST */);
PrintIndent(SubPhrase(P, 3) /*, L';' */);
} else { //\\ ;
}
continuation_spaces = 0;
return r;
//\\ P<COMMENT> =
case G_COMMENT:
{ //\\ <COMMENT_NO_SEMI> ';';
reindent(SubPhraseIdx(P, 1), depth+1 /* G_COMMENT_NO_SEMI */);
PrintIndent(SubPhrase(P, 2) /*, L';' */);
continuation_spaces = 0;
}
return r;
//\\ P<MORE_COMMENTS> =
case G_MORE_COMMENTS:
if (alt == 0) { //\\ ';' <COMMENT> <MORE_COMMENTS>,
PrintIndent(SubPhrase(P, 1) /*, L';' */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_COMMENT */);
reindent(SubPhraseIdx(P, 3), depth+1 /* G_MORE_COMMENTS */);
} else { //\\ ;
}
return r;
//\\ P<LABELS_opt> =
case G_LABELS_opt:
if (alt == 0) { //\\ <NAME> <!assign> ":" <!comment_keyword> <LABELS_opt>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_NAME */);
PrintIndent(SubPhrase(P, 3));
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 5), depth+1 /* G_LABELS_opt */);
} else { //\\ ;
}
return r;
//\\ P<LEXPR> =
case G_LEXPR:
if (alt == 0) { //\\ '(' <LEXPR> ')',
PrintIndent(SubPhrase(P, 1) /*, L'(' */);
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LEXPR */);
PrintIndent(SubPhrase(P, 3) /*, L')' */);
} else if (alt == 1) { //\\ "i̲f̲" <BEXPR> "t̲h̲e̲n̲" <SLEXPR> "e̲l̲s̲e̲" <LEXPR>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_BEXPR */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_SLEXPR */);
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 5));
continuation_spaces = 2;
reindent(SubPhraseIdx(P, 6), depth+1 /* G_LEXPR */);
} else { //\\ <SLEXPR>;
reindent(SubPhraseIdx(P, 1), depth+1 /* G_SLEXPR */);
}
return r;
//\\ P<COLON_WARN_COMMA> = ':', ',', "..";
case G_COLON_WARN_COMMA:
O(SubPhrase(P, 1), L":");
return r;
//\\ P<PROCBODY> =
case G_PROCBODY:
if (alt == 0) { //\\ "c̲o̲d̲e̲" <DIGITS>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_DIGITS */);
} else if (alt == 1) { //\\ "a̲l̲g̲o̲l̲",
PrintIndent(SubPhrase(P, 1));
} else if (alt == 2) { //\\ "f̲o̲r̲t̲r̲a̲n̲",
PrintIndent(SubPhrase(P, 1));
} else if (alt == 3) { //\\ "e̲x̲t̲e̲r̲n̲a̲l̲",
PrintIndent(SubPhrase(P, 1));
} else if (alt == 4) { //\\ "b̲e̲g̲i̲n̲" <LOCAL_BLOCK> "e̲n̲d̲" <ENDTEXT>,
ilev -= 1;
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 1));
ilev += 1; continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LOCAL_BLOCK */);
ilev -= 1; continuation_spaces = 0;
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_ENDTEXT */);
ilev += 1;
} else if (alt == 5) { //\\ <ASSIGNMENT>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_ASSIGNMENT */);
} else if (alt == 6) { //\\ <PROCEDURE_CALL>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROCEDURE_CALL */);
} else if (alt == 7) { //\\ "f̲o̲r̲" <LHS> ":=" <FLE> <FORLIST> "d̲o̲" <LABELS_opt> <LOCAL_STATEMENT>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LHS */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_FLE */);
reindent(SubPhraseIdx(P, 5), depth+1 /* G_FORLIST */);
PrintIndent(SubPhrase(P, 6));
ilev += 1;
reindent(SubPhraseIdx(P, 7), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 8), depth+1 /* G_LOCAL_STATEMENT */);
ilev -= 1;
} else if (alt == 8) { //\\ "i̲f̲" <BEXPR> "t̲h̲e̲n̲" <LABELS_opt> <LOCAL_STATEMENT> <OPT_ELSE>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_BEXPR */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 5), depth+1 /* G_LOCAL_STATEMENT */);
reindent(SubPhraseIdx(P, 6), depth+1 /* G_OPT_ELSE */);
} else if (alt == 9) { //\\ "g̲o̲" "t̲o̲" <JUMP_TARGET>,
PrintIndent(SubPhrase(P, 1));
PrintIndent(SubPhrase(P, 2));
reindent(SubPhraseIdx(P, 3), depth+1 /* G_JUMP_TARGET */);
} else { //\\ ;
}
return r;
//\\ P<MORE_LOCAL_STATEMENTS> =
case G_MORE_LOCAL_STATEMENTS:
if (alt == 0) { //\\ ';' <LABELS_opt> <LOCAL_STATEMENT> <MORE_LOCAL_STATEMENTS>,
PrintIndent(SubPhrase(P, 1) /*, L';' */);
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 3), depth+1 /* G_LOCAL_STATEMENT */);
reindent(SubPhraseIdx(P, 4), depth+1 /* G_MORE_LOCAL_STATEMENTS */);
} else { //\\ ;
}
return r;
//\\ P<LOCAL_STATEMENT> =
case G_LOCAL_STATEMENT:
if (alt == 0) { //\\ <COMMENT_NO_SEMI>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_COMMENT_NO_SEMI */);
} else if (alt == 1) { //\\ <ASSIGNMENT>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_ASSIGNMENT */);
} else if (alt == 2) { //\\ <PROCEDURE_CALL>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROCEDURE_CALL */);
} else if (alt == 3) { //\\ "b̲e̲g̲i̲n̲" <LOCAL_BLOCK> "e̲n̲d̲" <ENDTEXT>,
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 1));
ilev += 1; continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LOCAL_BLOCK */);
ilev -= 1; continuation_spaces = 0;
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_ENDTEXT */);
} else if (alt == 4) { //\\ "f̲o̲r̲" <LHS> ":=" <FLE> <FORLIST> "d̲o̲" <LABELS_opt> <LOCAL-STATEMENT>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LHS */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_FLE */);
reindent(SubPhraseIdx(P, 5), depth+1 /* G_MORE_FORLIST */);
PrintIndent(SubPhrase(P, 6));
ilev += 1;
reindent(SubPhraseIdx(P, 7), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 8), depth+1 /* G_LOCAL_STATEMENT */);
ilev -= 1;
} else if (alt == 5) { //\\ "i̲f̲" <BEXPR> "t̲h̲e̲n̲" <LABELS_opt> <LOCAL_STATEMENT> <OPT_ELSE>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_BEXPR */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 5), depth+1 /* G_LOCAL_STATEMENT */);
reindent(SubPhraseIdx(P, 6), depth+1 /* G_OPT_ELSE */);
} else if (alt == 6) { //\\ "g̲o̲" "t̲o̲" <JUMP_TARGET>,
PrintIndent(SubPhrase(P, 1));
PrintIndent(SubPhrase(P, 2));
reindent(SubPhraseIdx(P, 3), depth+1 /* G_JUMP_TARGET */);
} else if (alt == 7) { //\\ <CODE>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_CODE */);
} else if (alt == 8) { //\\ <PROCEDURE>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_PROCEDURE */);
} else if (alt == 9) { //\\ <OWN_DECLARATION>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_OWN_DECLARATION */);
} else if (alt == 10) { //\\ <LOCAL_DECLARATION>,
reindent(SubPhraseIdx(P, 1), depth+1 /* G_LOCAL_DECLARATION */);
} else { //\\ ;
}
return r;
//\\ P<OPT_ELSE> =
case G_OPT_ELSE:
if (alt == 0) { //\\ "e̲l̲s̲e̲" <LABELS_opt> "i̲f̲" <BEXPR> "t̲h̲e̲n̲" <LABELS_opt> <LOCAL_STATEMENT> <OPT_ELSE>,
continuation_spaces = 2;
PrintIndent(SubPhrase(P, 1));
continuation_spaces = 0;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LABELS_opt */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_BEXPR */);
PrintIndent(SubPhrase(P, 5));
reindent(SubPhraseIdx(P, 6), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 7), depth+1 /* G_LOCAL_STATEMENT */);
reindent(SubPhraseIdx(P, 8), depth+1 /* G_OPT_ELSE */);
} else if (alt == 1) { //\\ "e̲l̲s̲e̲" <LABELS_opt> <LOCAL_STATEMENT>,
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 1));
continuation_spaces = 2;
reindent(SubPhraseIdx(P, 2), depth+1 /* G_LABELS_opt */);
reindent(SubPhraseIdx(P, 3), depth+1 /* G_LOCAL_STATEMENT */);
} else { //\\ ;
}
return r;
//\\ P<simple_arithmetic_expression> =
case G_arithmetic_expression:
if (alt == 0) { //\\ "i̲f̲" <Boolean_expression> "t̲h̲e̲n̲" <simple_arithmetic_expression> "e̲l̲s̲e̲" <arithmetic_expression>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_Boolean_expression */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_simple_arithmetic_expression */);
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 5));
continuation_spaces = 2;
reindent(SubPhraseIdx(P, 6), depth+1 /* G_arithmetic_expression */);
} else { //\\ <simple_arithmetic_expression>
reindent(SubPhraseIdx(P, 1), depth+1 /* G_simple_arithmetic_expression */);
}
return r;
//\\ P<Boolean_expression> =
case G_Boolean_expression:
if (alt == 0) { //\\ "i̲f̲" <Boolean_expression> "t̲h̲e̲n̲" <simple_Boolean> "e̲l̲s̲e̲" <Boolean_expression>,
PrintIndent(SubPhrase(P, 1));
reindent(SubPhraseIdx(P, 2), depth+1 /* G_Boolean_expression */);
PrintIndent(SubPhrase(P, 3));
reindent(SubPhraseIdx(P, 4), depth+1 /* G_simple_Boolean */);
continuation_spaces = 0;
PrintIndent(SubPhrase(P, 5));
continuation_spaces = 2;
reindent(SubPhraseIdx(P, 6), depth+1 /* G_Boolean_expression */);
} else { //\\ <simple_Boolean>;
reindent(SubPhraseIdx(P, 1), depth+1 /* G_Boolean_expression */);
}
return r;
// We'll canonicalise _10 with IMP-style '@' for now,
// until the Unicode character becomes more widely implemented
//\\ P<decimalpoint> = ".", "·";
case G_decimalpoint:
// O(SubPhrase(P, 1), L".");
O(SubPhrase(P, 1), (jff ? L"." : L"·"));
return r;
//\\ P<subten> = "@", "&", "⏨", "\u23E8", "\u2081\u2080";
case G_subten:
O(SubPhrase(P, 1), L"@"); // until ⏨ is better supported
return r;
//\\ P<exp_op> = "^", "**", "⭡", "p̲o̲w̲e̲r̲";
case G_exp_op:
O(SubPhrase(P, 1), (jff ? L"^" : L"⭡"));
return r;
//\\ P<mul_op> = "*", "×";
case G_mul_op:
O(SubPhrase(P, 1), (jff ? L"*" : L"×"));
return r;
//\\ P<idiv_op> = "//", "÷", "%", "d̲i̲v̲";
case G_idiv_op:
// if (alt == 2) warn(L"Check that % was used as a substitute for ÷ and not as m̲o̲d̲\n");
O(SubPhrase(P, 1), (jff ? L"'div'" : L"÷"));
return r;
//\\ P<and_term> = "a̲n̲d̲", "∧", "&";
case G_and_term:
O(SubPhrase(P, 1), (jff ? L"'and'" : L"∧"));
return r;
//\\ P<or_term> = "o̲r̲", "∨";
case G_or_term:
O(SubPhrase(P, 1), (jff ? L"'or'" : L"∨"));
return r;
//\\ P<equiv_term> = "e̲q̲u̲i̲v̲", "e̲q̲v̲", "≡";
case G_equiv_term:
O(SubPhrase(P, 1), (jff ? L"'equiv'" : L"≡"));
return r;
//\\ P<not_term> = "n̲o̲t̲", "¬", "!", "~";
case G_not_term:
O(SubPhrase(P, 1), (jff ? L"!" : L"¬"));
return r;
//\\ P<impl_term> = "i̲m̲p̲l̲", "⊃", "\u2283";
case G_impl_term:
O(SubPhrase(P, 1), (jff ? L"'implies'" : L"i̲m̲p̲l̲")); // until ⊃ is supported properly
return r;
// NOTE: the sloping <= (⩽ - U+2A7D) and >= (⩾ - U+2A7E) are a better representation than the
// default ≤ and ≥, however they do not work in plain unicode text files on my system so until
// support for those two characters improves I'll stick with the 'underlined <' representation.
// (That does not preclude using ⩽ and ⩾ in html output however...)
case G_relational_operator:
if (alt == 0) { //\\ "=",
O(SubPhrase(P, 1), L"=");
} else if (alt == 1) { //\\ "e̲q̲u̲a̲l̲",
O(SubPhrase(P, 1), L"=");
} else if (alt == 2) { //\\ "e̲q̲",
O(SubPhrase(P, 1), L"=");
} else if (alt == 3) { //\\ ">=",
O(SubPhrase(P, 1), (jff ? L">=" : L"≥"));
} else if (alt == 4) { //\\ "≥",
O(SubPhrase(P, 1), (jff ? L">=" : L"≥"));
} else if (alt == 5) { //\\ "g̲e̲",
O(SubPhrase(P, 1), (jff ? L">=" : L"≥"));
} else if (alt == 6) { //\\ "n̲o̲t̲l̲e̲s̲s̲",
O(SubPhrase(P, 1), (jff ? L">=" : L"≥"));
} else if (alt == 7) { //\\ "g̲r̲e̲q̲",
O(SubPhrase(P, 1), (jff ? L">=" : L"≥"));
} else if (alt == 8) { //\\ ">",
O(SubPhrase(P, 1), L">");
} else if (alt == 9) { //\\ "g̲t̲",
O(SubPhrase(P, 1), L">");
} else if (alt == 10) { //\\ "g̲r̲e̲a̲t̲e̲r̲",
O(SubPhrase(P, 1), L">");
} else if (alt == 11) { //\\ "<>",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 12) { //\\ "#",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 13) { //\\ "≠",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 14) { //\\ "n̲e̲",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 15) { //\\ "n̲o̲t̲e̲q̲u̲a̲l̲",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 16) { //\\ "\=",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 17) { //\\ "¬=",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 18) { //\\ "!=",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 19) { //\\ "^=",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 20) { //\\ "|=",
O(SubPhrase(P, 1), (jff ? L"!=" : L"≠"));
} else if (alt == 21) { //\\ "<=",
O(SubPhrase(P, 1), (jff ? L"<=" : L"≤"));
} else if (alt == 22) { //\\ "≤",
O(SubPhrase(P, 1), (jff ? L"<=" : L"≤"));
} else if (alt == 23) { //\\ "l̲e̲s̲s̲e̲q̲",
O(SubPhrase(P, 1), (jff ? L"<=" : L"≤"));
} else if (alt == 24) { //\\ "n̲o̲t̲g̲r̲e̲a̲t̲e̲r̲",
O(SubPhrase(P, 1), (jff ? L"<=" : L"≤"));
} else if (alt == 25) { //\\ "<",
O(SubPhrase(P, 1), L"<");
} else if (alt == 26) { //\\ "l̲t̲",
O(SubPhrase(P, 1), L"<");
} else if (alt == 27) { //\\ "l̲e̲s̲s̲",
O(SubPhrase(P, 1), L"<");
} else { //\\ "l̲e̲";
O(SubPhrase(P, 1), (jff ? L"<=" : L"≤"));
}
return r;
//\\ P<ARRAY_LB> =
case G_ARRAY_LB:
if (alt == 0) { //\\ '[',
PrintIndent(SubPhrase(P, 1) /*, L'[' */);
} else { //\\ "(/";
O(SubPhrase(P, 1), L"[");
}
return r;
//\\ P<ARRAY_RB> =
case G_ARRAY_RB:
if (alt == 0) { //\\ ']',
PrintIndent(SubPhrase(P, 1) /*, L']' */);
} else { //\\ "/)";
O(SubPhrase(P, 1), L"]");
}
return r;
//\\ E
default: // Everything else can use the default output code:
for (i = 1; i <= count; i++) reindent(SubPhraseIdx/*Idx*/(P,i), depth+1);
}
} else if ((AST_type == AST_LITERAL) || (AST_type == AST_BIP)) {
// Will only be called for phrases not specifically listed above.
PrintIndent(AST_index);
}
return r;
}