-
Notifications
You must be signed in to change notification settings - Fork 7
/
trnod.h
1423 lines (1086 loc) · 35.5 KB
/
trnod.h
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
#ifndef __TRNOD_HPP__
#define __TRNOD_HPP__
#include "tpexpr.h"
enum {
ctx_program, // program
ctx_module, // list of declaration
ctx_object, // list of object components
ctx_value, // value of expression
ctx_rvalue, // rvalue part of assignment
ctx_lvalue, // lvalue part of assignment
ctx_lvalarray, // array element is used as lvalue
ctx_procptr, // pointer to procedure
ctx_apply, // functions is applied to arguments
ctx_varpar, // parameter passed by reference
ctx_valpar, // parameter passed by value
ctx_statement, // statement
ctx_condition, // result is used in condition expression
ctx_component, // type od array component
ctx_block, // block context
ctx_access, // result is used in access to record component operation
ctx_array, // result is used as base value in index expression
ctx_variant, // variant part of record
ctx_reftyp, // reference definition type
ctx_record, // initializer for record constant
ctx_union, // record with only variant component
ctx_constant, // constant expression
ctx_toascii // convertion of number to string
};
class decl_node;
class expr_node;
class block_node;
class compound_node;
class expr_group_node;
class node : public heap_object {
public:
token* f_tkn; /* First token */
token* l_tkn; /* Last token */
void force_semicolon();
void swallow_semicolon();
node() { f_tkn = l_tkn = NULL; }
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class token_list : public heap_object {
public:
token* ident;
symbol* var;
token_list* next;
token_list(token* id, token_list* chain = NULL) {
ident = id;
next = chain;
}
};
//=============================================================================
// Program level grammar:
// program ::= PROGRAM ident [ '(' parameter_list ')' ] block '.'
// parameter_list ::= ident { ',' ident }
// block ::= decl_part_list compoundst
// decl_part_list ::= { decl_part }
// decl_part ::= label_decl_part | const_def_part | type_def_part
// | var_decl_part | proc_decl proc_fwd_decl
//=============================================================================
class import_list_node : public node {
public:
token* lpar;
token_list* params;
token* rpar;
import_list_node(token* lpar, token_list* params, token* rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class program_node : public node {
public:
token* program;
token* name;
import_list_node* params;
token* semi;
block_node* block;
token* end; // '.'
proc_tp* main;
program_node(token* program, token* name, import_list_node* params,
token* semi, block_node* body, token* end);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class module_node : public node {
public:
token* program;
token* name;
import_list_node* params;
token* semi;
decl_node* decls;
token* t_dot;
module_node(token* program, token* name, import_list_node* params,
token* semi, decl_node* decls, token* t_dot);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class unit_node : public node {
public:
token* t_unit;
token* t_name;
token* t_semi;
token* t_interface;
decl_node* unit_decl;
token* t_implementation;
decl_node* unit_def;
compound_node* initializer;
token* t_end;
token* t_dot; // '.'
proc_tp* main;
static bool interface_part; // translate interface part of module
static char* unit_name;
unit_node(token* t_unit, token* t_name, token* t_semi, token* t_interface,
decl_node* unit_decl, token* t_implementation,
decl_node* unit_def, compound_node* initializer,
token* t_end, token* t_dot);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class block_node : public node {
public:
decl_node* decls;
compound_node* body;
block_node(decl_node* decls, compound_node* body);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//=============================================================================
// Statement level grammar
// statement ::= compoundst | assignmentst | gotost | switchst | ifst
// | forst | whilest | repeatst | procst | returnst
// | withst | labelst | emtyst | writest | readst
// sequence ::= statement { ';' statement }
// compoundst ::= BEGIN sequence END
// assignmentst ::= expr ':=' expr
// gotost ::= GOTO ident
// labelst ::= ident ':'
// switchst ::= CASE expr OF case_list END
// case_list ::= case_list_elem { ';' case-list-elem } [ ';' ]
// case_list_elem ::= expr_list ':' statement | OTHERWISE statement
// ifst ::= IF expr THEN statement [ELSE statement]
// forst ::= FOR identifier := expr (TO | DOWNTO) expr DO statement
// repeatst ::= REPEAT sequence UNTIL expr
// whilest ::= WHILE expr DO statement
// withst ::= WITH expr_list DO statement
// procst ::= ident [ expr_group ]
// writest ::= (WRITE | WRITELN) [ write_list ]
// readst ::= (READ | READLN) [ expr_group ]
// returnst ::= RETURN
// emptyst ::=
//=============================================================================
class stmt_node : public node {
public:
stmt_node* next;
stmt_node() : next(NULL) {}
virtual bool is_compound();
};
class label_node : public stmt_node {
public:
token* ident; /* label name */
token* colon; /* colon */
stmt_node* stmt;
label_node(token* ident, token* colon, stmt_node* stmt);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class with_node : public stmt_node {
public:
token* t_with;
expr_node* ptrs;
token* t_do;
stmt_node* body;
int nested_counter;
static int nested;
with_node(token* t_with, expr_node* ptrs, token* t_do, stmt_node* body);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class pcall_node : public stmt_node {
public:
expr_node* fcall;
pcall_node(expr_node* fcall);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class read_node : public stmt_node {
public:
token* t_read;
expr_group_node* params;
read_node(token* t_read, expr_group_node* params = NULL);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class write_list_node;
class write_node : public stmt_node {
public:
token* t_write;
write_list_node* params;
write_node(token* t_write, write_list_node* params = NULL);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class compound_node : public stmt_node {
public:
token *t_begin, *t_end;
stmt_node* body;
compound_node(token* t_begin, stmt_node* body, token* t_end);
virtual void attrib(int ctx);
virtual void translate(int ctx);
virtual bool is_compound();
};
class assign_node : public stmt_node {
public:
expr_node* lval;
token* assign;
expr_node* rval;
static assign_node* stmt;
assign_node(expr_node* lval, token* assign, expr_node* rval);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class goto_node : public stmt_node {
public:
token* t_goto;
token* t_label;
goto_node(token* t_goto, token* t_label);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class case_node : public node {
public:
case_node* next;
expr_node* list;
token* coln; // ':'
stmt_node* stmt;
case_node(expr_node*, token* coln, stmt_node* stmt);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class switch_node : public stmt_node {
public:
token *t_case, *t_of;
expr_node* expr;
case_node* cases;
token* t_end;
switch_node(token* t_case, expr_node* expr, token* t_of, case_node* cases,
token* t_end);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class if_node : public stmt_node {
public:
expr_node* expr;
stmt_node* alt1;
stmt_node* alt2;
token *t_if, *t_then, *t_else;
if_node(token* t_if, expr_node* expr, token* t_then, stmt_node* alt1,
token* t_else = NULL, stmt_node* alt2 = NULL);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class for_node : public stmt_node {
public:
token *t_for, *t_ident, *t_asg, *t_to, *t_do;
expr_node *from, *till;
stmt_node *body;
symbol *var;
for_node(token* t_for, token* t_ident, token* t_asg, expr_node* from,
token* t_to, expr_node* till, token* t_do, stmt_node* body);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class while_node : public stmt_node {
public:
token *t_while, *t_do;
expr_node *expr;
stmt_node *body;
while_node(token* t_while, expr_node* expr, token* t_do, stmt_node* body);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class repeat_node : public stmt_node {
public:
token *t_repeat, *t_until;
stmt_node *body;
expr_node *expr;
repeat_node(token* t_repeat, stmt_node* body, token* t_until, expr_node* expr);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class return_node : public stmt_node {
public:
token *t_return;
return_node(token* t_return);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class empty_node : public stmt_node {
public:
token* last;
empty_node(token* last);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//=============================================================================
// Expression level syntax:
// constant ::= integer | real | string | set
// set_elem ::= expr | expr '..' expr
// set ::= '[' set_elem { ',' set_elem } ']'
// expr_group ::= '(' expr_list ')
// expr_list ::= expr { ',' expr } ')'
// primary ::= '(' expr ')' | literal | call_expr | ident
// | deref_expr | idx_expr | access_expr | set_constant
// access_expr ::= expr '.' ident
// deref_expr ::= expr '^'
// idx_expr ::= expr '[' expr_list ']'
// call_expr ::= expr [ expr_group ]
// binary ::= expresion op expr
// unary ::= op expr
// expr ::= primary | unary | binary
// write_list ::= '(' write_param { ',' write_param } ')'
// write_param ::= expr [ ':' constant [ ':' constant ] ]
//=============================================================================
// Values for expression flags
enum {
tn_is_const = 0x01, // constant integer expression
tn_is_literal = 0x02 // expression is literal (immediate constant)
};
//-----------------------------------------------------------------------------
// Values for expression tags
enum {
tn_add, // addition
tn_sub, // subtraction
tn_mod, // modulo
tn_mul, // multiplication
tn_div, // division with truncation of the result
tn_divr, // division with real result
tn_plus, // unary plus
tn_minus, // unary minus
tn_deref, // dereferencing pointer
tn_filevar, // dereferencing file variable
tn_address, // dereference operation eaten by getting address (&*x)
tn_access, // access to component of record
tn_ref, // reference to variable: &v
tn_index, // indiexation in array
tn_in, // in set predicat
tn_eq, // comparison operators
tn_ne, //
tn_gt, //
tn_ge, //
tn_lt, //
tn_le, //
tn_let, // =
tn_letadd, // +=
tn_letsub, // -=
tn_letmul, // *=
tn_letdiv, // /=
tn_letshl, // <<=
tn_letshr, // >>=
tn_letand, // &=
tn_letor, // |=
tn_binand, // &
tn_binor, // |
tn_binnot, // ~
tn_and, // logical(bit) AND
tn_shr, // shift right
tn_shl, // shift left
tn_not, // logical(bit) NOT
tn_or, // logical(bit) OR
tn_xor, // bit eXclusive-OR
tn_atom, // atom expresion (variable)
tn_self, // atom expresion (variable)
tn_intnum, // integer constant
tn_realnum, // real constant
tn_string, // string constant
tn_char, // character constant
tn_set, // set of elements
tn_group, // group of expressions in braces
tn_fcall, // function call
tn_loophole, // type conversion
tn_skip, // skipped optional positional parameter
tn_wrp, // write parameter
tn_retarr, // result of function is assigned to array
tn_case_range, // case items range
tn_record_const // record constant
};
class expr_node : public node {
public:
expr_node* next;
char tag;
char parent_tag;
char flags;
int value; // value of constant expression
tpexpr* type;
bool is_const_literal() {
return (flags & (tn_is_const|tn_is_literal)) == (tn_is_const|tn_is_literal);
}
bool is_parameter();
expr_node(int expr_tag, int expr_flags = 0) {
tag = expr_tag;
parent_tag = tn_group;
type = NULL;
flags = expr_flags;
next = NULL;
}
};
//=============================================================================
class atom_expr_node : public expr_node {
public:
token *tkn;
symbol *var;
symbol *with; // variable stored result of 'with' expression
char *temp; // temporary variable for returning array
atom_expr_node(token* tkn);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class literal_node : public expr_node {
public:
token* value_tkn;
literal_node(token* value_tkn, int tag);
};
class integer_node : public literal_node {
public:
int radix;
integer_node(token* value_str);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class real_node : public literal_node {
public:
real_node(token* value_str);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class string_node : public literal_node {
public:
string_node(token* value_str);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class address_node : public expr_node {
expr_node* var;
token* t_adr;
public:
address_node(token* t_adr, expr_node* var);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class case_range_node : public expr_node {
public:
expr_node* from;
token* t_range;
expr_node* to;
virtual void attrib(int ctx);
virtual void translate(int ctx);
case_range_node(expr_node* from, token* t_range, expr_node* to);
};
class set_item_node : public node {
public:
set_item_node* next;
tpexpr* type;
set_item_node() { next = NULL; }
};
class set_elem_node : public set_item_node {
public:
expr_node* item;
set_elem_node(expr_node* item);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class set_range_node : public set_item_node {
public:
expr_node* low;
token* dots; // '..'
expr_node* high;
set_range_node(expr_node* low, token* dots, expr_node* high);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class set_node : public expr_node {
public:
token* t_lbr; // '['
token* t_rbr; // ']'
set_item_node* items;
set_node(token* t_lbr, set_item_node* items, token* t_rbr);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class idx_expr_node : public expr_node {
public:
expr_node* arr;
token* t_lbr; // '['
token* t_rbr; // ']'
expr_node* indices;
idx_expr_node(expr_node* arr, token* t_lbr, expr_node* indices,
token* t_rbr);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class deref_expr_node : public expr_node {
public:
token* op; // '^'
expr_node* ptr;
deref_expr_node(expr_node* ptr, token* op);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class access_expr_node : public expr_node {
public:
expr_node* rec;
token* pnt; // '.'
token* field;
symbol* recfld;
access_expr_node(expr_node* rec, token* pnt, token* field);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class op_node : public expr_node {
public:
token* op;
expr_node* left;
expr_node* right;
expr_node* parent;
op_node(int tag, expr_node* left, token* op, expr_node* right = NULL);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class fcall_node : public expr_node {
public:
expr_node *fptr;
token *lpar;
expr_node *args;
token *rpar;
char *temp; // temporary variable used for returning array
fcall_node(expr_node* fptr, token* lpar, expr_node* args,
token* rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class skipped_node : public expr_node {
public:
token* comma;
skipped_node(token* comma);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class tpd_node;
class loophole_node : public expr_node {
public:
token *t_loophole;
token *t_lpar;
tpd_node *tpd;
token *t_comma;
expr_node *expr;
token *t_rpar;
loophole_node(token* t_loophole, token* t_lpar, tpd_node* tpd, token* t_comma,
expr_node *expr, token* t_rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class expr_group_node : public expr_node {
public:
token *lpar;
token *rpar;
expr_node *expr;
int ctx;
expr_group_node(token* lpar, expr_node* expr, token* rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class field_init_node : public node {
public:
field_init_node* next;
token* t_field;
token* t_coln;
expr_node* value;
field_init_node(token* t_field, token* t_coln, expr_node* value);
void attrib(tpexpr* record_type);
void translate(int);
};
class record_constant_node : public expr_node {
public:
token *lpar;
token *rpar;
field_init_node *flist;
record_constant_node(token* lpar, field_init_node* flist, token* rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class write_param_node : public expr_node {
public:
expr_node* val;
token* t_coln1;
expr_node* width;
token* t_coln2;
expr_node* prec;
write_param_node(expr_node* val,
token* t_coln1 = NULL, expr_node* width = NULL,
token* t_coln2 = NULL, expr_node* prec = NULL);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class write_list_node : public node {
public:
token *lpar;
token *rpar;
write_param_node *vals;
write_list_node(token* lpar, write_param_node* vals, token* rpar);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//=============================================================================
// Declaration syntax:
// label_decl_part ::= [ LABEL ident { ',' ident } ';' ]
// const_def_part ::= [ CONST const_def ';' { const_def ';' } ]
// type_def_part ::= [ TYPE type_def ';' { type_def ';' } ]
// var_decl_part ::= [ VAR var_decls ';' ]
// proc_fwd_decl ::= proc_decl ';' ident ';'
// proc_decl ::= (PROCEDURE | FUNCTION) ident [ formal_params ] [ ':' type ]
// proc_def ::= proc_decl ';' body ';'
// formal_params ::= '(' formal_param { ';' formal_param } ')'
// formal_param ::= var_decl | proc_decl
// const_def ::= ident '=' expr
// type_def ::= ident '=' type
// var_decls ::= var_decl { ';' var_decl }
// var_decl ::= ident { ',' ident } ':' type
// type ::= simple_type | array_type | record_type | set_type |
// file_type | pointer_type | subrange_type | enum_type
// subrange_type ::= '[' expr '..' expr ']'
// enum_type ::= '(' expr { ',' expr } ')'
// pointer_type ::= '^' type
// file_type ::= FILE OF type_denoter
// set_type ::= SET OF type_denoter
// record_type ::= RECORD field_list END
// field_list ::= [ (fixed_part [';' variant_part] | variant_part) [;] ]
// fixed_part ::= var_decls
// variant_part ::= CASE selector OF
// variant { ';' variant }
// selector ::= [ tag_field ':' ] tag_type
// variant ::= constant { ',' constant } ':' '(' field_list ')'
// simple_type ::= ident
// array_type ::= ARRAY '[' index ']' OF type
// index ::= conformant_index | fixed_index
// conformant_index ::= var_decls
// fixed_index ::= range { ',' range }
// range ::= expr '..' expr | type
//=============================================================================
class decl_node : public node {
public:
decl_node* next;
enum {
is_toplevel = 1, // The declaration is at the top level of module
is_argument = 2, // The declaration is in the argument list of
// procedure
is_static = 4, // keyword 'static' must be prepended before decl
is_extern = 8,
is_member = 16
};
int attr;
decl_node() { next = NULL; }
};
//
// labels declaration
//
class label_decl_part_node : public decl_node {
public:
token* t_label;
token* t_semi; // ';'
token_list* labels;
label_decl_part_node(token* t_label, token_list* label_list,
token* t_semi);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//
// Constant definition
//
class const_def_node : public decl_node {
public:
token* ident;
token* equal;
expr_node* constant;
symbol* sym;
static const_def_node* enumeration;
const_def_node(token* ident, token* equal, expr_node* value);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class typed_const_def_node : public const_def_node {
public:
token* coln;
tpd_node* tpd;
typed_const_def_node(token* ident, token* coln, tpd_node* tpd,
token* equal, expr_node* constant);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class const_def_part_node : public decl_node {
public:
token* t_const;
const_def_node* list;
const_def_part_node(token* t_const, const_def_node* list);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//
// Type definition
//
class type_def_node : public decl_node {
public:
token* ident;
token* equal;
tpd_node* tpd;
symbol* sym;
type_def_node(token* ident, token* equal, tpd_node* tpd);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class type_def_part_node : public decl_node {
public:
token* t_type;
type_def_node* types;
type_def_part_node(token* t_type, type_def_node* list);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//
// Variable declaration
//
class var_decl_node : public decl_node {
public:
token_list* vars;
token* coln; // ':'
tpd_node* tpd;
token* scope;
var_decl_node(token_list* vars, token* coln, tpd_node* tpd);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class var_decl_part_node : public decl_node {
public:
token* t_var;
var_decl_node* vars;
var_decl_part_node(token* t_var, var_decl_node* vars);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
class var_origin_decl_node : public decl_node {
public:
token *t_ident;
token *t_origin;
expr_node *addr;
token *t_colon;
tpd_node *tpd;
symbol *sym;
tpexpr *type;
var_origin_decl_node(token* t_ident, token* t_origin,
expr_node *addr, token* t_colon, tpd_node *tpd);
virtual void attrib(int ctx);
virtual void translate(int ctx);
};
//
// Procedures and functions declarations and definition
//
class param_list_node : public node {
public:
token *lpar, *rpar;
decl_node *params;
param_list_node(token* lpar, decl_node* params, token* rpar);