annotate lwbasic/lwbasic.h @ 35:cdb0175e1063

More work on expressions
author Lost Wizard (lost@starbug3)
date Sat, 05 Feb 2011 14:22:54 -0700
parents bfea77812e64
children 5325b640424d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
1 /*
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
2 lwbasic.h
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
3
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
4 Copyright © 2011 William Astle
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
5
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
6 This file is part of LWTOOLS.
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
7
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
11 version.
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
12
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
16 more details.
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
17
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
20 */
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
21
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
22 /*
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
23 definitions used throughout lwbasic
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
24 */
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
25
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
26 #ifndef __lwbasic_h_seen__
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
27 #define __lwbasic_h_seen__
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
28
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
29 #include <stdint.h>
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
30
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
31 #include "symtab.h"
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
32
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
33 /* note: integer and uinteger will be the same for positive values from 0
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
34 through 0x7FFFFFFF; the unsigned type should be used for doing ascii
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
35 conversions and then if a negative value was discovered, it should be
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
36 negated IFF it is in range. */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
37
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
38 union lexer_numbers
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
39 {
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
40 uint32_t uinteger;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
41 int32_t integer;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
42 };
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
43
22
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
44 typedef struct
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
45 {
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
46 char *output_file;
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
47 char *input_file;
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
48
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
49 int debug_level;
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
50
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
51 char *lexer_token_string;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
52 union lexer_numbers lexer_token_number;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
53 int lexer_token;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
54 int lexer_curchar;
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
55 int lexer_ignorechar;
35
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
56 int expression;
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
57 int parser_state;
23
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
58
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
59 void *input_state;
26
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
60
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
61 char *currentsub;
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
62 symtab_t *global_syms;
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
63 symtab_t *local_syms;
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
64 int returntype;
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
65 int framesize;
22
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
66 } cstate;
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
67
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
68 /* parser states */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
69 enum
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
70 {
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
71 parser_state_global = 0, /* only global decls allowed */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
72 parser_state_error
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
73 };
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
74
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
75 /* token types */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
76 enum
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
77 {
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
78 token_kw_sub, /* SUB keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
79 token_kw_function, /* FUNCTION keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
80 token_kw_as, /* AS keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
81 token_kw_public, /* PUBLIC keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
82 token_kw_private, /* PRIVATE keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
83 token_kw_params, /* PARAMS keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
84 token_kw_returns, /* RETURNS keyword */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
85 token_kw_integer, /* INTEGER keyword */
26
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
86 token_kw_endsub, /* ENDSUB keyword */
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
87 token_kw_endfunction, /* ENDFUNCTION keyword */
33
890a8f688889 Basic parsing of local variable decls
lost@l-w.ca
parents: 32
diff changeset
88 token_kw_dim, /* DIM keyword */
34
bfea77812e64 Start of assignment code
Lost Wizard (lost@starbug3)
parents: 33
diff changeset
89 token_op_assignment, /* assignment operator */
35
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
90 token_op_equality, /* equality test */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
91 token_op_greater, /* greater than */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
92 token_op_less, /* less than */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
93 token_op_greaterequal, /* greater or equal */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
94 token_op_lessequal, /* less or equal */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
95 token_op_notequal, /* not equal */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
96 token_op_and, /* boolean and */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
97 token_op_or, /* boolean or */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
98 token_op_xor, /* boolean exlusive or */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
99 token_op_band, /* bitwise and */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
100 token_op_bor, /* bitwise or */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
101 token_op_bxor, /* bitwise xor */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
102 token_op_plus, /* plus */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
103 token_op_minus, /* minus */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
104 token_op_times, /* times */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
105 token_op_divide, /* divide */
cdb0175e1063 More work on expressions
Lost Wizard (lost@starbug3)
parents: 34
diff changeset
106 token_op_modulus, /* modulus */
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
107 token_identifier, /* an identifier (variable, function, etc. */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
108 token_char, /* single character; fallback */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
109 token_uint, /* unsigned integer up to 32 bits */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
110 token_int, /* signed integer up to 32 bits */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
111 token_eol, /* end of line */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
112 token_eof /* end of file */
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
113 };
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
114
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
115 /* symbol types */
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
116 enum
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
117 {
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
118 symtype_sub, /* "sub" (void function) */
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
119 symtype_func, /* function (nonvoid) */
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
120 symtype_param, /* function parameter */
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
121 symtype_var /* variable */
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
122 };
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
123
23
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
124 #ifndef __input_c_seen__
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
125 extern int input_getchar(cstate *state);
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
126 #endif
25a4aef9c5ed lwbasic: Added basic character input framework
lost@l-w.ca
parents: 22
diff changeset
127
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
128 #ifndef __main_c_seen__
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
129 extern void lwb_error(const char *fmt, ...);
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
130 #endif
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
131
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
132 #ifndef __lexer_c_seen__
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
133 extern void lexer(cstate *state);
31
574931d87abd Created a function to prettyprint the current lexer token
lost@l-w.ca
parents: 27
diff changeset
134 extern char *lexer_return_token(cstate *state);
34
bfea77812e64 Start of assignment code
Lost Wizard (lost@starbug3)
parents: 33
diff changeset
135 extern char *lexer_token_name(int token);
25
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
136 #endif
87590f43e76d Started lwbasic parser; checkpoint
lost@l-w.ca
parents: 23
diff changeset
137
26
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
138 #ifndef __emit_c_seen__
32
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
139 extern void emit_prolog(cstate *state, int vis);
49d608aecc4d Framework for handling local stack frame and/or variables
lost@l-w.ca
parents: 31
diff changeset
140 extern void emit_epilog(cstate *state);
26
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
141 #endif
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
142
26aa76da75ad Additional parsing in function/sub; emission of prolog/epilog code
lost@l-w.ca
parents: 25
diff changeset
143
22
7c35fa8dbc91 Added initial framework for lwbasic
lost@l-w.ca
parents:
diff changeset
144 #endif /* __lwbasic_h_seen__ */