Mercurial > hg > octave-avbm
comparison src/lex.l @ 7336:745a8299c2b5
[project @ 2007-12-28 20:56:55 by jwe]
author | jwe |
---|---|
date | Fri, 28 Dec 2007 20:56:58 +0000 |
parents | a1dbe9d80eee |
children | 1f662945c2be |
comparison
equal
deleted
inserted
replaced
7335:58f5fab3ebe5 | 7336:745a8299c2b5 |
---|---|
240 static void fixup_column_count (char *s); | 240 static void fixup_column_count (char *s); |
241 static void do_comma_insert_check (void); | 241 static void do_comma_insert_check (void); |
242 static int is_keyword_token (const std::string& s); | 242 static int is_keyword_token (const std::string& s); |
243 static void prep_for_function (void); | 243 static void prep_for_function (void); |
244 static void prep_for_nested_function (void); | 244 static void prep_for_nested_function (void); |
245 static symbol_record *lookup_identifier (const std::string& s); | |
246 static std::string grab_help_text (void); | 245 static std::string grab_help_text (void); |
247 static bool match_any (char c, const char *s); | 246 static bool match_any (char c, const char *s); |
248 static bool next_token_is_sep_op (void); | 247 static bool next_token_is_sep_op (void); |
249 static bool next_token_is_bin_op (bool spc_prev); | 248 static bool next_token_is_bin_op (bool spc_prev); |
250 static bool next_token_is_postfix_unary_op (bool spc_prev); | 249 static bool next_token_is_postfix_unary_op (bool spc_prev); |
842 end_tokens_expected = 0; | 841 end_tokens_expected = 0; |
843 | 842 |
844 while (! symtab_context.empty ()) | 843 while (! symtab_context.empty ()) |
845 symtab_context.pop (); | 844 symtab_context.pop (); |
846 | 845 |
846 symbol_table::reset_parent_scope (); | |
847 | |
847 // We do want a prompt by default. | 848 // We do want a prompt by default. |
848 promptflag = 1; | 849 promptflag = 1; |
849 | 850 |
850 // Error may have occurred inside some brackets, braces, or parentheses. | 851 // Error may have occurred inside some brackets, braces, or parentheses. |
851 nesting_level.clear (); | 852 nesting_level.clear (); |
956 | 957 |
957 static void | 958 static void |
958 prep_for_function (void) | 959 prep_for_function (void) |
959 { | 960 { |
960 end_tokens_expected++; | 961 end_tokens_expected++; |
961 | |
962 // Prepare for local symbols. | |
963 | |
964 tmp_local_sym_tab = new symbol_table (); | |
965 | 962 |
966 promptflag--; | 963 promptflag--; |
967 | 964 |
968 lexer_flags.defining_func = true; | 965 lexer_flags.defining_func = true; |
969 lexer_flags.parsed_function_name = false; | 966 lexer_flags.parsed_function_name = false; |
1172 } | 1169 } |
1173 | 1170 |
1174 return 0; | 1171 return 0; |
1175 } | 1172 } |
1176 | 1173 |
1177 // Try to find an identifier. All binding to global or builtin | |
1178 // variables occurs when expressions are evaluated. | |
1179 | |
1180 static symbol_record * | |
1181 lookup_identifier (const std::string& name) | |
1182 { | |
1183 std::string sym_name = name; | |
1184 | |
1185 if (curr_sym_tab == fbi_sym_tab | |
1186 && lexer_flags.parsing_nested_function) | |
1187 sym_name = parent_function_name + ":" + sym_name; | |
1188 | |
1189 return curr_sym_tab->lookup (sym_name, true); | |
1190 } | |
1191 | |
1192 static bool | 1174 static bool |
1193 is_variable (const std::string& name) | 1175 is_variable (const std::string& name) |
1194 { | 1176 { |
1195 symbol_record *sr = curr_sym_tab->lookup (name); | 1177 return symbol_table::is_variable (name); |
1196 | |
1197 return sr && sr->is_variable (); | |
1198 } | 1178 } |
1199 | 1179 |
1200 static void | 1180 static void |
1201 force_local_variable (const std::string& name) | 1181 force_local_variable (const std::string& name) |
1202 { | 1182 { |
1203 if (! is_variable (name)) | 1183 octave_value& val = symbol_table::varref (name); |
1204 curr_sym_tab->clear (name); | 1184 |
1205 | 1185 if (! val.is_defined ()) |
1206 symbol_record *sr = curr_sym_tab->lookup (name, true); | 1186 val = Matrix (); |
1207 | |
1208 if (sr) | |
1209 sr->define (octave_value ()); | |
1210 } | 1187 } |
1211 | 1188 |
1212 // Grab the help text from an function file. | 1189 // Grab the help text from an function file. |
1213 | 1190 |
1214 // FIXME -- gobble_leading_white_space() in parse.y | 1191 // FIXME -- gobble_leading_white_space() in parse.y |
2305 next_tok_is_eq = true; | 2282 next_tok_is_eq = true; |
2306 } | 2283 } |
2307 | 2284 |
2308 yyunput (c1, yytext); | 2285 yyunput (c1, yytext); |
2309 | 2286 |
2310 // Make sure we put the return values of a function in the symbol | |
2311 // table that is local to the function. | |
2312 | |
2313 // If we are defining a function and we have not seen the function | |
2314 // name yet and the next token is `=', then this identifier must be | |
2315 // the only return value for the function and it belongs in the | |
2316 // local symbol table. | |
2317 | |
2318 if (next_tok_is_eq | |
2319 && lexer_flags.defining_func | |
2320 && ! lexer_flags.parsed_function_name) | |
2321 curr_sym_tab = tmp_local_sym_tab; | |
2322 | |
2323 // Kluge alert. | 2287 // Kluge alert. |
2324 // | 2288 // |
2325 // If we are looking at a text style function, set up to gobble its | 2289 // If we are looking at a text style function, set up to gobble its |
2326 // arguments. | 2290 // arguments. |
2327 // | 2291 // |
2355 // transformation of the end keyword... | 2319 // transformation of the end keyword... |
2356 | 2320 |
2357 if (tok == "end") | 2321 if (tok == "end") |
2358 tok = "__end__"; | 2322 tok = "__end__"; |
2359 | 2323 |
2360 yylval.tok_val = new token (lookup_identifier (tok), | 2324 yylval.tok_val = new token (&(symbol_table::insert (tok)), |
2361 input_line_number, | 2325 input_line_number, current_input_column); |
2362 current_input_column); | 2326 |
2327 // FIXME -- this forces a link for tok in the chain of variables for | |
2328 // the current scope. Probably this step should be done | |
2329 // differently, maybe in symbol_table::insert? | |
2330 symbol_table::varref (tok); | |
2363 | 2331 |
2364 token_stack.push (yylval.tok_val); | 2332 token_stack.push (yylval.tok_val); |
2365 | 2333 |
2366 // After seeing an identifer, it is ok to convert spaces to a comma | 2334 // After seeing an identifer, it is ok to convert spaces to a comma |
2367 // (if needed). | 2335 // (if needed). |
2397 // Not initially defining a function. | 2365 // Not initially defining a function. |
2398 beginning_of_function = false; | 2366 beginning_of_function = false; |
2399 defining_func = false; | 2367 defining_func = false; |
2400 parsed_function_name = false; | 2368 parsed_function_name = false; |
2401 parsing_nested_function = 0; | 2369 parsing_nested_function = 0; |
2370 parsing_class_method = false; | |
2402 | 2371 |
2403 // Not initiallly looking at a function handle. | 2372 // Not initiallly looking at a function handle. |
2404 looking_at_function_handle = 0; | 2373 looking_at_function_handle = 0; |
2405 | 2374 |
2406 // Not parsing a function return or parameter list. | 2375 // Not parsing a function return or parameter list. |