# HG changeset patch # User John W. Eaton # Date 1361860451 18000 # Node ID 3ec4f6488569ab6ceb55163d079010d49fe58b46 # Parent 7302f8a4df832d9186f36862a1ba386487badf3d 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. diff -r 7302f8a4df83 -r 3ec4f6488569 libinterp/parse-tree/lex.h --- a/libinterp/parse-tree/lex.h Tue Feb 26 01:10:08 2013 -0500 +++ b/libinterp/parse-tree/lex.h Tue Feb 26 01:34:11 2013 -0500 @@ -54,6 +54,10 @@ extern void prep_lexer_for_script_file (void); extern void prep_lexer_for_function_file (void); + +// Forward decl for lexical_feedback::token_stack. +class token; + // For communication between the lexer and parser. class @@ -175,7 +179,7 @@ init (); } - ~lexical_feedback (void) { } + ~lexical_feedback (void); void init (void) { @@ -280,6 +284,11 @@ // a paren? bbp_nesting_level nesting_level; + // 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. + std::stack token_stack; + private: // No copying! diff -r 7302f8a4df83 -r 3ec4f6488569 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Tue Feb 26 01:10:08 2013 -0500 +++ b/libinterp/parse-tree/lex.ll Tue Feb 26 01:34:11 2013 -0500 @@ -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_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).