forked from rc0/jbofihe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex2.c
1217 lines (959 loc) · 26.9 KB
/
lex2.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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************
$Header$
Higher level lexing functions - group tokens together to implement
functions below the level of the bison grammar. Provide the yylex
function.
The order in which the lexing functions have to be performed comes
from the top of grammar.300 - acknowledgements to the Logical
Language Group who generated that file.
***************************************/
/* COPYRIGHT */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "functions.h"
#include "cmavotab.h"
#include "nodes.h"
#define YYSTYPE TreeNode *
#include "rpc_tab.h"
#include "elide.h"
/* For signalling syntax errors back to main routine */
int had_bad_tokens;
int last_tok_line;
int last_tok_column;
/* This is the main linked list used to hold all the tokens acquired during the
lexical analysis phase. */
static TreeNode toks = {&toks,&toks};
static TreeNode *next_tok;
/*++++++++++++++++++++++++++++++++++++++
Initialise the token list.
++++++++++++++++++++++++++++++++++++++*/
void
lex2_initialise(void)
{
toks.next = toks.prev = &toks;
next_tok = toks.next;
}
/*++++++++++++++++++++++++++++++++++++++
Add a new token to the token stream parsed from the file.
struct token *tok
++++++++++++++++++++++++++++++++++++++*/
void
add_token(TreeNode *node)
{
node->next = &toks;
node->prev = toks.prev;
toks.prev->next = node;
toks.prev = node;
}
/*++++++++++++++++++++++++++++++
Increment number of EOLs following last token
++++++++++++++++++++++++++++++*/
void
mark_eol(void)
{
++toks.prev->eols;
}
/*++++++++++++++++++++++++++++++++++++++
Delete a token, include fix up of pointers in neighbours
++++++++++++++++++++++++++++++++++++++*/
void
delete_node(TreeNode *x)
{
x->next->prev = x->prev;
x->prev->next = x->next;
/* Ought to release memory inside the node depending on type. */
Free(x);
}
/*++++++++++++++++++++++++++++++++++++++
Delete a token
++++++++++++++++++++++++++++++++++++++*/
void
free_node(TreeNode *x)
{
/* Ought to release memory inside the node depending on type. */
Free(x);
}
/*++++++++++++++++++++++++++++++++++++++
Display a single token.
++++++++++++++++++++++++++++++++++++++*/
static void
show_token(TreeNode *x)
{
int code;
switch (x->type) {
case N_GARBAGE:
printf("GAR : %s\n", x->data.garbage.word);
break;
case N_MARKER:
printf("MAR : %s\n", x->data.marker.text);
break;
case N_CMAVO:
code = x->data.cmavo.code;
printf("CMV : %s [%s]\n", cmavo_table[code].cmavo, cmavo_table[code].meaning);
break;
case N_ZOI:
printf("ZOI : %s\n", x->data.zoi.text);
break;
case N_ZO:
printf("ZO : %s\n", x->data.zo.text);
break;
case N_LOhU:
printf("LOhU : %s\n", x->data.lohu.text);
break;
case N_ZEI:
printf("ZEI : ");
printf("%s", build_string_from_node(x));
printf("\n");
break;
case N_BU:
printf("BU : %s\n", x->data.bu.word);
break;
case N_BRIVLA:
printf("BRV : %s\n", x->data.brivla.word);
break;
case N_CMENE:
printf("CMN : %s\n", x->data.cmene.word);
break;
case N_BROKEN_ERASURE:
printf("BKN : (broken erasure)\n");
break;
case N_NONTERM:
assert(0);
break;
}
}
/*++++++++++++++++++++++++++++++++++++++
Display sequence of tokens
++++++++++++++++++++++++++++++++++++++*/
void
show_tokens(void)
{
TreeNode *x;
for (x=toks.next;
x!=&toks;
x=x->next) {
show_token(x);
}
}
/*++++++++++++++++++++++++++++++
Take an inclusive range of nodes and return a text string formed from them.
Nodes should be primitive lexer tokens - can extend this later.
++++++++++++++++++++++++++++++*/
#define DEFECTIVE_ERASURE "<Defective erasure>"
char *
build_string_from_nodes(TreeNode *start, TreeNode *end)
{
char *result;
TreeNode *y;
int len;
len = 0;
for (y=start; ; y = y->next) {
switch (y->type) {
case N_GARBAGE:
len += strlen(y->data.garbage.word);
break;
case N_CMAVO:
len += strlen(cmavo_table[y->data.cmavo.code].cmavo);
break;
case N_BRIVLA:
len += strlen(y->data.brivla.word);
break;
case N_CMENE:
len += strlen(y->data.cmene.word);
break;
case N_ZOI:
len += 6 + strlen(y->data.zoi.text);
break;
case N_ZO:
len += 3 + strlen(y->data.zo.text);
break;
case N_ZEI:
/* Not particularly efficient, the strings get built again later for now! */
len += strlen(y->data.zei.sep_with_zei);
break;
case N_BROKEN_ERASURE:
len += strlen(DEFECTIVE_ERASURE);
break;
case N_NONTERM:
case N_MARKER:
case N_LOhU:
case N_BU:
assert(0);
break;
}
if (y == end) {
break;
} else {
len++; /* allow for a space between intermediate terms */
}
}
result = (char *) Malloc(1+len);
result[0] = 0;
for (y=start; ; y = y->next) {
switch (y->type) {
case N_GARBAGE:
strcat(result, y->data.garbage.word);
break;
case N_CMAVO:
strcat(result, cmavo_table[y->data.cmavo.code].cmavo);
break;
case N_BRIVLA:
strcat(result, y->data.brivla.word);
break;
case N_CMENE:
strcat(result, y->data.cmene.word);
break;
case N_ZOI:
strcat(result, "zoi+\"");
strcat(result, y->data.zoi.text);
strcat(result, "\"");
break;
case N_ZO:
strcat(result, "zo+");
strcat(result, y->data.zo.text);
break;
case N_ZEI:
strcat(result, y->data.zei.sep_with_zei);
break;
case N_BROKEN_ERASURE:
strcat(result, DEFECTIVE_ERASURE);
break;
case N_NONTERM:
case N_MARKER:
case N_LOhU:
case N_BU:
assert(0);
break;
}
if (y == end) {
break;
} else {
strcat(result, " ");
}
}
return result;
}
/*++++++++++++++++++++++++++++++++++++++
Convert a single treenode to a string representation. This is at its most
useful for recursively expanding zei nodes.
++++++++++++++++++++++++++++++++++++++*/
char *
build_string_from_node(TreeNode *the_node)
{
return build_string_from_nodes(the_node, the_node);
}
/*++++++++++++++++++++++++++++++++++++++
zo processing
++++++++++++++++++++++++++++++++++++++*/
static void
handle_zo(void)
{
TreeNode *x, *y, *nt;
for (x = toks.next;
x != &toks;
x = x->next) {
if ((x->type == N_CMAVO) &&
cmavo_table[x->data.cmavo.code].selmao == ZO) {
y = x->next;
if (y == &toks) {
fprintf(stderr, "Cannot have ZO as the last token in the text\n");
exit(1);
}
nt = new_node();
nt->type = N_ZO;
switch (y->type) {
case N_CMAVO:
nt->data.zo.text = new_string(cmavo_table[y->data.cmavo.code].cmavo);
break;
case N_GARBAGE:
nt->data.zo.text = new_string(y->data.garbage.word);
break;
case N_BRIVLA:
nt->data.zo.text = new_string(y->data.brivla.word);
break;
case N_CMENE:
nt->data.zo.text = new_string(y->data.cmene.word);
break;
case N_ZOI:
nt->data.zo.text = new_string(y->data.zoi.text);
break;
case N_NONTERM:
case N_ZO:
case N_LOhU:
case N_MARKER:
case N_BU:
case N_ZEI:
case N_BROKEN_ERASURE:
assert(0);
break;
}
x->type = nt->type;
x->data = nt->data;
y->next->prev = x;
x->next = y->next;
}
}
}
/*++++++++++++++++++++++++++++++++++++++
lo'u processing
++++++++++++++++++++++++++++++++++++++*/
static void
handle_lohu(void)
{
TreeNode *x, *y;
TreeNode *start, *end, *term;
for (x = toks.next;
x != &toks;
x = x->next) {
if (x->type == N_CMAVO &&
x->data.cmavo.selmao == LOhU) {
y = start = x->next;
do {
if (y == &toks) {
fprintf(stderr, "Unterminated LOhU .. LEhU construction\n");
exit(1);
}
if (y->type == N_CMAVO &&
y->data.cmavo.selmao == LEhU) {
term = y;
end = term->prev;
break;
}
y = y->next;
} while (1);
x->type = N_LOhU;
x->data.lohu.text = build_string_from_nodes(start, end);
term->next->prev = x;
x->next = term->next;
/* Lose nodes in range start .. end */
}
}
}
/*++++++++++++++++++++++++++++++
ZEI processing.
++++++++++++++++++++++++++++++*/
static inline int
is_zei(TreeNode *x)
{
return ((x->type == N_CMAVO) &&
(x->data.cmavo.selmao == ZEI));
}
static void
handle_zei(void)
{
TreeNode *x, *nt;
int first = 1;
char **components;
int total_comp_length;
for (x = toks.next;
x != &toks;
x = nt, first=0) {
nt = x->next; /* As a default */
if (is_zei(x)) {
int count = 1;
int i;
TreeNode *y, *z, *left, *right;
if (first) {
fprintf(stderr, "Cannot have 'zei' at the start of the text\n");
had_bad_tokens = 1; /* flag back to main */
nt = x->next;
continue;
}
z = x; /* Points to a zei */
do {
y = z->next;
if (y == &toks) {
fprintf(stderr, "Cannot have 'zei' at the end of the text\n");
had_bad_tokens = 1; /* flag back to main */
nt = x->next;
goto done_this_block;
}
count++;
z = y->next;
} while ((z != &toks) && is_zei(z));
x->type = N_ZEI;
x->data.zei.nchildren = count;
x->data.zei.children = new_array(TreeNode *, count);
components = new_array(char *, count);
total_comp_length = 0;
for (i = 0, y = x->prev;
i < count;
i++, y = y->next->next) {
x->data.zei.children[i] = y;
components[i] = build_string_from_node(y);
total_comp_length += strlen(components[i]);
}
x->data.zei.sep_with_plus = new_array(char, total_comp_length + (count - 1) + 1);
x->data.zei.sep_with_zei = new_array(char, total_comp_length + (count - 1) * 5 + 1);
x->data.zei.sep_with_plus[0] = 0;
x->data.zei.sep_with_zei[0] = 0;
for (i=0; i<count; i++) {
if (i > 0) {
strcat(x->data.zei.sep_with_plus, "+");
strcat(x->data.zei.sep_with_zei, " zei ");
}
strcat(x->data.zei.sep_with_plus, components[i]);
strcat(x->data.zei.sep_with_zei, components[i]);
Free(components[i]);
}
Free(components);
left = x->prev->prev;
right = y->prev;
/* Fix up pointers to take collapsed tokens out of the sequence */
right->prev = x;
left->next = x;
x->next = right;
x->prev = left;
nt = right;
}
done_this_block:
(void) 0;
}
}
/*++++++++++++++++++++++++++++++++++++++
BAhE processing - look for any BAhE, and absorb it into the token
that follows.
++++++++++++++++++++++++++++++++++++++*/
static void
handle_bahe(void)
{
TreeNode *x, *y, *nt;
for (x = toks.next;
x != &toks;
x = nt) {
if (x->type == N_CMAVO &&
x->data.cmavo.selmao == BAhE) {
y = x->next;
nt = x->next;
if ((y != &toks) &&
!(y->type == N_CMAVO && y->data.cmavo.selmao == FAhO)) {
y->bahe = x;
/* Unlink x from the main token list */
x->prev->next = y;
y->prev = x->prev;
} else {
/* BAhE at end of text (EOF or FAhO) is an error */
}
} else {
nt = x->next;
}
}
}
/*++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++*/
static void
handle_bu(void)
{
TreeNode *x, *y, *nt;
for (x = toks.next;
x != &toks;
x = nt) {
nt = x->next;
if (x->type == N_CMAVO &&
x->data.cmavo.selmao == BU) {
y = x->prev;
x->type = N_BU;
switch (y->type) {
case N_CMAVO:
x->data.bu.word = new_string(cmavo_table[y->data.cmavo.code].cmavo);
break;
case N_GARBAGE:
x->data.bu.word = new_string(y->data.garbage.word);
break;
case N_BRIVLA:
x->data.bu.word = new_string(y->data.brivla.word);
break;
case N_CMENE:
x->data.bu.word = new_string(y->data.cmene.word);
break;
case N_ZOI:
x->data.bu.word = new_string(y->data.zoi.text);
break;
case N_ZO:
{
int len = strlen(y->data.zo.text);
len += 3;
x->data.bu.word = new_array(char, len);
strcpy(x->data.bu.word, "zo");
strcat(x->data.bu.word, y->data.zo.text);
}
break;
case N_ZEI:
x->data.bu.word = build_string_from_node(y);
break;
case N_BU:
{
int len = strlen(y->data.bu.word);
len += 4;
x->data.bu.word = new_array(char, len);
strcpy(x->data.bu.word, y->data.bu.word);
strcat(x->data.bu.word, ".bu");
}
break;
case N_LOhU:
{
int len = strlen(y->data.lohu.text);
len += 11;
x->data.bu.word = new_array(char, len);
strcpy(x->data.bu.word, "lo'u-");
strcat(x->data.bu.word, y->data.lohu.text);
strcat(x->data.bu.word, "-le'u");
}
break;
case N_BROKEN_ERASURE:
x->data.bu.word = new_string(DEFECTIVE_ERASURE);
break;
case N_NONTERM:
case N_MARKER:
assert(0);
break;
}
/* Unlink y from the chain */
y->prev->next = x;
x->prev = y->prev;
free_node(y);
}
}
}
/*++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++*/
static int
is_indicator_cmavo(TreeNode *x)
{
if (x->type == N_CMAVO) {
if ((x->data.cmavo.selmao == UI) ||
(x->data.cmavo.selmao == CAI) ||
(x->data.cmavo.selmao == Y) ||
(x->data.cmavo.selmao == DAhO) ||
(x->data.cmavo.selmao == FUhE) ||
(x->data.cmavo.selmao == FUhO)) {
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
/*++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++*/
static int
is_fuhe(TreeNode *x)
{
if (x->type == N_CMAVO &&
x->data.cmavo.selmao == FUhE) {
return 1;
} else {
return 0;
}
}
/*++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++*/
static void
advance_indicator(TreeNode **x)
{
while (is_indicator_cmavo(*x)) {
(*x) = (*x)->next;
}
}
/*++++++++++++++++++++++++++++++++++++++
Go through looking for all UI and CAI cmavo. If a NAI immediately
follows, pull the NAI onto the 'parent' cmavo as a property. If a
CAI follows UI [NAI], pull that onto the UI as a property too. If a
NAI follows the CAI, discard it and give a warning - I don't know
what that's supposed to mean at the moment.
++++++++++++++++++++++++++++++++++++++*/
static void
pair_off_indicator_suffixes(void)
{
TreeNode *x, *y, *z, *w, *v, *nt;
for (x = toks.next;
x != &toks;
x = nt) {
y = x->next;
if (is_indicator_cmavo(x)) {
if ((y != &toks) &&
(y->type == N_CMAVO) &&
(y->data.cmavo.selmao == NAI)) {
z = y->next;
/* Create the property, we aren't interested in its body so
void it */
(void) prop_neg_indicator(x, YES);
/* Drop the y node out */
x->next = z;
z->prev = x;
/* y just dropped altogether */
nt = z;
} else {
nt = y;
}
z = nt;
/* See if CAI follows */
if ((z != &toks) &&
(z->type == N_CMAVO) &&
(z->data.cmavo.selmao == CAI)) {
char *tok;
XCaiIndicator *xci;
xci = prop_cai_indicator(x, YES);
tok = cmavo_table[z->data.cmavo.code].cmavo;
if (!strcmp(tok, "cai")) {
xci->code = CC_CAI;
} else if (!strcmp(tok, "sai")) {
xci->code = CC_SAI;
} else if (!strcmp(tok, "ru'e")) {
xci->code = CC_RUhE;
} else if (!strcmp(tok, "cu'i")) {
xci->code = CC_CUhI;
} else if (!strcmp(tok, "pei")) {
xci->code = CC_PEI;
} else {
abort();
}
w = z->next;
/* Drop z */
x->next = w;
w->prev = x;
nt = w;
/* Handle NAI coming after CAI */
if ((w != &toks) &&
(w->type == N_CMAVO) &&
(w->data.cmavo.selmao == NAI)) {
switch (xci->code) {
case CC_CAI:
xci->code = CC_CAINAI;
break;
case CC_SAI:
xci->code = CC_SAINAI;
break;
case CC_RUhE:
xci->code = CC_RUhENAI;
break;
case CC_CUhI:
/* Nothing to do, this is the neutral case so you
can't invert it */
break;
case CC_PEI:
xci->code = CC_PEINAI;
break;
default:
break;
}
/* Drop w */
v = w->next;
x->next = v;
v->prev = x;
nt = v;
}
}
} else {
nt = y;
}
}
}
/*++++++++++++++++++++++++++++++++++++++
Indicators processing.
Look for any sequence matching the indicators non-terminal, and
attach to the preceding node.
++++++++++++++++++++++++++++++++++++++*/
static void
handle_indicators(void)
{
TreeNode *x, *nt, *target, *start, *end;
enum {XX_BEGIN, XX_AFTER_INITIAL_FUHE, XX_AFTER_INITIAL_INDICATOR, XX_OTHER} state = XX_BEGIN;
pair_off_indicator_suffixes();
for (x = toks.next;
x != &toks;
x = nt) {
switch(state) {
case XX_BEGIN:
if (is_fuhe(x)) {
state = XX_AFTER_INITIAL_FUHE;
} else if (is_indicator_cmavo(x)) {
state = XX_AFTER_INITIAL_INDICATOR;
} else {
state = XX_OTHER;
}
nt = x->next;
break;
case XX_AFTER_INITIAL_FUHE:
if (is_indicator_cmavo(x)) {
state = XX_AFTER_INITIAL_INDICATOR;
} else {
state = XX_OTHER;
}
nt = x->next;
break;
case XX_AFTER_INITIAL_INDICATOR:
if (!is_indicator_cmavo(x)) {
state = XX_OTHER;
}
nt = x->next;
break;
case XX_OTHER:
if (is_indicator_cmavo(x)) {
target = x->prev;
start = x;
advance_indicator(&x); /* So x now looks at the first token
beyond the end of the indicator string */
nt = x;
end = nt->prev;
/* Unlink the indicator string from the main token list .. */
nt->prev = target;
target->next = nt;
/* .. and link it onto the indicators list of the target */
start->prev = end->next = (TreeNode *) &target->ui_next;
target->ui_next = start;
target->ui_prev = end;
} else {
nt = x->next;
}
break;
}
}
}
/*++++++++++++++++++++++++++++++++++++++
Called to preprocess the token stream. This involves processing the
various erasure and quoting constructions, as well as marking certain
tokens that need to cope with more than 1 token lookahead for the
parser to work (notably things were KE and BO come several tokens
later and are required to disambiguate constructs).
++++++++++++++++++++++++++++++++++++++*/
void
preprocess_tokens(void)
{
/* 2a. Look for 'zoi'. This is done in lex1.c, before each word
gets split into tokens. */
/* 2b. Look for 'zo' and group following word into it. */
handle_zo();
/* 2c. Look for lo'u ... le'u and eliminate internal data */
handle_lohu();
/* 2d. Done. */
/* 2e. Remove any token followed by SI and the SI itself. */
/* 2f. SA - too vague, don't implement */
/* 2g. Remove anything from SU backwards up to NIhO, LU, TUhE, TO inclusive */
do_erasures(&toks);
handle_zei();
handle_bahe();
handle_bu();
handle_indicators();
categorize_tokens(&toks);
return;
}
/*+ External variable referenced by parser. +*/
extern TreeNode *yylval;
extern YYLTYPE yylloc;
/*++++++++++++++++++++++++++++++
Discard tokens after a parse error. Advance to one of a designated
set of tokens or to one of a fall-back set, whichever comes first.
Unfortunately, it is practically impossible to use bison's automatic
token discarding mechanism. To make that work, you need to have rules
of the form
nonterm : thing TERMINATOR
so that you can enhance this to
nonterm : thing TERMINATOR
| error TERMINATOR
However, the Lojban grammar allows just about every terminator to be
elided. Having 'error' at the end of a rule causes Bison to reduce
the rule, and then to just keep reducing to the outermost rule
because the next (offending) token can usually not be shifted in any
of the intermediate contexts. This is obviously useless - you want
to reject the smallest enclosing block of material around the error
and try to resume parsing at the next sentence of whatever.
The 'code' argument to this allows the elidable terminator to be
supplied, so that it can be sought for if present and parsing can
resume ASAP.
++++++++++++++++++++++++++++++*/
void
error_advance(int code)
{
next_tok = next_tok->next;
do {
if ((next_tok == &toks) || /* End of file */
((next_tok->type == N_CMAVO || next_tok->type == N_MARKER) &&
((next_tok->data.cmavo.selmao == I) ||
(next_tok->data.cmavo.selmao == PRIVATE_I_BO) ||
(next_tok->data.cmavo.selmao == NIhO) ||
(next_tok->data.cmavo.selmao == LIhU) ||
(next_tok->data.cmavo.selmao == TOI) ||
(next_tok->data.cmavo.selmao == TUhU) ||
(next_tok->data.cmavo.selmao == FAhO) ||
((code != 0) && (next_tok->data.cmavo.selmao == code))))) {
break;
}
next_tok = next_tok->next;
} while (1);
next_tok = next_tok->prev;
}