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
|
/* l2xacts.c Grammer actions for l2x */
/* 6/96 replaced myprint(tag) by tag_print(tag) */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifndef STRTYPES_H
#include "strtypes.h"
#endif
#ifndef L2XCOM_H
#include "l2xcom.h"
#endif
#include "l2xusrlb.h" /* user defined action functions */
#include "l2xlib.h" /* functions and global variables */
#include "l2xytab.h" /* parser communication */
/* functions defined herein */
void default_start_with_opt();
void default_end_start_opt();
void start_it();
void end_it();
void start_section();
void start_list();
void end_list();
void start_with_req();
void action_p_p1();
void action_last_p();
void start_with_opt();
void action_opt_first();
void action_p_opt();
void action_last_opt();
void action_no_param();
void do_start_pc();
void do_end_pc();
int not_ok_sym();
/* lexer/parser communication */
extern int opt_param;
/* 6/96 changed int pos to PSENTRY pos */
/* DEFAULT_START_WITH_OPT default action before an initial opt param */
void default_start_with_opt(pos)
PSENTRY pos; /* ptr to sym entry */
{
if (not_ok_sym(pos)) {
return;
}
tag_print(get_opttag_t(pos)); /* print start tag for opt param */
set_print(get_opt_print(pos)); /* set parameter printing */
opt_param = TRUE; /* processing optional */
} /* end DEFAULT_START_WITH_OPT */
/* DEFAULT_END_START_OPT defaults action after an initial opt param */
void default_end_start_opt(pos)
PSENTRY pos; /* command position in table */
{
if (not_ok_sym(pos)) {
return;
}
opt_param = FALSE; /* not processing optional */
reset_print(); /* set printing on */
tag_print(get_opttag_et(pos)); /* print opt param end tag */
} /* end DEFAULT_END_START_OPT */
/* START_IT starts a grammar rule */
void start_it(pos) /* command position in table */
PSENTRY pos;
{
int ut;
if (not_ok_sym(pos)) {
return;
}
do_start_pc(pos); /* added 6/96 */
ut = get_user_type(pos);
switch (ut) { /* switch on user type */
case SECTIONING: {
start_section(pos);
break;
}
case BEGIN_LIST_ENV: {
start_list(pos);
break;
}
case END_LIST_ENV: {
end_list();
break;
}
}
tag_print(get_t(pos)); /* print command start tag */
} /* end START_IT */
/* END_IT ends a grammar rule */
void end_it(pos) /* position in command table */
PSENTRY pos;
{
int ut;
if (not_ok_sym(pos)) { /* out of range */
return;
}
ut = get_user_type(pos);
switch (ut) { /* switch on user type */
case SECTIONING: { /* end tag printed via start-section */
break;
}
default: {
tag_print(get_et(pos)); /* print command end tag */
break;
}
} /* end switch */
do_end_pc(pos); /* added 6/96 */
} /* end END_IT */
/* START_SECTION sets up sectioning stuff */
void start_section(pos) /* position in command table */
PSENTRY pos;
{
int this_level; /* sectioning level */
if (not_ok_sym(pos)) { /* out of range */
return;
}
this_level = get_level(pos);
close_doc_divs(this_level); /* close prior levels */
current_level = this_level; /* set current level */
set_clause_stack(current_level, get_et(pos) );
} /* end START_SECTION */
/* START_LIST sets up item list stuff */
void start_list(pos) /* position in command table */
PSENTRY pos;
{
if (not_ok_sym(pos)) { /* out of range */
return;
}
/* push tags onto list stack */
set_list_stack(get_item_t(pos), get_item_et(pos),
get_itemopt_t(pos), get_itemopt_et(pos) );
} /* end START_LIST */
/* END_LIST finishes a list environment */
void end_list()
{
if (list_level >= LIST_STACK_SIZE) {
yyerror("Somethings wrong (end_list): overflow");
list_level = LIST_STACK_SIZE - 1;
}
else if (list_level < 0) {
yyerror("Somethings wrong (end_list): underflow");
list_level = 0;
}
else if (num_items[list_level] > 0) { /* close off last item */
tag_print(list_str_stack[list_level]);
}
num_items[list_level] = 0;
list_level--;
} /* end END_LIST */
/* START_WITH_REQ action at start of command with req param */
void start_with_req(pos)
PSENTRY pos; /* command position in table */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
start_it(pos); /* command start action */
tag_print(get_tag_t(pos,1)); /* print start tag for 1st param */
set_print(get_param_print(pos,1)); /* set parameter printing */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_start_with_req(pos);
break;
}
default: { /* should not be here! */
warning("(start_with_req) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end START_WITH_REQ */
/* ACTION_P_P1 action between p'th and p+1'th req params */
void action_p_p1(pos,p)
PSENTRY pos; /* position of command in table */
int p; /* number of p'th parameter */
{
int p1;
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
p1 = p + 1;
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
reset_print(); /* set printing on */
tag_print(get_tag_et(pos,p)); /* print end tag for parameter p */
tag_print(get_tag_t(pos,p1)); /* print start tag for p+1 */
set_print(get_param_print(pos,p1)); /* set parameter printing */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_p_p1(pos,p);
break;
}
default: { /* should not be here! */
warning("(action_p_p1) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_P_P1 */
/* ACTION_LAST_P action after last req parameter */
void action_last_p(pos,p)
PSENTRY pos; /* position of command in table */
int p; /* number of last parameter */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
reset_print();
tag_print(get_tag_et(pos,p)); /* print end tag for parameter p */
end_it(pos); /* final action for command */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_last_p(pos,p);
break;
}
default: { /* should not be here! */
warning("(action_last_p) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_LAST_P */
/* START_WITH_OPT start action for command with optional param */
void start_with_opt(pos)
PSENTRY pos; /* position of command in table */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
start_it(pos); /* command start action */
default_start_with_opt(pos); /* start optional param */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_start_with_opt(pos);
break;
}
default: { /* should not be here! */
warning("(start_with_opt) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end START_WITH_OPT */
/* ACTION_OPT_FIRST action between opt and 1st param */
void action_opt_first(pos)
PSENTRY pos; /* position of command in table */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
default_end_start_opt(pos); /* end opt param */
tag_print(get_tag_t(pos,1)); /* print start tag for 1st param */
set_print(get_param_print(pos,1)); /* set parameter printing */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_opt_first(pos);
break;
}
default: { /* should not be here! */
warning("(action_opt_first) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_OPT_FIRST */
/* ACTION_P_OPT action between param p and opt */
void action_p_opt(pos,p)
PSENTRY pos; /* position of command in table */
int p; /* number of p'th parameter */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
reset_print(); /* set printing on */
tag_print(get_tag_et(pos,p)); /* print end tag for parameter p */
tag_print(get_opttag_t(pos)); /* print start tag for opt param */
set_print(get_opt_print(pos)); /* set parameter printing */
opt_param = TRUE; /* processing optional */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_p_opt(pos,p);
break;
}
default: { /* should not be here! */
warning("(action_p_opt) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_P_OPT */
/* ACTION_LAST_OPT action after last opt param */
void action_last_opt(pos)
PSENTRY pos; /* position of command in table */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
opt_param = FALSE; /* not processing optional */
reset_print();
tag_print(get_opttag_et(pos)); /* print end tag for opt parameter */
end_it(pos); /* final action for command */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_last_opt(pos);
break;
}
default: { /* should not be here! */
warning("(action_last_opt) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_LAST_OPT */
/* ACTION_NO_PARAM command with no params */
void action_no_param(pos)
PSENTRY pos; /* position of command in table */
{
int user_kind; /* user-specified command type */
if (not_ok_sym(pos)) {
return;
}
user_kind = get_user_type(pos);
switch(user_kind) {
case TEX_CHAR: /* the general, non-specials */
case CHAR_COMMAND:
case COMMAND:
case BEGIN_ENV:
case END_ENV:
case BEGIN_LIST_ENV:
case END_LIST_ENV:
case SECTIONING:
case BEGIN_DOCUMENT:
case END_DOCUMENT:
case VCOMMAND:
case BEGIN_VENV:
case END_VENV: {
start_it(pos); /* start action for command */
end_it(pos); /* final action for command */
break;
}
case SPECIAL: /* the specials */
case SPECIAL_BEGIN_ENV:
case SPECIAL_END_ENV:
case SPECIAL_BEGIN_LIST:
case SPECIAL_END_LIST:
case SPECIAL_COMMAND:
case SPECIAL_SECTIONING: {
special_action_no_param(pos);
break;
}
default: { /* should not be here! */
warning("(action_no_param) Unrecognized command type");
break;
}
} /* end switch on user_kind */
} /* end ACTION_NO_PARAM */
/* DO_START_PC sets the starting print control */
void do_start_pc(pos)
PSENTRY pos; /* position in command table */
{
int pc;
if (not_ok_sym(pos)) {
return;
}
pc = get_pc_enum(get_start_pc(pos));
switch (pc) {
case DEFAULT_PRINT : { /* do nothing */
break;
}
case RESET : { /* reset print control */
reset_print();
break;
}
default : { /* anything else changes the setting */
set_print(get_start_pc(pos));
break;
}
} /* end switch */
return;
} /* end DO_START_PC */
/* DO_END_PC sets the ending print control */
void do_end_pc(pos)
PSENTRY pos; /* position in command table */
{
int pc;
if (not_ok_sym(pos)) {
return;
}
pc = get_pc_enum(get_end_pc(pos));
switch (pc) {
case DEFAULT_PRINT : { /* do nothing */
break;
}
case RESET : { /* reset print control */
reset_print();
break;
}
default : { /* anything else changes the setting */
set_print(get_end_pc(pos));
break;
}
} /* end switch */
return;
} /* end DO_END_PC */
/* NOT_OK_SYM returns TRUE if sym entry not found */
int not_ok_sym(pos)
PSENTRY pos;
{
if (pos == NULL) {
yyerror("symbol table entry not found");
return(TRUE);
}
return(FALSE);
} /* end NOT_OK_SYM */
|