Mercurial > octave-nkf
comparison src/lex.l @ 4208:e96f52432059
[project @ 2002-12-03 19:48:57 by jwe]
author | jwe |
---|---|
date | Tue, 03 Dec 2002 19:48:57 +0000 |
parents | af1d77a5e44d |
children | b9317f3973ec |
comparison
equal
deleted
inserted
replaced
4207:fa3482b34599 | 4208:e96f52432059 |
---|---|
18 along with GNU CC; see the file COPYING. If not, write to the Free | 18 along with GNU CC; see the file COPYING. If not, write to the Free |
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 | 20 |
21 */ | 21 */ |
22 | 22 |
23 %s TEXT_FCN | 23 %s COMMAND_START |
24 %s MATRIX | 24 %s MATRIX_START |
25 | 25 |
26 %{ | 26 %{ |
27 #ifdef HAVE_CONFIG_H | 27 #ifdef HAVE_CONFIG_H |
28 #include <config.h> | 28 #include <config.h> |
29 #endif | 29 #endif |
231 EXPON ([DdEe][+-]?{D}+) | 231 EXPON ([DdEe][+-]?{D}+) |
232 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) | 232 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
233 %% | 233 %% |
234 | 234 |
235 %{ | 235 %{ |
236 // Help and other text-style functions are a pain in the ass. This | 236 // Help and other command-style functions are a pain in the ass. This |
237 // stuff needs to be simplified. May require some changes in the | 237 // stuff needs to be simplified. May require some changes in the |
238 // parser too. | 238 // parser too. |
239 %} | 239 %} |
240 | 240 |
241 <TEXT_FCN>{NL} { | 241 <COMMAND_START>{NL} { |
242 BEGIN 0; | 242 BEGIN 0; |
243 current_input_column = 1; | 243 current_input_column = 1; |
244 lexer_flags.quote_is_transpose = false; | 244 lexer_flags.quote_is_transpose = false; |
245 lexer_flags.cant_be_identifier = false; | 245 lexer_flags.cant_be_identifier = false; |
246 lexer_flags.convert_spaces_to_comma = true; | 246 lexer_flags.convert_spaces_to_comma = true; |
247 return '\n'; | 247 return '\n'; |
248 } | 248 } |
249 | 249 |
250 <TEXT_FCN>[\;\,] { | 250 <COMMAND_START>[\;\,] { |
251 if (lexer_flags.doing_set && strcmp (yytext, ",") == 0) | 251 if (lexer_flags.doing_set && strcmp (yytext, ",") == 0) |
252 { | 252 { |
253 TOK_PUSH_AND_RETURN (yytext, STRING); | 253 TOK_PUSH_AND_RETURN (yytext, STRING); |
254 } | 254 } |
255 else | 255 else |
260 else | 260 else |
261 TOK_RETURN (';'); | 261 TOK_RETURN (';'); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 <TEXT_FCN>[\"\'] { | 265 <COMMAND_START>[\"\'] { |
266 current_input_column++; | 266 current_input_column++; |
267 return handle_string (yytext[0], true); | 267 return handle_string (yytext[0], true); |
268 } | 268 } |
269 | 269 |
270 <TEXT_FCN>[^#% \t\n\;\,\"\'][^ \t\n\;\,]*{S}* { | 270 <COMMAND_START>[^#% \t\n\;\,\"\'][^ \t\n\;\,]*{S}* { |
271 std::string tok = strip_trailing_whitespace (yytext); | 271 std::string tok = strip_trailing_whitespace (yytext); |
272 TOK_PUSH_AND_RETURN (tok, STRING); | 272 TOK_PUSH_AND_RETURN (tok, STRING); |
273 } | 273 } |
274 | 274 |
275 %{ | 275 %{ |
282 // | 282 // |
283 // It's also a pain in the ass to decide whether to insert a comma | 283 // It's also a pain in the ass to decide whether to insert a comma |
284 // after seeing a ']' character... | 284 // after seeing a ']' character... |
285 %} | 285 %} |
286 | 286 |
287 <MATRIX>{SNLCMT}*\]{S}* { | 287 <MATRIX_START>{SNLCMT}*\]{S}* { |
288 scan_for_comments (yytext); | 288 scan_for_comments (yytext); |
289 fixup_column_count (yytext); | 289 fixup_column_count (yytext); |
290 int c = yytext[yyleng-1]; | 290 int c = yytext[yyleng-1]; |
291 int cont_is_spc = eat_continuation (); | 291 int cont_is_spc = eat_continuation (); |
292 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | 292 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
297 // Commas are element separators in matrix constants. If we don't | 297 // Commas are element separators in matrix constants. If we don't |
298 // check for continuations here we can end up inserting too many | 298 // check for continuations here we can end up inserting too many |
299 // commas. | 299 // commas. |
300 %} | 300 %} |
301 | 301 |
302 <MATRIX>{S}*\,{S}* { | 302 <MATRIX_START>{S}*\,{S}* { |
303 current_input_column += yyleng; | 303 current_input_column += yyleng; |
304 | 304 |
305 int tmp = eat_continuation (); | 305 int tmp = eat_continuation (); |
306 | 306 |
307 lexer_flags.quote_is_transpose = false; | 307 lexer_flags.quote_is_transpose = false; |
324 // If commas are required, spaces are not important in matrix | 324 // If commas are required, spaces are not important in matrix |
325 // constants so we just eat them. If we don't check for continuations | 325 // constants so we just eat them. If we don't check for continuations |
326 // here we can end up inserting too many commas. | 326 // here we can end up inserting too many commas. |
327 %} | 327 %} |
328 | 328 |
329 <MATRIX>{S}+ { | 329 <MATRIX_START>{S}+ { |
330 current_input_column += yyleng; | 330 current_input_column += yyleng; |
331 | 331 |
332 int tmp = eat_continuation (); | 332 int tmp = eat_continuation (); |
333 int bin_op = next_token_is_bin_op (true); | 333 int bin_op = next_token_is_bin_op (true); |
334 int postfix_un_op = next_token_is_postfix_unary_op (true); | 334 int postfix_un_op = next_token_is_postfix_unary_op (true); |
362 // Semicolons are handled as row seprators in matrix constants. If we | 362 // Semicolons are handled as row seprators in matrix constants. If we |
363 // don't eat whitespace here we can end up inserting too many | 363 // don't eat whitespace here we can end up inserting too many |
364 // semicolons. | 364 // semicolons. |
365 %} | 365 %} |
366 | 366 |
367 <MATRIX>{SNLCMT}*;{SNLCMT}* { | 367 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
368 scan_for_comments (yytext); | 368 scan_for_comments (yytext); |
369 fixup_column_count (yytext); | 369 fixup_column_count (yytext); |
370 eat_whitespace (); | 370 eat_whitespace (); |
371 lexer_flags.quote_is_transpose = false; | 371 lexer_flags.quote_is_transpose = false; |
372 lexer_flags.cant_be_identifier = false; | 372 lexer_flags.cant_be_identifier = false; |
378 // In some cases, new lines can also become row separators. If we | 378 // In some cases, new lines can also become row separators. If we |
379 // don't eat whitespace here we can end up inserting too many | 379 // don't eat whitespace here we can end up inserting too many |
380 // semicolons. | 380 // semicolons. |
381 %} | 381 %} |
382 | 382 |
383 <MATRIX>{S}*{COMMENT}{SNLCMT}* | | 383 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
384 <MATRIX>{S}*{NL}{SNLCMT}* { | 384 <MATRIX_START>{S}*{NL}{SNLCMT}* { |
385 scan_for_comments (yytext); | 385 scan_for_comments (yytext); |
386 fixup_column_count (yytext); | 386 fixup_column_count (yytext); |
387 eat_whitespace (); | 387 eat_whitespace (); |
388 | 388 |
389 if (Vwhitespace_in_literal_matrix != 2) | 389 if (Vwhitespace_in_literal_matrix != 2) |
428 return OPEN_BRACE; | 428 return OPEN_BRACE; |
429 } | 429 } |
430 else | 430 else |
431 { | 431 { |
432 lexer_flags.bracketflag++; | 432 lexer_flags.bracketflag++; |
433 BEGIN MATRIX; | 433 BEGIN MATRIX_START; |
434 return '['; | 434 return '['; |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 \] { | 438 \] { |
467 return NUM; | 467 return NUM; |
468 } | 468 } |
469 | 469 |
470 %{ | 470 %{ |
471 // Eat whitespace. Whitespace inside matrix constants is handled by | 471 // Eat whitespace. Whitespace inside matrix constants is handled by |
472 // the <MATRIX> start state code above. | 472 // the <MATRIX_START> start state code above. |
473 %} | 473 %} |
474 | 474 |
475 {S}* { | 475 {S}* { |
476 current_input_column += yyleng; | 476 current_input_column += yyleng; |
477 } | 477 } |
526 return handle_identifier (); | 526 return handle_identifier (); |
527 } | 527 } |
528 | 528 |
529 %{ | 529 %{ |
530 // A new line character. New line characters inside matrix constants | 530 // A new line character. New line characters inside matrix constants |
531 // are handled by the <MATRIX> start state code above. If closest | 531 // are handled by the <MATRIX_START> start state code above. If closest |
532 // nesting is inside parentheses, don't return a row separator. | 532 // nesting is inside parentheses, don't return a row separator. |
533 %} | 533 %} |
534 | 534 |
535 {NL} { | 535 {NL} { |
536 current_input_column = 1; | 536 current_input_column = 1; |
2354 // If the following token is `=', or if we are parsing a function | 2354 // If the following token is `=', or if we are parsing a function |
2355 // return list or function parameter list, or if we are looking at | 2355 // return list or function parameter list, or if we are looking at |
2356 // something like [ab,cd] = foo (), force the symbol to be inserted | 2356 // something like [ab,cd] = foo (), force the symbol to be inserted |
2357 // as a variable in the current symbol table. | 2357 // as a variable in the current symbol table. |
2358 | 2358 |
2359 if (is_text_function_name (tok) && ! is_variable (tok)) | 2359 if (is_command_name (tok) && ! is_variable (tok)) |
2360 { | 2360 { |
2361 if (next_tok_is_eq | 2361 if (next_tok_is_eq |
2362 || lexer_flags.looking_at_return_list | 2362 || lexer_flags.looking_at_return_list |
2363 || lexer_flags.looking_at_parameter_list | 2363 || lexer_flags.looking_at_parameter_list |
2364 || lexer_flags.looking_at_matrix_or_assign_lhs) | 2364 || lexer_flags.looking_at_matrix_or_assign_lhs) |
2368 else if (! next_tok_is_paren) | 2368 else if (! next_tok_is_paren) |
2369 { | 2369 { |
2370 if (tok == "gset") | 2370 if (tok == "gset") |
2371 lexer_flags.doing_set = true; | 2371 lexer_flags.doing_set = true; |
2372 | 2372 |
2373 BEGIN TEXT_FCN; | 2373 BEGIN COMMAND_START; |
2374 } | 2374 } |
2375 } | 2375 } |
2376 | 2376 |
2377 // Find the token in the symbol table. | 2377 // Find the token in the symbol table. |
2378 | 2378 |