Mercurial > hg > octave-lyh
diff libinterp/parse-tree/lex.ll @ 16111:3ec4f6488569
move token stack to lexical_feedback class
* lex.h, lex.ll (token_stack): Move global variable to
lexical_feedback class. Change all uses.
* lex.ll (lexical_feedback::~lexical_feedback): Move definition here
from lex.h. Clean up token_stack.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 01:34:11 -0500 |
parents | 7302f8a4df83 |
children | 7c5e5e97a3bc |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -160,7 +160,7 @@ { \ yylval.tok_val = new token (name, curr_lexer->input_line_number, \ curr_lexer->current_input_column); \ - token_stack.push (yylval.tok_val); \ + curr_lexer->token_stack.push (yylval.tok_val); \ TOK_RETURN (tok); \ } \ while (0) @@ -170,7 +170,7 @@ { \ yylval.tok_val = new token (curr_lexer->input_line_number, \ curr_lexer->current_input_column); \ - token_stack.push (yylval.tok_val); \ + curr_lexer->token_stack.push (yylval.tok_val); \ curr_lexer->current_input_column += yyleng; \ curr_lexer->quote_is_transpose = qit; \ curr_lexer->convert_spaces_to_comma = convert; \ @@ -214,15 +214,6 @@ // The state of the lexer. lexical_feedback *curr_lexer = 0; -// Stack to hold tokens so that we can delete them when the parser is -// reset and avoid growing forever just because we are stashing some -// information. This has to appear before lex.h is included, because -// one of the macros defined there uses token_stack. -// -// FIXME -- this should really be static, but that causes -// problems on some systems. -std::stack <token*> token_stack; - static bool Vdisplay_tokens = false; static unsigned int Vtoken_count = 0; @@ -1051,14 +1042,6 @@ // We do want a prompt by default. promptflag = 1; - // Clear out the stack of token info used to track line and column - // numbers. - while (! token_stack.empty ()) - { - delete token_stack.top (); - token_stack.pop (); - } - // Only ask for input from stdin if we are expecting interactive // input. @@ -1222,6 +1205,18 @@ } } +lexical_feedback::~lexical_feedback (void) +{ + // Clear out the stack of token info used to track line and + // column numbers. + + while (! token_stack.empty ()) + { + delete token_stack.top (); + token_stack.pop (); + } +} + static int text_yyinput (void) { @@ -1598,7 +1593,7 @@ if (! yylval.tok_val) yylval.tok_val = new token (l, c); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); return kw->tok; } @@ -2356,7 +2351,7 @@ yylval.tok_val = new token (value, yytext, curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); curr_lexer->current_input_column += yyleng; @@ -2571,7 +2566,7 @@ curr_lexer->convert_spaces_to_comma = true; yylval.tok_val = new token (s, bos_line, bos_col); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); if (delim == '"') gripe_matlab_incompatible ("\" used as string delimiter"); @@ -3089,7 +3084,7 @@ pkg.empty () ? 0 : &(symbol_table::insert (pkg)), curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); curr_lexer->convert_spaces_to_comma = true; curr_lexer->current_input_column += yyleng; @@ -3125,7 +3120,7 @@ curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); curr_lexer->convert_spaces_to_comma = true; curr_lexer->current_input_column += yyleng; @@ -3164,7 +3159,7 @@ yylval.tok_val = new token (tok, curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); curr_lexer->quote_is_transpose = true; curr_lexer->convert_spaces_to_comma = true; @@ -3201,7 +3196,7 @@ yylval.tok_val = new token (tok, curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); curr_lexer->current_input_column += yyleng; curr_lexer->quote_is_transpose = false; @@ -3285,7 +3280,7 @@ curr_lexer->input_line_number, curr_lexer->current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->token_stack.push (yylval.tok_val); // After seeing an identifer, it is ok to convert spaces to a comma // (if needed).