comparison lwbasic/parser.c @ 35:cdb0175e1063

More work on expressions
author Lost Wizard (lost@starbug3)
date Sat, 05 Feb 2011 14:22:54 -0700
parents bfea77812e64
children 5325b640424d
comparison
equal deleted inserted replaced
34:bfea77812e64 35:cdb0175e1063
62 lwb_error("Invalid type specification"); 62 lwb_error("Invalid type specification");
63 } 63 }
64 lexer(state); 64 lexer(state);
65 /* look for "unsigned" modifier for integer types */ 65 /* look for "unsigned" modifier for integer types */
66 return pt; 66 return pt;
67 }
68
69 static int parse_expression(cstate *state)
70 {
71 state -> expression = 1;
72
73 state -> expression = 0;
74 return 1;
67 } 75 }
68 76
69 static void parse_decls(cstate *state) 77 static void parse_decls(cstate *state)
70 { 78 {
71 /* declarations */ 79 /* declarations */
120 } 128 }
121 129
122 static void parse_statements(cstate *state) 130 static void parse_statements(cstate *state)
123 { 131 {
124 symtab_entry_t *se; 132 symtab_entry_t *se;
133 int et;
125 134
126 for (;;) 135 for (;;)
127 { 136 {
128 switch (state -> lexer_token) 137 switch (state -> lexer_token)
129 { 138 {
139 se = symtab_find(state -> global_syms, state -> lexer_token_string); 148 se = symtab_find(state -> global_syms, state -> lexer_token_string);
140 } 149 }
141 if (!se) 150 if (!se)
142 lwb_error("Unknown variable %s\n", state -> lexer_token_string); 151 lwb_error("Unknown variable %s\n", state -> lexer_token_string);
143 lexer(state); 152 lexer(state);
153 /* ensure the first token of the expression will be parsed correctly */
154 state -> expression = 1;
144 expect(state, token_op_assignment); 155 expect(state, token_op_assignment);
145 156
146 /* parse the expression */ 157 /* parse the expression */
147 /* parse_expression(state); */ 158 et = parse_expression(state);
159
160 /* check type compatibility */
148 161
149 /* actually do the assignment */ 162 /* actually do the assignment */
150 163
151 break; 164 break;
152 165