Mercurial > hg > octave-lyh
changeset 4753:9f0ce1536368
[project @ 2004-02-13 17:55:24 by jwe]
author | jwe |
---|---|
date | Fri, 13 Feb 2004 17:55:24 +0000 |
parents | 2be826ada7bb |
children | 245523b54e0f |
files | src/ChangeLog src/lex.h src/lex.l src/octave.cc src/parse.h src/parse.y src/toplev.cc |
diffstat | 7 files changed, 94 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2004-02-13 John W. Eaton <jwe@bevo.che.wisc.edu> + + * toplev.cc (main_loop): Call octave_parse, not yyparse. + * octave.cc (octave_main): Increment octave_debug, not yydebug. + * parse.y (%name-prefix): New directive, set to "octave_". + * parse.h: Provide declarations for octave_lex and octave_parse + instead of yylex and yyparse. + * lex.l (%option prefix): New directive, set to "_octave". + Define yylval to be octave_lval. + Move definitions of YY_INPUT, YY_FATAL_ERROR, TOK_RETURN, + TOK_PUSH_AND_RETURN, BIN_OP_RETURN, XBIN_OP_RETURN here. + * lex.h: From here. + 2004-02-07 Petter Risholm <risholm@stud.ntnu.no> * ov-struct.cc (Fcell2struct): New function.
--- a/src/lex.h +++ b/src/lex.h @@ -23,74 +23,7 @@ #if !defined (octave_lex_h) #define octave_lex_h 1 -// Arrange to get input via readline. - -#ifdef YY_INPUT -#undef YY_INPUT -#endif -#define YY_INPUT(buf, result, max_size) \ - if ((result = octave_read (buf, max_size)) < 0) \ - YY_FATAL_ERROR ("octave_read () in flex scanner failed"); - -// Try to avoid crashing out completely on fatal scanner errors. -// The call to yy_fatal_error should never happen, but it avoids a -// `static function defined but not used' warning from gcc. - -#ifdef YY_FATAL_ERROR -#undef YY_FATAL_ERROR -#endif -#define YY_FATAL_ERROR(msg) \ - do \ - { \ - error (msg); \ - OCTAVE_QUIT; \ - yy_fatal_error (msg); \ - } \ - while (0) - -#define TOK_RETURN(tok) \ - do \ - { \ - current_input_column += yyleng; \ - lexer_flags.quote_is_transpose = false; \ - lexer_flags.cant_be_identifier = false; \ - lexer_flags.convert_spaces_to_comma = true; \ - return (tok); \ - } \ - while (0) - -#define TOK_PUSH_AND_RETURN(name, tok) \ - do \ - { \ - yylval.tok_val = new token (name, input_line_number, \ - current_input_column); \ - token_stack.push (yylval.tok_val); \ - TOK_RETURN (tok); \ - } \ - while (0) - -#define BIN_OP_RETURN(tok, convert) \ - do \ - { \ - yylval.tok_val = new token (input_line_number, current_input_column); \ - token_stack.push (yylval.tok_val); \ - current_input_column += yyleng; \ - lexer_flags.quote_is_transpose = false; \ - lexer_flags.cant_be_identifier = true; \ - lexer_flags.convert_spaces_to_comma = convert; \ - return (tok); \ - } \ - while (0) - -#define XBIN_OP_RETURN(tok, convert) \ - do \ - { \ - gripe_matlab_incompatible_operator (yytext); \ - BIN_OP_RETURN (tok, convert); \ - } \ - while (0) - -// XXX FIXME XXX -- these input buffer things should be members of an +// XXX FIXME XXX -- these input buffer things should be members of a // parser input stream class. typedef struct yy_buffer_state *YY_BUFFER_STATE;
--- a/src/lex.l +++ b/src/lex.l @@ -20,6 +20,8 @@ */ +%option prefix = "octave_" + %s COMMAND_START %s MATRIX_START @@ -77,6 +79,75 @@ #error lex.l requires flex version 2.5.4 or later #endif +#define yylval octave_lval + +// Arrange to get input via readline. + +#ifdef YY_INPUT +#undef YY_INPUT +#endif +#define YY_INPUT(buf, result, max_size) \ + if ((result = octave_read (buf, max_size)) < 0) \ + YY_FATAL_ERROR ("octave_read () in flex scanner failed"); + +// Try to avoid crashing out completely on fatal scanner errors. +// The call to yy_fatal_error should never happen, but it avoids a +// `static function defined but not used' warning from gcc. + +#ifdef YY_FATAL_ERROR +#undef YY_FATAL_ERROR +#endif +#define YY_FATAL_ERROR(msg) \ + do \ + { \ + error (msg); \ + OCTAVE_QUIT; \ + yy_fatal_error (msg); \ + } \ + while (0) + +#define TOK_RETURN(tok) \ + do \ + { \ + current_input_column += yyleng; \ + lexer_flags.quote_is_transpose = false; \ + lexer_flags.cant_be_identifier = false; \ + lexer_flags.convert_spaces_to_comma = true; \ + return (tok); \ + } \ + while (0) + +#define TOK_PUSH_AND_RETURN(name, tok) \ + do \ + { \ + yylval.tok_val = new token (name, input_line_number, \ + current_input_column); \ + token_stack.push (yylval.tok_val); \ + TOK_RETURN (tok); \ + } \ + while (0) + +#define BIN_OP_RETURN(tok, convert) \ + do \ + { \ + yylval.tok_val = new token (input_line_number, current_input_column); \ + token_stack.push (yylval.tok_val); \ + current_input_column += yyleng; \ + lexer_flags.quote_is_transpose = false; \ + lexer_flags.cant_be_identifier = true; \ + lexer_flags.convert_spaces_to_comma = convert; \ + return (tok); \ + } \ + while (0) + +#define XBIN_OP_RETURN(tok, convert) \ + do \ + { \ + gripe_matlab_incompatible_operator (yytext); \ + BIN_OP_RETURN (tok, convert); \ + } \ + while (0) + // TRUE means that we have encountered EOF on the input stream. bool parser_end_of_input = false;
--- a/src/octave.cc +++ b/src/octave.cc @@ -413,7 +413,8 @@ break; case 'd': - yydebug++; + // This is the same as yydebug in parse.y. + octave_debug++; break; case 'f':
--- a/src/parse.h +++ b/src/parse.h @@ -30,8 +30,8 @@ #include <stack> extern void reset_parser (void); -extern int yylex (void); -extern int yyparse (void); +extern int octave_lex (void); +extern int octave_parse (void); class tree; class tree_matrix; @@ -46,7 +46,7 @@ extern symbol_table *tmp_local_sym_tab; // Nonzero means print parser debugging info (-d). -extern int yydebug; +extern int octave_debug; // The current input line number. extern int input_line_number;