annotate lwcc/tree.h @ 536:33a59e232a5b

Fix basic output target to keep lines below 249 characters The line length limiter in the basic output was not properly moving to the next before 249 characters, which is the limit Color Basic can read in an ASCII basic program. Changed the line limiter to 240 from 247 to account for a possible 5 digit number plus a comma and just a bit of extra breathing space.
author William Astle <lost@l-w.ca>
date Thu, 16 Jun 2022 13:55:34 -0600
parents 7e8298f7bc0a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
312
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
2 lwcc/tree.h
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
3
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2013 William Astle
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
5
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
7
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
12
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
17
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
21
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
22 #ifndef tree_h_seen___
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #define tree_h_seen___
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
24
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
25 #include <stdio.h>
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
26
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
27 /* the various node types */
314
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
28 #define NODE_NONE 0 // a node with no type
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
29 #define NODE_PROGRAM 1 // the whole program
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
30 #define NODE_DECL 2 // a declaration
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
31 #define NODE_TYPE_CHAR 3 // a character type
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
32 #define NODE_TYPE_SHORT 4 // short int
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
33 #define NODE_TYPE_INT 5 // integer
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
34 #define NODE_TYPE_LONG 6 // long int
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
35 #define NODE_TYPE_LONGLONG 7 // long long
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
36 #define NODE_IDENT 8 // an identifier of some kind
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
37 #define NODE_TYPE_PTR 9 // a pointer
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
38 #define NODE_TYPE_SCHAR 10 // signed char
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
39 #define NODE_TYPE_UCHAR 11 // unsigned char
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
40 #define NODE_TYPE_USHORT 12 // unsigned short
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
41 #define NODE_TYPE_UINT 13 // unsigned int
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
42 #define NODE_TYPE_ULONG 14 // unsigned long
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
43 #define NODE_TYPE_ULONGLONG 15 // unsigned long long
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
44 #define NODE_TYPE_VOID 16 // void
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
45 #define NODE_TYPE_FLOAT 17 // float
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
46 #define NODE_TYPE_DOUBLE 18 // double
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
47 #define NODE_TYPE_LDOUBLE 19 // long double
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
48 #define NODE_FUNDEF 20 // function definition
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
49 #define NODE_FUNDECL 21 // function declaration
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
50 #define NODE_FUNARGS 22 // list of function args
a3e277c58df9 Checkpoint parser development for lwcc
William Astle <lost@l-w.ca>
parents: 312
diff changeset
51 #define NODE_BLOCK 23 // statement block
498
1bd2d590d734 Rejig parser to eliminate lemon
William Astle <lost@l-w.ca>
parents: 314
diff changeset
52 #define NODE_STMT_RETURN 24 // return statement
1bd2d590d734 Rejig parser to eliminate lemon
William Astle <lost@l-w.ca>
parents: 314
diff changeset
53 #define NODE_CONST_INT 25 // constant integer
501
f3e9732973f1 Add basic integer operations to lwcc
William Astle <lost@l-w.ca>
parents: 498
diff changeset
54 #define NODE_OPER_PLUS 26 // addition
f3e9732973f1 Add basic integer operations to lwcc
William Astle <lost@l-w.ca>
parents: 498
diff changeset
55 #define NODE_OPER_MINUS 27 // subtraction
f3e9732973f1 Add basic integer operations to lwcc
William Astle <lost@l-w.ca>
parents: 498
diff changeset
56 #define NODE_OPER_TIMES 28 // multiplcation
f3e9732973f1 Add basic integer operations to lwcc
William Astle <lost@l-w.ca>
parents: 498
diff changeset
57 #define NODE_OPER_DIVIDE 29 // division
502
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
58 #define NODE_OPER_MOD 30 // modulus
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
59 #define NODE_OPER_COND 31 // ternary conditional
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
60 #define NODE_OPER_FNCALL 32 // function call
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
61 #define NODE_OPER_SUBSCRIPT 33 // array subscript
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
62 #define NODE_OPER_POSTINC 34 // post increment
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
63 #define NODE_OPER_POSTDEC 35 // post decrement
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
64 #define NODE_OPER_PTRMEM 36 // member of pointer operator
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
65 #define NODE_OPER_OBJMEM 37 // member of object operator
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
66 #define NODE_OPER_LSH 38 // left shift
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
67 #define NODE_OPER_RSH 39 // right shift
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
68 #define NODE_OPER_LT 40 // less than
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
69 #define NODE_OPER_LE 41 // less than or equal
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
70 #define NODE_OPER_GT 42 // greater than
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
71 #define NODE_OPER_GE 43 // greater than or equal
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
72 #define NODE_OPER_EQ 44 // equality
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
73 #define NODE_OPER_NE 45 // inequality
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
74 #define NODE_OPER_BWAND 46 // bitwise and
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
75 #define NODE_OPER_BWXOR 47 // bitwise xor
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
76 #define NODE_OPER_BWOR 48 // bitwise or
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
77 #define NODE_OPER_BAND 49 // boolean and
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
78 #define NODE_OPER_BOR 50 // boolean or
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
79 #define NODE_OPER_ASS 51 // assignment
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
80 #define NODE_OPER_ADDASS 52 // add/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
81 #define NODE_OPER_SUBASS 53 // subtract/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
82 #define NODE_OPER_MULASS 54 // multiply/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
83 #define NODE_OPER_DIVASS 55 // divide/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
84 #define NODE_OPER_MODASS 56 // modulus/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
85 #define NODE_OPER_LSHASS 57 // left shift/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
86 #define NODE_OPER_RSHASS 58 // right shift/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
87 #define NODE_OPER_BWANDASS 59 // bitwise and/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
88 #define NODE_OPER_BWXORASS 60 // bitwise xor/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
89 #define NODE_OPER_BWORASS 61 // bitwise or/assign combo
14a40f8bb4eb Add various operators to lwcc
William Astle <lost@l-w.ca>
parents: 501
diff changeset
90 #define NODE_OPER_COMMA 62 // comma sequential evaluation operator
506
7e8298f7bc0a Add basic syntax for typecasting
William Astle <lost@l-w.ca>
parents: 502
diff changeset
91 #define NODE_TYPECAST 63 // type cast to unsigned long long
7e8298f7bc0a Add basic syntax for typecasting
William Astle <lost@l-w.ca>
parents: 502
diff changeset
92 #define NODE_NUMTYPES 64 // the number of node types
312
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
93
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
94 typedef struct node_s node_t;
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
95
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
96 struct node_s
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
97 {
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
98 int type; // node type
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
99 char *strval; // any string value associated with the node
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
100 unsigned char ival[8]; // any 64 bit integer value associated with the node, signed or unsigned
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
101 node_t *children; // pointer to list of child nodes
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
102 node_t *next_child; // pointer to next child in the list
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
103 node_t *parent; // pointer to parent node
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
104 };
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
105
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
106 extern node_t *node_create(int, ...);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
107 extern void node_destroy(node_t *);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
108 extern void node_addchild(node_t *, node_t *);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
109 extern void node_removechild(node_t *, node_t *);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
110 extern void node_display(node_t *, FILE *);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
111 extern void node_removechild_destroy(node_t *, node_t *);
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
112
41118fb0a8f2 Add no-op parser and parse tree infrastructure
William Astle <lost@l-w.ca>
parents:
diff changeset
113 #endif // tree_h_seen___