Mercurial > hg > octave-nkf
annotate src/lex.l @ 8812:7d48766c21a5
use consistent format for doc strings of internal functions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 Feb 2009 02:16:34 -0500 |
parents | 026c6732ec7a |
children | 8ed42c679af5 |
rev | line source |
---|---|
1994 | 1 /* |
1 | 2 |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
4753 | 24 %option prefix = "octave_" |
25 | |
4208 | 26 %s COMMAND_START |
27 %s MATRIX_START | |
4240 | 28 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
29 %x SCRIPT_FILE_BEGIN |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
30 |
4240 | 31 %x NESTED_FUNCTION_END |
32 %x NESTED_FUNCTION_BEGIN | |
1 | 33 |
34 %{ | |
240 | 35 #ifdef HAVE_CONFIG_H |
1220 | 36 #include <config.h> |
240 | 37 #endif |
38 | |
1341 | 39 #include <cctype> |
40 #include <cstring> | |
41 | |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
42 #include <set> |
5765 | 43 #include <sstream> |
1823 | 44 #include <string> |
4214 | 45 #include <stack> |
1823 | 46 |
4093 | 47 #ifdef HAVE_UNISTD_H |
48 #ifdef HAVE_SYS_TYPES_H | |
49 #include <sys/types.h> | |
50 #endif | |
51 #include <unistd.h> | |
52 #endif | |
53 | |
2926 | 54 #include "cmd-edit.h" |
4153 | 55 #include "quit.h" |
4910 | 56 #include "lo-mappers.h" |
2926 | 57 |
1497 | 58 // These would be alphabetical, but y.tab.h must be included before |
59 // oct-gperf.h and y.tab.h must be included after token.h and the tree | |
60 // class declarations. We can't include y.tab.h in oct-gperf.h | |
61 // because it may not be protected to allow it to be included multiple | |
62 // times. | |
63 | |
4264 | 64 #include "Cell.h" |
3665 | 65 #include "comment-list.h" |
2181 | 66 #include "defun.h" |
1355 | 67 #include "error.h" |
4910 | 68 #include "gripes.h" |
1351 | 69 #include "input.h" |
1355 | 70 #include "lex.h" |
2891 | 71 #include "ov.h" |
1355 | 72 #include "parse.h" |
2987 | 73 #include "pt-all.h" |
2891 | 74 #include "symtab.h" |
75 #include "token.h" | |
76 #include "toplev.h" | |
1355 | 77 #include "utils.h" |
78 #include "variables.h" | |
2492 | 79 #include <y.tab.h> |
80 #include <oct-gperf.h> | |
1 | 81 |
2716 | 82 #if ! (defined (FLEX_SCANNER) \ |
83 && defined (YY_FLEX_MAJOR_VERSION) && YY_FLEX_MAJOR_VERSION >= 2 \ | |
84 && defined (YY_FLEX_MINOR_VERSION) && YY_FLEX_MINOR_VERSION >= 5) | |
85 #error lex.l requires flex version 2.5.4 or later | |
86 #endif | |
87 | |
4753 | 88 #define yylval octave_lval |
89 | |
90 // Arrange to get input via readline. | |
91 | |
92 #ifdef YY_INPUT | |
93 #undef YY_INPUT | |
94 #endif | |
95 #define YY_INPUT(buf, result, max_size) \ | |
96 if ((result = octave_read (buf, max_size)) < 0) \ | |
97 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); | |
98 | |
99 // Try to avoid crashing out completely on fatal scanner errors. | |
100 // The call to yy_fatal_error should never happen, but it avoids a | |
101 // `static function defined but not used' warning from gcc. | |
102 | |
103 #ifdef YY_FATAL_ERROR | |
104 #undef YY_FATAL_ERROR | |
105 #endif | |
106 #define YY_FATAL_ERROR(msg) \ | |
107 do \ | |
108 { \ | |
109 error (msg); \ | |
110 OCTAVE_QUIT; \ | |
111 yy_fatal_error (msg); \ | |
112 } \ | |
113 while (0) | |
114 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
115 #define DISPLAY_TOK_AND_RETURN(tok) \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
116 do \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
117 { \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
118 int tok_val = tok; \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
119 if (Vdisplay_tokens) \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
120 display_token (tok_val); \ |
8535 | 121 if (lexer_debug_flag) \ |
122 { \ | |
123 std::cerr << "R: "; \ | |
124 display_token (tok_val); \ | |
125 std::cerr << std::endl; \ | |
126 } \ | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
127 return tok_val; \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
128 } \ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
129 while (0) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
130 |
4910 | 131 #define COUNT_TOK_AND_RETURN(tok) \ |
132 do \ | |
133 { \ | |
134 Vtoken_count++; \ | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
135 DISPLAY_TOK_AND_RETURN (tok); \ |
4910 | 136 } \ |
137 while (0) | |
138 | |
4753 | 139 #define TOK_RETURN(tok) \ |
140 do \ | |
141 { \ | |
142 current_input_column += yyleng; \ | |
143 lexer_flags.quote_is_transpose = false; \ | |
144 lexer_flags.convert_spaces_to_comma = true; \ | |
4910 | 145 COUNT_TOK_AND_RETURN (tok); \ |
4753 | 146 } \ |
147 while (0) | |
148 | |
149 #define TOK_PUSH_AND_RETURN(name, tok) \ | |
150 do \ | |
151 { \ | |
152 yylval.tok_val = new token (name, input_line_number, \ | |
153 current_input_column); \ | |
154 token_stack.push (yylval.tok_val); \ | |
155 TOK_RETURN (tok); \ | |
156 } \ | |
157 while (0) | |
158 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
159 #define BIN_OP_RETURN(tok, convert, bos) \ |
4753 | 160 do \ |
161 { \ | |
162 yylval.tok_val = new token (input_line_number, current_input_column); \ | |
163 token_stack.push (yylval.tok_val); \ | |
164 current_input_column += yyleng; \ | |
165 lexer_flags.quote_is_transpose = false; \ | |
166 lexer_flags.convert_spaces_to_comma = convert; \ | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
167 lexer_flags.looking_for_object_index = false; \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
168 lexer_flags.at_beginning_of_statement = bos; \ |
4910 | 169 COUNT_TOK_AND_RETURN (tok); \ |
4753 | 170 } \ |
171 while (0) | |
172 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
173 #define XBIN_OP_RETURN(tok, convert, bos) \ |
4753 | 174 do \ |
175 { \ | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
176 gripe_matlab_incompatible_operator (yytext); \ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
177 BIN_OP_RETURN (tok, convert, bos); \ |
4753 | 178 } \ |
179 while (0) | |
180 | |
8535 | 181 #define LEXER_DEBUG(pattern) \ |
182 do \ | |
183 { \ | |
184 if (lexer_debug_flag) \ | |
185 lexer_debug (pattern, yytext); \ | |
186 } \ | |
187 while (0) | |
188 | |
3883 | 189 // TRUE means that we have encountered EOF on the input stream. |
190 bool parser_end_of_input = false; | |
191 | |
1826 | 192 // Flags that need to be shared between the lexer and parser. |
193 lexical_feedback lexer_flags; | |
194 | |
1351 | 195 // Stack to hold tokens so that we can delete them when the parser is |
196 // reset and avoid growing forever just because we are stashing some | |
197 // information. This has to appear before lex.h is included, because | |
198 // one of the macros defined there uses token_stack. | |
2614 | 199 // |
5775 | 200 // FIXME -- this should really be static, but that causes |
2614 | 201 // problems on some systems. |
4214 | 202 std::stack <token*> token_stack; |
1351 | 203 |
1826 | 204 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
1 | 205 |
1826 | 206 typedef int yum_yum; |
1 | 207 |
1826 | 208 const yum_yum ATE_NOTHING = 0; |
209 const yum_yum ATE_SPACE_OR_TAB = 1; | |
210 const yum_yum ATE_NEWLINE = 2; | |
1088 | 211 |
3351 | 212 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
1826 | 213 |
4214 | 214 class bracket_brace_paren_nesting_level |
1826 | 215 { |
216 public: | |
217 | |
4214 | 218 bracket_brace_paren_nesting_level (void) : context () { } |
1826 | 219 |
3351 | 220 ~bracket_brace_paren_nesting_level (void) { } |
221 | |
4214 | 222 void bracket (void) { context.push (BRACKET); } |
223 bool is_bracket (void) | |
224 { return ! context.empty () && context.top () == BRACKET; } | |
225 | |
226 void brace (void) { context.push (BRACE); } | |
227 bool is_brace (void) | |
228 { return ! context.empty () && context.top () == BRACE; } | |
229 | |
230 void paren (void) { context.push (PAREN); } | |
231 bool is_paren (void) | |
232 { return ! context.empty () && context.top () == PAREN; } | |
233 | |
4608 | 234 bool is_bracket_or_brace (void) |
235 { return (! context.empty () | |
236 && (context.top () == BRACKET || context.top () == BRACE)); } | |
237 | |
4214 | 238 bool none (void) { return context.empty (); } |
239 | |
240 void remove (void) { if (! context.empty ()) context.pop (); } | |
241 | |
242 void clear (void) { while (! context.empty ()) context.pop (); } | |
1826 | 243 |
244 private: | |
245 | |
4214 | 246 std::stack<int> context; |
247 | |
5225 | 248 static const int BRACKET; |
249 static const int BRACE; | |
250 static const int PAREN; | |
1826 | 251 |
3351 | 252 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
1826 | 253 |
3351 | 254 bracket_brace_paren_nesting_level& |
255 operator = (const bracket_brace_paren_nesting_level&); | |
1826 | 256 }; |
257 | |
5225 | 258 const int bracket_brace_paren_nesting_level::BRACKET = 1; |
259 const int bracket_brace_paren_nesting_level::BRACE = 2; | |
260 const int bracket_brace_paren_nesting_level::PAREN = 3; | |
261 | |
3351 | 262 static bracket_brace_paren_nesting_level nesting_level; |
1 | 263 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
264 static bool Vdisplay_tokens = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
265 |
4910 | 266 static unsigned int Vtoken_count = 0; |
267 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
268 // The start state that was in effect when the beginning of a block |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
269 // comment was noticed. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
270 static int block_comment_nesting_level = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
271 |
8535 | 272 // Internal variable for lexer debugging state. |
273 static bool lexer_debug_flag = false; | |
274 | |
146 | 275 // Forward declarations for functions defined at the bottom of this |
276 // file. | |
277 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
278 static int text_yyinput (void); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
279 static void xunput (char c, char *buf); |
1 | 280 static void fixup_column_count (char *s); |
146 | 281 static void do_comma_insert_check (void); |
4867 | 282 static int is_keyword_token (const std::string& s); |
4238 | 283 static void prep_for_function (void); |
284 static void prep_for_nested_function (void); | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
285 static int process_comment (bool start_in_block, bool& eof); |
2857 | 286 static bool match_any (char c, const char *s); |
3263 | 287 static bool next_token_is_sep_op (void); |
3246 | 288 static bool next_token_is_bin_op (bool spc_prev); |
289 static bool next_token_is_postfix_unary_op (bool spc_prev); | |
3523 | 290 static std::string strip_trailing_whitespace (char *s); |
3246 | 291 static void handle_number (void); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
292 static int handle_string (char delim); |
4612 | 293 static int handle_close_bracket (bool spc_gobbled, int bracket_type); |
3974 | 294 static int handle_identifier (void); |
3096 | 295 static bool have_continuation (bool trailing_comments_ok = true); |
296 static bool have_ellipsis_continuation (bool trailing_comments_ok = true); | |
3665 | 297 static void scan_for_comments (const char *); |
1826 | 298 static yum_yum eat_whitespace (void); |
299 static yum_yum eat_continuation (void); | |
3388 | 300 static void maybe_warn_separator_insert (char sep); |
3400 | 301 static void gripe_single_quote_string (void); |
4037 | 302 static void gripe_matlab_incompatible (const std::string& msg); |
303 static void maybe_gripe_matlab_incompatible_comment (char c); | |
304 static void gripe_matlab_incompatible_continuation (void); | |
305 static void gripe_matlab_incompatible_operator (const std::string& op); | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
306 static void display_token (int tok); |
8535 | 307 static void lexer_debug (const char *pattern, const char *text); |
1 | 308 |
309 %} | |
310 | |
311 D [0-9] | |
312 S [ \t] | |
5570 | 313 NL ((\n)|(\r)|(\r\n)) |
2042 | 314 SNL ({S}|{NL}) |
1 | 315 EL (\.\.\.) |
967 | 316 BS (\\) |
317 CONT ({EL}|{BS}) | |
1 | 318 Im [iIjJ] |
967 | 319 CCHAR [#%] |
320 COMMENT ({CCHAR}.*{NL}) | |
321 SNLCMT ({SNL}|{COMMENT}) | |
322 NOT ((\~)|(\!)) | |
4037 | 323 POW ((\*\*)|(\^)) |
324 EPOW (\.{POW}) | |
5290 | 325 IDENT ([_$a-zA-Z][_$a-zA-Z0-9]*) |
1 | 326 EXPON ([DdEe][+-]?{D}+) |
3220 | 327 NUMBER (({D}+\.?{D}*{EXPON}?)|(\.{D}+{EXPON}?)|(0[xX][0-9a-fA-F]+)) |
1 | 328 %% |
329 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
330 <SCRIPT_FILE_BEGIN>. { |
8535 | 331 LEXER_DEBUG ("<SCRIPT_FILE_BEGIN>."); |
332 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
333 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
334 xunput (yytext[0], yytext); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
335 COUNT_TOK_AND_RETURN (SCRIPT); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
336 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
337 |
4240 | 338 <NESTED_FUNCTION_END>. { |
8535 | 339 LEXER_DEBUG ("<NESTED_FUNCTION_END>."); |
340 | |
4323 | 341 BEGIN (NESTED_FUNCTION_BEGIN); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
342 xunput (yytext[0], yytext); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
343 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
344 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
345 |
4910 | 346 COUNT_TOK_AND_RETURN (';'); |
4240 | 347 } |
348 | |
349 <NESTED_FUNCTION_BEGIN>. { | |
8535 | 350 LEXER_DEBUG ("<NESTED_FUNCTION_BEGIN>."); |
351 | |
4323 | 352 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
353 xunput (yytext[0], yytext); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
354 |
4238 | 355 prep_for_nested_function (); |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
356 |
4910 | 357 COUNT_TOK_AND_RETURN (FCN); |
4238 | 358 } |
359 | |
968 | 360 %{ |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
361 // Help and other command-style functions. |
968 | 362 %} |
363 | |
4208 | 364 <COMMAND_START>{NL} { |
8535 | 365 LEXER_DEBUG ("<COMMAND_START>{NL}"); |
366 | |
4323 | 367 BEGIN (INITIAL); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
368 input_line_number++; |
967 | 369 current_input_column = 1; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
370 |
2857 | 371 lexer_flags.quote_is_transpose = false; |
372 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
373 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
374 lexer_flags.at_beginning_of_statement = true; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
375 |
4910 | 376 COUNT_TOK_AND_RETURN ('\n'); |
967 | 377 } |
1 | 378 |
4208 | 379 <COMMAND_START>[\;\,] { |
8535 | 380 LEXER_DEBUG ("<COMMAND_START>[\\;\\,]"); |
381 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
382 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
383 lexer_flags.at_beginning_of_statement = true; |
5102 | 384 |
385 BEGIN (INITIAL); | |
386 | |
387 if (strcmp (yytext, ",") == 0) | |
388 TOK_RETURN (','); | |
967 | 389 else |
5102 | 390 TOK_RETURN (';'); |
967 | 391 } |
1 | 392 |
4208 | 393 <COMMAND_START>[\"\'] { |
8535 | 394 LEXER_DEBUG ("<COMMAND_START>[\\\"\\']"); |
395 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
396 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
397 |
975 | 398 current_input_column++; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
399 int tok = handle_string (yytext[0]); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
400 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
401 COUNT_TOK_AND_RETURN (tok); |
975 | 402 } |
403 | |
4923 | 404 <COMMAND_START>[^#% \t\r\n\;\,\"\'][^ \t\r\n\;\,]*{S}* { |
8535 | 405 LEXER_DEBUG ("<COMMAND_START>[^#% \\t\\r\\n\\;\\,\\\"\\'][^ \\t\\r\\n\\;\\,]*{S}*"); |
406 | |
3523 | 407 std::string tok = strip_trailing_whitespace (yytext); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
408 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
409 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
410 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
411 |
5279 | 412 TOK_PUSH_AND_RETURN (tok, SQ_STRING); |
967 | 413 } |
1 | 414 |
968 | 415 %{ |
1 | 416 // For this and the next two rules, we're looking at ']', and we |
971 | 417 // need to know if the next token is `=' or `=='. |
1 | 418 // |
419 // It would have been so much easier if the delimiters were simply | |
420 // different for the expression on the left hand side of the equals | |
421 // operator. | |
971 | 422 // |
423 // It's also a pain in the ass to decide whether to insert a comma | |
424 // after seeing a ']' character... | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
425 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
426 // FIXME -- we need to handle block comments here. |
968 | 427 %} |
428 | |
4208 | 429 <MATRIX_START>{SNLCMT}*\]{S}* { |
8535 | 430 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\]{S}*"); |
431 | |
3665 | 432 scan_for_comments (yytext); |
1001 | 433 fixup_column_count (yytext); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
434 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
435 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
436 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
437 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
438 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
439 |
1001 | 440 int c = yytext[yyleng-1]; |
441 int cont_is_spc = eat_continuation (); | |
4608 | 442 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); |
5345 | 443 int tok_to_return = handle_close_bracket (spc_gobbled, ']'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
444 |
5345 | 445 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
446 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
447 |
5345 | 448 COUNT_TOK_AND_RETURN (tok_to_return); |
4608 | 449 } |
450 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
451 %{ |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
452 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
453 %} |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
454 |
4608 | 455 <MATRIX_START>{SNLCMT}*\}{S}* { |
8535 | 456 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*\\}{S}*"); |
457 | |
4608 | 458 scan_for_comments (yytext); |
459 fixup_column_count (yytext); | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
460 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
461 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
462 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
463 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
464 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
465 |
4608 | 466 int c = yytext[yyleng-1]; |
467 int cont_is_spc = eat_continuation (); | |
468 bool spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | |
5345 | 469 int tok_to_return = handle_close_bracket (spc_gobbled, '}'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
470 |
5345 | 471 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
472 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
473 |
5345 | 474 COUNT_TOK_AND_RETURN (tok_to_return); |
967 | 475 } |
1 | 476 |
968 | 477 %{ |
1088 | 478 // Commas are element separators in matrix constants. If we don't |
479 // check for continuations here we can end up inserting too many | |
480 // commas. | |
968 | 481 %} |
482 | |
4208 | 483 <MATRIX_START>{S}*\,{S}* { |
8535 | 484 LEXER_DEBUG ("<MATRIX_START>{S}*\\,{S}*"); |
485 | |
1088 | 486 current_input_column += yyleng; |
3388 | 487 |
1088 | 488 int tmp = eat_continuation (); |
3388 | 489 |
2857 | 490 lexer_flags.quote_is_transpose = false; |
491 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
492 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
493 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
494 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
495 if (! lexer_flags.looking_at_object_index.front ()) |
3388 | 496 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
497 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
498 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
499 maybe_warn_separator_insert (';'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
500 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
501 xunput (';', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
502 } |
3388 | 503 } |
504 | |
4910 | 505 COUNT_TOK_AND_RETURN (','); |
967 | 506 } |
1 | 507 |
968 | 508 %{ |
509 // In some cases, spaces in matrix constants can turn into commas. | |
510 // If commas are required, spaces are not important in matrix | |
1088 | 511 // constants so we just eat them. If we don't check for continuations |
512 // here we can end up inserting too many commas. | |
968 | 513 %} |
430 | 514 |
4208 | 515 <MATRIX_START>{S}+ { |
8535 | 516 LEXER_DEBUG ("<MATRIX_START>{S}+"); |
517 | |
1088 | 518 current_input_column += yyleng; |
3388 | 519 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
520 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
521 |
3388 | 522 int tmp = eat_continuation (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
523 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
524 if (! lexer_flags.looking_at_object_index.front ()) |
967 | 525 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
526 bool bin_op = next_token_is_bin_op (true); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
527 bool postfix_un_op = next_token_is_postfix_unary_op (true); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
528 bool sep_op = next_token_is_sep_op (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
529 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
530 if (! (postfix_un_op || bin_op || sep_op) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
531 && nesting_level.is_bracket_or_brace () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
532 && lexer_flags.convert_spaces_to_comma) |
3388 | 533 { |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
534 if ((tmp & ATE_NEWLINE) == ATE_NEWLINE) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
535 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
536 maybe_warn_separator_insert (';'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
537 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
538 xunput (';', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
539 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
540 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
541 lexer_flags.quote_is_transpose = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
542 lexer_flags.convert_spaces_to_comma = true; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
543 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
544 maybe_warn_separator_insert (','); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
545 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
546 COUNT_TOK_AND_RETURN (','); |
3388 | 547 } |
967 | 548 } |
549 } | |
430 | 550 |
968 | 551 %{ |
1088 | 552 // Semicolons are handled as row seprators in matrix constants. If we |
553 // don't eat whitespace here we can end up inserting too many | |
554 // semicolons. | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
555 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
556 // FIXME -- we need to handle block comments here. |
968 | 557 %} |
558 | |
4208 | 559 <MATRIX_START>{SNLCMT}*;{SNLCMT}* { |
8535 | 560 LEXER_DEBUG ("<MATRIX_START>{SNLCMT}*;{SNLCMT}*"); |
561 | |
3665 | 562 scan_for_comments (yytext); |
967 | 563 fixup_column_count (yytext); |
1001 | 564 eat_whitespace (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
565 |
2857 | 566 lexer_flags.quote_is_transpose = false; |
567 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
568 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
569 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
570 |
4910 | 571 COUNT_TOK_AND_RETURN (';'); |
967 | 572 } |
573 | |
968 | 574 %{ |
1088 | 575 // In some cases, new lines can also become row separators. If we |
576 // don't eat whitespace here we can end up inserting too many | |
577 // semicolons. | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
578 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
579 // FIXME -- we need to handle block comments here. |
985 | 580 %} |
581 | |
4208 | 582 <MATRIX_START>{S}*{COMMENT}{SNLCMT}* | |
583 <MATRIX_START>{S}*{NL}{SNLCMT}* { | |
8535 | 584 LEXER_DEBUG ("<MATRIX_START>{S}*{COMMENT}{SNLCMT}*|<MATRIX_START>{S}*{NL}{SNLCMT}*"); |
585 | |
3665 | 586 scan_for_comments (yytext); |
1082 | 587 fixup_column_count (yytext); |
1088 | 588 eat_whitespace (); |
3388 | 589 |
4476 | 590 lexer_flags.quote_is_transpose = false; |
591 lexer_flags.convert_spaces_to_comma = true; | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
592 lexer_flags.at_beginning_of_statement = false; |
4476 | 593 |
594 if (nesting_level.none ()) | |
595 return LEXICAL_ERROR; | |
985 | 596 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
597 if (! lexer_flags.looking_at_object_index.front () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
598 && nesting_level.is_bracket_or_brace ()) |
3388 | 599 { |
600 maybe_warn_separator_insert (';'); | |
601 | |
4910 | 602 COUNT_TOK_AND_RETURN (';'); |
985 | 603 } |
604 } | |
605 | |
967 | 606 \[{S}* { |
8535 | 607 LEXER_DEBUG ("\\[{S}*"); |
608 | |
3351 | 609 nesting_level.bracket (); |
975 | 610 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
611 lexer_flags.looking_at_object_index.push_front (false); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
612 |
1082 | 613 current_input_column += yyleng; |
2857 | 614 lexer_flags.quote_is_transpose = false; |
615 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
616 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
617 lexer_flags.at_beginning_of_statement = false; |
975 | 618 |
5615 | 619 if (lexer_flags.defining_func && ! lexer_flags.parsed_function_name) |
620 lexer_flags.looking_at_return_list = true; | |
621 else | |
622 lexer_flags.looking_at_matrix_or_assign_lhs = true; | |
623 | |
975 | 624 promptflag--; |
625 eat_whitespace (); | |
626 | |
5102 | 627 lexer_flags.bracketflag++; |
628 BEGIN (MATRIX_START); | |
629 COUNT_TOK_AND_RETURN ('['); | |
967 | 630 } |
1 | 631 |
968 | 632 \] { |
8535 | 633 LEXER_DEBUG ("\\]"); |
634 | |
1826 | 635 nesting_level.remove (); |
968 | 636 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
637 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
638 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
639 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
640 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
641 |
5102 | 642 TOK_RETURN (']'); |
968 | 643 } |
644 | |
645 %{ | |
646 // Imaginary numbers. | |
647 %} | |
648 | |
649 {NUMBER}{Im} { | |
8535 | 650 LEXER_DEBUG ("{NUMBER}{Im}"); |
651 | |
3246 | 652 handle_number (); |
4910 | 653 COUNT_TOK_AND_RETURN (IMAG_NUM); |
968 | 654 } |
655 | |
656 %{ | |
657 // Real numbers. Don't grab the `.' part of a dot operator as part of | |
658 // the constant. | |
659 %} | |
660 | |
8535 | 661 {D}+/\.[\*/\\^\'] | |
968 | 662 {NUMBER} { |
8535 | 663 LEXER_DEBUG ("{D}+/\\.[\\*/\\^\\']|{NUMBER}"); |
3246 | 664 handle_number (); |
4910 | 665 COUNT_TOK_AND_RETURN (NUM); |
968 | 666 } |
667 | |
668 %{ | |
669 // Eat whitespace. Whitespace inside matrix constants is handled by | |
4208 | 670 // the <MATRIX_START> start state code above. |
968 | 671 %} |
672 | |
967 | 673 {S}* { |
674 current_input_column += yyleng; | |
675 } | |
676 | |
968 | 677 %{ |
678 // Continuation lines. Allow comments after continuations. | |
679 %} | |
680 | |
967 | 681 {CONT}{S}*{NL} | |
682 {CONT}{S}*{COMMENT} { | |
8535 | 683 LEXER_DEBUG ("{CONT}{S}*{NL}|{CONT}{S}*{COMMENT}"); |
684 | |
4037 | 685 if (yytext[0] == '\\') |
686 gripe_matlab_incompatible_continuation (); | |
3665 | 687 scan_for_comments (yytext); |
967 | 688 promptflag--; |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
689 input_line_number++; |
967 | 690 current_input_column = 1; |
691 } | |
1 | 692 |
968 | 693 %{ |
694 // End of file. | |
695 %} | |
696 | |
967 | 697 <<EOF>> { |
8535 | 698 LEXER_DEBUG ("<<EOF>>"); |
699 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
700 if (block_comment_nesting_level != 0) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
701 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
702 warning ("block comment open at end of input"); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
703 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
704 if ((reading_fcn_file || reading_script_file) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
705 && ! curr_fcn_file_name.empty ()) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
706 warning ("near line %d of file `%s.m'", |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
707 input_line_number, curr_fcn_file_name.c_str ()); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
708 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
709 |
967 | 710 TOK_RETURN (END_OF_INPUT); |
711 } | |
1 | 712 |
968 | 713 %{ |
970 | 714 // Identifiers. Truncate the token at the first space or tab but |
715 // don't write directly on yytext. | |
968 | 716 %} |
717 | |
967 | 718 {IDENT}{S}* { |
8535 | 719 LEXER_DEBUG ("{IDENT}{S}*"); |
720 | |
4238 | 721 int id_tok = handle_identifier (); |
722 | |
723 if (id_tok >= 0) | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
724 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
725 lexer_flags.looking_for_object_index = true; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
726 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
727 COUNT_TOK_AND_RETURN (id_tok); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
728 } |
967 | 729 } |
1 | 730 |
968 | 731 %{ |
4342 | 732 // Function handles. |
733 %} | |
734 | |
4930 | 735 "@" { |
8535 | 736 LEXER_DEBUG ("@"); |
737 | |
4930 | 738 current_input_column++; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
739 |
4930 | 740 lexer_flags.quote_is_transpose = false; |
741 lexer_flags.convert_spaces_to_comma = false; | |
742 lexer_flags.looking_at_function_handle++; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
743 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
744 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
745 |
4930 | 746 COUNT_TOK_AND_RETURN ('@'); |
4342 | 747 } |
748 | |
749 %{ | |
968 | 750 // A new line character. New line characters inside matrix constants |
4208 | 751 // are handled by the <MATRIX_START> start state code above. If closest |
985 | 752 // nesting is inside parentheses, don't return a row separator. |
968 | 753 %} |
754 | |
967 | 755 {NL} { |
8535 | 756 LEXER_DEBUG ("{NL}"); |
757 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
758 input_line_number++; |
967 | 759 current_input_column = 1; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
760 |
2857 | 761 lexer_flags.quote_is_transpose = false; |
762 lexer_flags.convert_spaces_to_comma = true; | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
763 |
1826 | 764 if (nesting_level.none ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
765 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
766 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
767 COUNT_TOK_AND_RETURN ('\n'); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
768 } |
4037 | 769 else if (nesting_level.is_paren ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
770 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
771 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
772 gripe_matlab_incompatible ("bare newline inside parentheses"); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
773 } |
4608 | 774 else if (nesting_level.is_bracket_or_brace ()) |
985 | 775 return LEXICAL_ERROR; |
967 | 776 } |
1 | 777 |
968 | 778 %{ |
779 // Single quote can either be the beginning of a string or a transpose | |
780 // operator. | |
781 %} | |
782 | |
967 | 783 "'" { |
8535 | 784 LEXER_DEBUG ("'"); |
785 | |
967 | 786 current_input_column++; |
2857 | 787 lexer_flags.convert_spaces_to_comma = true; |
1 | 788 |
1826 | 789 if (lexer_flags.quote_is_transpose) |
967 | 790 { |
791 do_comma_insert_check (); | |
4910 | 792 COUNT_TOK_AND_RETURN (QUOTE); |
967 | 793 } |
794 else | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
795 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
796 int tok = handle_string ('\''); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
797 COUNT_TOK_AND_RETURN (tok); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
798 } |
967 | 799 } |
1 | 800 |
968 | 801 %{ |
971 | 802 // Double quotes always begin strings. |
803 %} | |
804 | |
973 | 805 \" { |
8535 | 806 LEXER_DEBUG ("\""); |
807 | |
973 | 808 current_input_column++; |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
809 int tok = handle_string ('"'); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
810 |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
811 COUNT_TOK_AND_RETURN (tok); |
973 | 812 } |
971 | 813 |
814 %{ | |
8536
de1b944d5306
lex.l: finish previous change
John W. Eaton <jwe@octave.org>
parents:
8535
diff
changeset
|
815 // Gobble comments. |
985 | 816 %} |
968 | 817 |
967 | 818 {CCHAR} { |
8535 | 819 LEXER_DEBUG ("{CCHAR}"); |
820 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
821 lexer_flags.looking_for_object_index = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
822 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
823 xunput (yytext[0], yytext); |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
824 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
825 bool eof = false; |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
826 int tok = process_comment (false, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
827 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
828 if (eof) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
829 TOK_RETURN (END_OF_INPUT); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
830 else if (tok > 0) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
831 COUNT_TOK_AND_RETURN (tok); |
967 | 832 } |
440 | 833 |
968 | 834 %{ |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
835 // Block comments. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
836 %} |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
837 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
838 ^{S}*{CCHAR}\{{S}*{NL} { |
8535 | 839 LEXER_DEBUG ("^{S}*{CCHAR}\\{{S}*{NL}"); |
840 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
841 lexer_flags.looking_for_object_index = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
842 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
843 input_line_number++; |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
844 current_input_column = 1; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
845 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
846 promptflag--; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
847 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
848 bool eof = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
849 process_comment (true, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
850 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
851 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
852 %{ |
968 | 853 // Other operators. |
854 %} | |
855 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
856 ":" { LEXER_DEBUG (":"); BIN_OP_RETURN (':', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
857 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
858 ".+" { LEXER_DEBUG (".+"); XBIN_OP_RETURN (EPLUS, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
859 ".-" { LEXER_DEBUG (".-"); XBIN_OP_RETURN (EMINUS, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
860 ".*" { LEXER_DEBUG (".*"); BIN_OP_RETURN (EMUL, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
861 "./" { LEXER_DEBUG ("./"); BIN_OP_RETURN (EDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
862 ".\\" { LEXER_DEBUG (".\\"); BIN_OP_RETURN (ELEFTDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
863 ".^" { LEXER_DEBUG (".^"); BIN_OP_RETURN (EPOW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
864 ".**" { LEXER_DEBUG (".**"); XBIN_OP_RETURN (EPOW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
865 ".'" { LEXER_DEBUG (".'"); do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
866 "++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
867 "--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
868 "<=" { LEXER_DEBUG ("<="); BIN_OP_RETURN (EXPR_LE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
869 "==" { LEXER_DEBUG ("=="); BIN_OP_RETURN (EXPR_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
870 "~=" { LEXER_DEBUG ("~="); BIN_OP_RETURN (EXPR_NE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
871 "!=" { LEXER_DEBUG ("!="); XBIN_OP_RETURN (EXPR_NE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
872 ">=" { LEXER_DEBUG (">="); BIN_OP_RETURN (EXPR_GE, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
873 "&" { LEXER_DEBUG ("&"); BIN_OP_RETURN (EXPR_AND, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
874 "|" { LEXER_DEBUG ("|"); BIN_OP_RETURN (EXPR_OR, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
875 "<" { LEXER_DEBUG ("<"); BIN_OP_RETURN (EXPR_LT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
876 ">" { LEXER_DEBUG (">"); BIN_OP_RETURN (EXPR_GT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
877 "+" { LEXER_DEBUG ("+"); BIN_OP_RETURN ('+', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
878 "-" { LEXER_DEBUG ("-"); BIN_OP_RETURN ('-', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
879 "*" { LEXER_DEBUG ("*"); BIN_OP_RETURN ('*', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
880 "/" { LEXER_DEBUG ("/"); BIN_OP_RETURN ('/', false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
881 "\\" { LEXER_DEBUG ("\\"); BIN_OP_RETURN (LEFTDIV, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
882 ";" { LEXER_DEBUG (";"); BIN_OP_RETURN (';', true, true); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
883 "," { LEXER_DEBUG (","); BIN_OP_RETURN (',', true, ! lexer_flags.looking_at_object_index.front ()); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
884 "^" { LEXER_DEBUG ("^"); BIN_OP_RETURN (POW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
885 "**" { LEXER_DEBUG ("**"); XBIN_OP_RETURN (POW, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
886 "=" { LEXER_DEBUG ("="); BIN_OP_RETURN ('=', true, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
887 "&&" { LEXER_DEBUG ("&&"); BIN_OP_RETURN (EXPR_AND_AND, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
888 "||" { LEXER_DEBUG ("||"); BIN_OP_RETURN (EXPR_OR_OR, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
889 "<<" { LEXER_DEBUG ("<<"); XBIN_OP_RETURN (LSHIFT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
890 ">>" { LEXER_DEBUG (">>"); XBIN_OP_RETURN (RSHIFT, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
891 |
967 | 892 |
893 {NOT} { | |
8535 | 894 LEXER_DEBUG ("{NOT}"); |
895 | |
4037 | 896 if (yytext[0] == '~') |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
897 BIN_OP_RETURN (EXPR_NOT, false, false); |
4037 | 898 else |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
899 XBIN_OP_RETURN (EXPR_NOT, false, false); |
967 | 900 } |
1 | 901 |
967 | 902 "(" { |
8535 | 903 LEXER_DEBUG ("("); |
904 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
905 // If we are looking for an object index, then push TRUE for |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
906 // looking_at_object_index. Otherwise, just push whatever state |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
907 // is current (so that we can pop it off the stack when we find |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
908 // the matching close paren). |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
909 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
910 lexer_flags.looking_at_object_index.push_front |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
911 (lexer_flags.looking_for_object_index); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
912 |
4131 | 913 lexer_flags.looking_at_indirect_ref = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
914 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
915 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
916 |
1826 | 917 nesting_level.paren (); |
985 | 918 promptflag--; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
919 |
967 | 920 TOK_RETURN ('('); |
921 } | |
922 | |
923 ")" { | |
8535 | 924 LEXER_DEBUG (")"); |
925 | |
1826 | 926 nesting_level.remove (); |
967 | 927 current_input_column++; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
928 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
929 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
930 |
2857 | 931 lexer_flags.quote_is_transpose = true; |
4608 | 932 lexer_flags.convert_spaces_to_comma = nesting_level.is_bracket_or_brace (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
933 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
934 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
935 |
1001 | 936 do_comma_insert_check (); |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
937 |
4910 | 938 COUNT_TOK_AND_RETURN (')'); |
967 | 939 } |
940 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
941 "." { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
942 LEXER_DEBUG ("."); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
943 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
944 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
945 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
946 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
947 TOK_RETURN ('.'); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
948 } |
8535 | 949 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
950 "+=" { LEXER_DEBUG ("+="); XBIN_OP_RETURN (ADD_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
951 "-=" { LEXER_DEBUG ("-="); XBIN_OP_RETURN (SUB_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
952 "*=" { LEXER_DEBUG ("*="); XBIN_OP_RETURN (MUL_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
953 "/=" { LEXER_DEBUG ("/="); XBIN_OP_RETURN (DIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
954 "\\=" { LEXER_DEBUG ("\\="); XBIN_OP_RETURN (LEFTDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
955 ".+=" { LEXER_DEBUG (".+="); XBIN_OP_RETURN (ADD_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
956 ".-=" { LEXER_DEBUG (".-="); XBIN_OP_RETURN (SUB_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
957 ".*=" { LEXER_DEBUG (".*="); XBIN_OP_RETURN (EMUL_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
958 "./=" { LEXER_DEBUG ("./="); XBIN_OP_RETURN (EDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
959 ".\\=" { LEXER_DEBUG (".\\="); XBIN_OP_RETURN (ELEFTDIV_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
960 {POW}= { LEXER_DEBUG ("{POW}="); XBIN_OP_RETURN (POW_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
961 {EPOW}= { LEXER_DEBUG ("{EPOW}="); XBIN_OP_RETURN (EPOW_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
962 "&=" { LEXER_DEBUG ("&="); XBIN_OP_RETURN (AND_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
963 "|=" { LEXER_DEBUG ("|="); XBIN_OP_RETURN (OR_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
964 "<<=" { LEXER_DEBUG ("<<="); XBIN_OP_RETURN (LSHIFT_EQ, false, false); } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
965 ">>=" { LEXER_DEBUG (">>="); XBIN_OP_RETURN (RSHIFT_EQ, false, false); } |
2877 | 966 |
4608 | 967 \{{S}* { |
8535 | 968 LEXER_DEBUG ("\\{{S}*"); |
969 | |
3351 | 970 nesting_level.brace (); |
4608 | 971 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
972 lexer_flags.looking_at_object_index.push_front |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
973 (lexer_flags.looking_for_object_index); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
974 |
4608 | 975 current_input_column += yyleng; |
976 lexer_flags.quote_is_transpose = false; | |
977 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
978 lexer_flags.looking_for_object_index = false; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
979 lexer_flags.at_beginning_of_statement = false; |
4608 | 980 |
3351 | 981 promptflag--; |
4608 | 982 eat_whitespace (); |
983 | |
4613 | 984 lexer_flags.braceflag++; |
4608 | 985 BEGIN (MATRIX_START); |
4910 | 986 COUNT_TOK_AND_RETURN ('{'); |
3351 | 987 } |
988 | |
989 "}" { | |
8535 | 990 LEXER_DEBUG ("}"); |
991 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
992 lexer_flags.looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
993 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
994 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
995 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
996 |
3351 | 997 nesting_level.remove (); |
998 | |
4608 | 999 TOK_RETURN ('}'); |
3351 | 1000 } |
1001 | |
968 | 1002 %{ |
2066 | 1003 // Unrecognized input is a lexical error. |
968 | 1004 %} |
1 | 1005 |
2042 | 1006 . { |
8535 | 1007 LEXER_DEBUG ("."); |
1008 | |
4240 | 1009 // EOF happens here if we are parsing nested functions. |
1010 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1011 xunput (yytext[0], yytext); |
4248 | 1012 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1013 int c = text_yyinput (); |
4248 | 1014 |
1015 if (c != EOF) | |
4240 | 1016 { |
1017 current_input_column++; | |
1018 | |
1019 error ("invalid character `%s' (ASCII %d) near line %d, column %d", | |
4248 | 1020 undo_string_escape (static_cast<char> (c)), c, |
4240 | 1021 input_line_number, current_input_column); |
1022 | |
1023 return LEXICAL_ERROR; | |
1024 } | |
1025 else | |
1026 TOK_RETURN (END_OF_INPUT); | |
2066 | 1027 } |
1 | 1028 |
1029 %% | |
1030 | |
767 | 1031 // GAG. |
1032 // | |
1033 // If we're reading a matrix and the next character is '[', make sure | |
1034 // that we insert a comma ahead of it. | |
1035 | |
146 | 1036 void |
1 | 1037 do_comma_insert_check (void) |
1038 { | |
1001 | 1039 int spc_gobbled = eat_continuation (); |
2970 | 1040 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1041 int c = text_yyinput (); |
2970 | 1042 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1043 xunput (c, yytext); |
2970 | 1044 |
1001 | 1045 if (spc_gobbled) |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1046 xunput (' ', yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1047 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1048 lexer_flags.do_comma_insert = (! lexer_flags.looking_at_object_index.front () |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1049 && lexer_flags.bracketflag && c == '['); |
1 | 1050 } |
1051 | |
767 | 1052 // Fix things up for errors or interrupts. The parser is never called |
1053 // recursively, so it is always safe to reinitialize its state before | |
1054 // doing any parsing. | |
1055 | |
1 | 1056 void |
1057 reset_parser (void) | |
1058 { | |
1826 | 1059 // Start off on the right foot. |
4323 | 1060 BEGIN (INITIAL); |
4318 | 1061 |
3883 | 1062 parser_end_of_input = false; |
4238 | 1063 end_tokens_expected = 0; |
1064 | |
1065 while (! symtab_context.empty ()) | |
1066 symtab_context.pop (); | |
287 | 1067 |
7336 | 1068 symbol_table::reset_parent_scope (); |
1069 | |
1826 | 1070 // We do want a prompt by default. |
1 | 1071 promptflag = 1; |
287 | 1072 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1073 // We are not in a block comment. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1074 block_comment_nesting_level = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1075 |
3351 | 1076 // Error may have occurred inside some brackets, braces, or parentheses. |
985 | 1077 nesting_level.clear (); |
287 | 1078 |
1826 | 1079 // Clear out the stack of token info used to track line and column |
1080 // numbers. | |
143 | 1081 while (! token_stack.empty ()) |
4214 | 1082 { |
1083 delete token_stack.top (); | |
1084 token_stack.pop (); | |
1085 } | |
287 | 1086 |
1826 | 1087 // Can be reset by defining a function. |
985 | 1088 if (! (reading_script_file || reading_fcn_file)) |
1089 { | |
1090 current_input_column = 1; | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1091 input_line_number = command_editor::current_command_number (); |
985 | 1092 } |
287 | 1093 |
1826 | 1094 // Only ask for input from stdin if we are expecting interactive |
1095 // input. | |
3174 | 1096 if ((interactive || forced_interactive) |
3880 | 1097 && ! (reading_fcn_file |
1098 || reading_script_file | |
1099 || get_input_from_eval_string | |
3174 | 1100 || input_from_startup_file)) |
287 | 1101 yyrestart (stdin); |
991 | 1102 |
1826 | 1103 // Clear the buffer for help text. |
4426 | 1104 while (! help_buf.empty ()) |
1105 help_buf.pop (); | |
1755 | 1106 |
1826 | 1107 // Reset other flags. |
1108 lexer_flags.init (); | |
1 | 1109 } |
1110 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1111 static void |
8535 | 1112 display_character (char c) |
1113 { | |
1114 if (isgraph (c)) | |
1115 std::cerr << c; | |
1116 else | |
1117 switch (c) | |
1118 { | |
1119 case 0: | |
1120 std::cerr << "NUL"; | |
1121 break; | |
1122 | |
1123 case 1: | |
1124 std::cerr << "SOH"; | |
1125 break; | |
1126 | |
1127 case 2: | |
1128 std::cerr << "STX"; | |
1129 break; | |
1130 | |
1131 case 3: | |
1132 std::cerr << "ETX"; | |
1133 break; | |
1134 | |
1135 case 4: | |
1136 std::cerr << "EOT"; | |
1137 break; | |
1138 | |
1139 case 5: | |
1140 std::cerr << "ENQ"; | |
1141 break; | |
1142 | |
1143 case 6: | |
1144 std::cerr << "ACK"; | |
1145 break; | |
1146 | |
1147 case 7: | |
1148 std::cerr << "\\a"; | |
1149 break; | |
1150 | |
1151 case 8: | |
1152 std::cerr << "\\b"; | |
1153 break; | |
1154 | |
1155 case 9: | |
1156 std::cerr << "\\t"; | |
1157 break; | |
1158 | |
1159 case 10: | |
1160 std::cerr << "\\n"; | |
1161 break; | |
1162 | |
1163 case 11: | |
1164 std::cerr << "\\v"; | |
1165 break; | |
1166 | |
1167 case 12: | |
1168 std::cerr << "\\f"; | |
1169 break; | |
1170 | |
1171 case 13: | |
1172 std::cerr << "\\r"; | |
1173 break; | |
1174 | |
1175 case 14: | |
1176 std::cerr << "SO"; | |
1177 break; | |
1178 | |
1179 case 15: | |
1180 std::cerr << "SI"; | |
1181 break; | |
1182 | |
1183 case 16: | |
1184 std::cerr << "DLE"; | |
1185 break; | |
1186 | |
1187 case 17: | |
1188 std::cerr << "DC1"; | |
1189 break; | |
1190 | |
1191 case 18: | |
1192 std::cerr << "DC2"; | |
1193 break; | |
1194 | |
1195 case 19: | |
1196 std::cerr << "DC3"; | |
1197 break; | |
1198 | |
1199 case 20: | |
1200 std::cerr << "DC4"; | |
1201 break; | |
1202 | |
1203 case 21: | |
1204 std::cerr << "NAK"; | |
1205 break; | |
1206 | |
1207 case 22: | |
1208 std::cerr << "SYN"; | |
1209 break; | |
1210 | |
1211 case 23: | |
1212 std::cerr << "ETB"; | |
1213 break; | |
1214 | |
1215 case 24: | |
1216 std::cerr << "CAN"; | |
1217 break; | |
1218 | |
1219 case 25: | |
1220 std::cerr << "EM"; | |
1221 break; | |
1222 | |
1223 case 26: | |
1224 std::cerr << "SUB"; | |
1225 break; | |
1226 | |
1227 case 27: | |
1228 std::cerr << "ESC"; | |
1229 break; | |
1230 | |
1231 case 28: | |
1232 std::cerr << "FS"; | |
1233 break; | |
1234 | |
1235 case 29: | |
1236 std::cerr << "GS"; | |
1237 break; | |
1238 | |
1239 case 30: | |
1240 std::cerr << "RS"; | |
1241 break; | |
1242 | |
1243 case 31: | |
1244 std::cerr << "US"; | |
1245 break; | |
1246 | |
1247 case 32: | |
1248 std::cerr << "SPACE"; | |
1249 break; | |
1250 | |
1251 case 127: | |
1252 std::cerr << "DEL"; | |
1253 break; | |
1254 } | |
1255 } | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1256 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1257 static int |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1258 text_yyinput (void) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1259 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1260 int c = yyinput (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1261 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1262 if (lexer_debug_flag) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1263 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1264 std::cerr << "I: "; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1265 display_character (c); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1266 std::cerr << std::endl; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1267 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1268 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1269 // Convert CRLF into just LF and single CR into LF. |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1270 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1271 if (c == '\r') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1272 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1273 c = yyinput (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1274 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1275 if (lexer_debug_flag) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1276 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1277 std::cerr << "I: "; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1278 display_character (c); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1279 std::cerr << std::endl; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1280 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1281 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1282 if (c != '\n') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1283 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1284 xunput (c, yytext); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1285 c = '\n'; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1286 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1287 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1288 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1289 if (c == '\n') |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1290 input_line_number++; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1291 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1292 return c; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1293 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1294 |
8535 | 1295 static void |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1296 xunput (char c, char *buf) |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1297 { |
8535 | 1298 if (lexer_debug_flag) |
1299 { | |
1300 std::cerr << "U: "; | |
1301 display_character (c); | |
1302 std::cerr << std::endl; | |
1303 } | |
1304 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1305 if (c == '\n') |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1306 input_line_number--; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1307 |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1308 yyunput (c, buf); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1309 } |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1310 |
767 | 1311 // If we read some newlines, we need figure out what column we're |
1312 // really looking at. | |
1313 | |
1 | 1314 static void |
1315 fixup_column_count (char *s) | |
1316 { | |
1317 char c; | |
1318 while ((c = *s++) != '\0') | |
1319 { | |
1320 if (c == '\n') | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1321 { |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1322 input_line_number++; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1323 current_input_column = 1; |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1324 } |
1 | 1325 else |
1326 current_input_column++; | |
1327 } | |
1328 } | |
1329 | |
767 | 1330 // Include these so that we don't have to link to libfl.a. |
246 | 1331 |
3332 | 1332 int |
1 | 1333 yywrap (void) |
1334 { | |
287 | 1335 return 1; |
1 | 1336 } |
1337 | |
767 | 1338 // Tell us all what the current buffer is. |
1339 | |
1 | 1340 YY_BUFFER_STATE |
1341 current_buffer (void) | |
1342 { | |
1343 return YY_CURRENT_BUFFER; | |
1344 } | |
1345 | |
767 | 1346 // Create a new buffer. |
1347 | |
1 | 1348 YY_BUFFER_STATE |
1349 create_buffer (FILE *f) | |
1350 { | |
1351 return yy_create_buffer (f, YY_BUF_SIZE); | |
1352 } | |
1353 | |
767 | 1354 // Start reading a new buffer. |
1355 | |
1 | 1356 void |
1357 switch_to_buffer (YY_BUFFER_STATE buf) | |
1358 { | |
1359 yy_switch_to_buffer (buf); | |
1360 } | |
1361 | |
767 | 1362 // Delete a buffer. |
1363 | |
1 | 1364 void |
1365 delete_buffer (YY_BUFFER_STATE buf) | |
1366 { | |
1367 yy_delete_buffer (buf); | |
1368 } | |
1369 | |
767 | 1370 // Restore a buffer (for unwind-prot). |
1371 | |
1 | 1372 void |
1373 restore_input_buffer (void *buf) | |
1374 { | |
2861 | 1375 switch_to_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1 | 1376 } |
1377 | |
767 | 1378 // Delete a buffer (for unwind-prot). |
1379 | |
1 | 1380 void |
1381 delete_input_buffer (void *buf) | |
1382 { | |
2861 | 1383 delete_buffer (static_cast<YY_BUFFER_STATE> (buf)); |
1 | 1384 } |
1385 | |
4238 | 1386 static void |
1387 prep_for_function (void) | |
1388 { | |
1389 end_tokens_expected++; | |
1390 | |
1391 promptflag--; | |
1392 | |
1393 lexer_flags.defining_func = true; | |
1394 lexer_flags.parsed_function_name = false; | |
1395 | |
1396 if (! (reading_fcn_file || reading_script_file)) | |
1397 input_line_number = 1; | |
1398 } | |
1399 | |
1400 static void | |
1401 prep_for_nested_function (void) | |
1402 { | |
4240 | 1403 lexer_flags.parsing_nested_function = 1; |
4426 | 1404 help_buf.push (std::string ()); |
4238 | 1405 prep_for_function (); |
4240 | 1406 // We're still only expecting one end token for this set of functions. |
1407 end_tokens_expected--; | |
4238 | 1408 yylval.tok_val = new token (input_line_number, current_input_column); |
1409 token_stack.push (yylval.tok_val); | |
1410 } | |
1411 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1412 static bool |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1413 inside_any_object_index (void) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1414 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1415 bool retval = false; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1416 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1417 for (std::list<bool>::const_iterator i = lexer_flags.looking_at_object_index.begin (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1418 i != lexer_flags.looking_at_object_index.end (); i++) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1419 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1420 if (*i) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1421 { |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1422 retval = true; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1423 break; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1424 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1425 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1426 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1427 return retval; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1428 } |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1429 |
4238 | 1430 // Handle keywords. Return -1 if the keyword should be ignored. |
767 | 1431 |
1 | 1432 static int |
4867 | 1433 is_keyword_token (const std::string& s) |
1 | 1434 { |
3805 | 1435 int l = input_line_number; |
1436 int c = current_input_column; | |
1437 | |
1823 | 1438 int len = s.length (); |
922 | 1439 |
5088 | 1440 const octave_kw *kw = octave_kw_hash::in_word_set (s.c_str (), len); |
191 | 1441 |
1497 | 1442 if (kw) |
143 | 1443 { |
1497 | 1444 yylval.tok_val = 0; |
1445 | |
1446 switch (kw->kw_id) | |
1447 { | |
1448 case break_kw: | |
1449 case catch_kw: | |
1450 case continue_kw: | |
1451 case else_kw: | |
2764 | 1452 case otherwise_kw: |
1497 | 1453 case return_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1454 case unwind_protect_cleanup_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1455 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1456 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1457 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1458 case case_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1459 case elseif_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1460 case global_kw: |
2846 | 1461 case static_kw: |
3484 | 1462 case until_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1463 break; |
1497 | 1464 |
1465 case end_kw: | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
1466 if (inside_any_object_index () |
8136
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1467 || (lexer_flags.defining_func |
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1468 && ! (lexer_flags.looking_at_return_list |
2b2ca62f8ab6
dispatch to user-defined end function for classes if one is defined
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
1469 || lexer_flags.parsed_function_name))) |
4234 | 1470 return 0; |
1471 else | |
4238 | 1472 { |
1473 if (reading_fcn_file && end_tokens_expected == 1) | |
1474 return -1; | |
1475 else | |
1476 { | |
1477 yylval.tok_val = new token (token::simple_end, l, c); | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1478 lexer_flags.at_beginning_of_statement = true; |
4238 | 1479 end_tokens_expected--; |
1480 } | |
1481 } | |
1497 | 1482 break; |
1483 | |
1484 case end_try_catch_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1485 yylval.tok_val = new token (token::try_catch_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1486 lexer_flags.at_beginning_of_statement = true; |
4238 | 1487 end_tokens_expected--; |
1497 | 1488 break; |
1489 | |
1490 case end_unwind_protect_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1491 yylval.tok_val = new token (token::unwind_protect_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1492 lexer_flags.at_beginning_of_statement = true; |
4238 | 1493 end_tokens_expected--; |
1497 | 1494 break; |
1495 | |
1496 case endfor_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1497 yylval.tok_val = new token (token::for_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1498 lexer_flags.at_beginning_of_statement = true; |
4238 | 1499 end_tokens_expected--; |
1497 | 1500 break; |
1501 | |
1502 case endfunction_kw: | |
4238 | 1503 { |
1504 if (reading_fcn_file && end_tokens_expected == 1) | |
1505 return -1; | |
1506 else | |
1507 { | |
1508 yylval.tok_val = new token (token::function_end, l, c); | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1509 lexer_flags.at_beginning_of_statement = true; |
4238 | 1510 end_tokens_expected--; |
1511 } | |
1512 } | |
1497 | 1513 break; |
1514 | |
1515 case endif_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1516 yylval.tok_val = new token (token::if_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1517 lexer_flags.at_beginning_of_statement = true; |
4238 | 1518 end_tokens_expected--; |
1497 | 1519 break; |
1520 | |
2764 | 1521 case endswitch_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1522 yylval.tok_val = new token (token::switch_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1523 lexer_flags.at_beginning_of_statement = true; |
4238 | 1524 end_tokens_expected--; |
2764 | 1525 break; |
1526 | |
1497 | 1527 case endwhile_kw: |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1528 yylval.tok_val = new token (token::while_end, l, c); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1529 lexer_flags.at_beginning_of_statement = true; |
4238 | 1530 end_tokens_expected--; |
1497 | 1531 break; |
1532 | |
1533 case for_kw: | |
1534 case while_kw: | |
4238 | 1535 end_tokens_expected++; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1536 promptflag--; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1537 lexer_flags.looping++; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1538 break; |
4238 | 1539 |
1540 case do_kw: | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1541 lexer_flags.at_beginning_of_statement = true; |
1497 | 1542 promptflag--; |
1826 | 1543 lexer_flags.looping++; |
1497 | 1544 break; |
1545 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1546 case try_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1547 case unwind_protect_kw: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1548 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1549 end_tokens_expected++; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1550 promptflag--; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1551 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1552 |
1497 | 1553 case if_kw: |
2764 | 1554 case switch_kw: |
4238 | 1555 end_tokens_expected++; |
1497 | 1556 promptflag--; |
1557 break; | |
1558 | |
1559 case function_kw: | |
4238 | 1560 { |
1561 if (lexer_flags.defining_func) | |
1562 { | |
1563 if (reading_fcn_file) | |
1564 { | |
1565 if (lexer_flags.parsing_nested_function) | |
1566 { | |
4323 | 1567 BEGIN (NESTED_FUNCTION_END); |
4240 | 1568 |
4238 | 1569 yylval.tok_val = new token (token::function_end, l, c); |
4240 | 1570 token_stack.push (yylval.tok_val); |
1571 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1572 lexer_flags.at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1573 |
4240 | 1574 return END; |
4238 | 1575 } |
1576 else | |
1577 { | |
1578 prep_for_nested_function (); | |
4240 | 1579 |
4238 | 1580 return FCN; |
1581 } | |
1582 } | |
1583 else | |
1584 { | |
1585 error ("nested functions not implemented in this context"); | |
1586 | |
1587 if ((reading_fcn_file || reading_script_file) | |
1588 && ! curr_fcn_file_name.empty ()) | |
1589 error ("near line %d of file `%s.m'", | |
1590 input_line_number, curr_fcn_file_name.c_str ()); | |
1591 else | |
1592 error ("near line %d", input_line_number); | |
1593 | |
1594 return LEXICAL_ERROR; | |
1595 } | |
1596 } | |
1597 else | |
1598 prep_for_function (); | |
1599 } | |
1497 | 1600 break; |
1601 | |
3174 | 1602 case magic_file_kw: |
1603 { | |
1604 if ((reading_fcn_file || reading_script_file) | |
1605 && ! curr_fcn_file_full_name.empty ()) | |
1606 yylval.tok_val = new token (curr_fcn_file_full_name, l, c); | |
1607 else | |
1608 yylval.tok_val = new token ("stdin", l, c); | |
1609 } | |
1610 break; | |
1611 | |
1612 case magic_line_kw: | |
1613 yylval.tok_val = new token (static_cast<double> (l), "", l, c); | |
1614 break; | |
1615 | |
1497 | 1616 default: |
1617 panic_impossible (); | |
1618 } | |
1619 | |
1620 if (! yylval.tok_val) | |
1621 yylval.tok_val = new token (l, c); | |
1622 | |
476 | 1623 token_stack.push (yylval.tok_val); |
1497 | 1624 |
1625 return kw->tok; | |
143 | 1626 } |
1 | 1627 |
1628 return 0; | |
1629 } | |
1630 | |
2702 | 1631 static bool |
3523 | 1632 is_variable (const std::string& name) |
2702 | 1633 { |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1634 return (symbol_table::is_variable (name) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1635 || (lexer_flags.pending_local_variables.find (name) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1636 != lexer_flags.pending_local_variables.end ())); |
2702 | 1637 } |
1638 | |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
1639 void |
3523 | 1640 force_local_variable (const std::string& name) |
2702 | 1641 { |
7336 | 1642 octave_value& val = symbol_table::varref (name); |
1643 | |
1644 if (! val.is_defined ()) | |
1645 val = Matrix (); | |
2702 | 1646 } |
1647 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1648 static std::string |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1649 grab_block_comment (stream_reader& reader, bool& eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1650 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1651 std::string buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1652 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1653 bool at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1654 bool look_for_marker = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1655 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1656 bool warned_incompatible = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1657 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1658 int c = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1659 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1660 while ((c = reader.getc ()) != EOF) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1661 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1662 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1663 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1664 if (look_for_marker) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1665 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1666 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1667 look_for_marker = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1668 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1669 if (c == '{' || c == '}') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1670 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1671 std::string tmp_buf (1, static_cast<char> (c)); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1672 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1673 int type = c; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1674 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1675 bool done = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1676 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1677 while ((c = reader.getc ()) != EOF && ! done) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1678 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1679 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1680 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1681 switch (c) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1682 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1683 case ' ': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1684 case '\t': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1685 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1686 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1687 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1688 case '\n': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1689 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1690 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1691 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1692 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1693 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1694 if (type == '{') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1695 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1696 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1697 promptflag--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1698 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1699 else |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1700 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1701 block_comment_nesting_level--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1702 promptflag++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1703 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1704 if (block_comment_nesting_level == 0) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1705 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1706 buf += grab_comment_block (reader, true, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1707 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1708 return buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1709 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1710 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1711 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1712 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1713 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1714 default: |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1715 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1716 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1717 buf += tmp_buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1718 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1719 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1720 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1721 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1722 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1723 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1724 |
7898
cce16b4e0970
lex.l (grab_block_comment): Use parens around || expression within && expression
John W. Eaton <jwe@octave.org>
parents:
7728
diff
changeset
|
1725 if (at_bol && (c == '%' || c == '#')) |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1726 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1727 if (c == '#' && ! warned_incompatible) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1728 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1729 warned_incompatible = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1730 maybe_gripe_matlab_incompatible_comment (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1731 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1732 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1733 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1734 look_for_marker = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1735 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1736 else |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1737 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1738 buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1739 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1740 if (c == '\n') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1741 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1742 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1743 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1744 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1745 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1746 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1747 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1748 if (c == EOF) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1749 eof = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1750 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1751 return buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1752 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1753 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1754 std::string |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1755 grab_comment_block (stream_reader& reader, bool at_bol, |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1756 bool& eof) |
1 | 1757 { |
4426 | 1758 std::string buf; |
1019 | 1759 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1760 // TRUE means we are at the beginning of a comment block. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1761 bool begin_comment = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1762 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1763 // TRUE means we are currently reading a comment block. |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1764 bool in_comment = false; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1765 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1766 bool warned_incompatible = false; |
3665 | 1767 |
1019 | 1768 int c = 0; |
1 | 1769 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1770 while ((c = reader.getc ()) != EOF) |
1019 | 1771 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1772 current_input_column++; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1773 |
2300 | 1774 if (begin_comment) |
1775 { | |
1776 if (c == '%' || c == '#') | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1777 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1778 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1779 continue; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1780 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1781 else if (at_bol && c == '{') |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1782 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1783 std::string tmp_buf (1, static_cast<char> (c)); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1784 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1785 bool done = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1786 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1787 while ((c = reader.getc ()) != EOF && ! done) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1788 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1789 current_input_column++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1790 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1791 switch (c) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1792 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1793 case ' ': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1794 case '\t': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1795 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1796 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1797 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1798 case '\n': |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1799 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1800 current_input_column = 0; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1801 at_bol = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1802 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1803 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1804 block_comment_nesting_level++; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1805 promptflag--; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1806 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1807 buf += grab_block_comment (reader, eof); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1808 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1809 in_comment = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1810 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1811 if (eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1812 goto done; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1813 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1814 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1815 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1816 default: |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1817 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1818 tmp_buf += static_cast<char> (c); |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1819 buf += tmp_buf; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1820 done = true; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1821 break; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1822 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1823 } |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1824 } |
2300 | 1825 else |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1826 { |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1827 at_bol = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1828 begin_comment = false; |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1829 } |
2300 | 1830 } |
1831 | |
1019 | 1832 if (in_comment) |
1 | 1833 { |
4426 | 1834 buf += static_cast<char> (c); |
1755 | 1835 |
1019 | 1836 if (c == '\n') |
3427 | 1837 { |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1838 at_bol = true; |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1839 current_input_column = 0; |
3427 | 1840 in_comment = false; |
8537
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1841 |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1842 // FIXME -- bailing out here prevents things like |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1843 // |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1844 // octave> # comment |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1845 // octave> x = 1 |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1846 // |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1847 // from failing at the command line, while still |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1848 // allowing blocks of comments to be grabbed properly |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1849 // for function doc strings. But only the first line of |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1850 // a mult-line doc string will be picked up for |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1851 // functions defined on the command line. We need a |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1852 // better way of collecting these comments... |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1853 if (! (reading_fcn_file || reading_script_file)) |
17ef48c699a5
lex.l (grab_comment_block): if not reading from a file, bail at first newline inside a comment:
John W. Eaton <jwe@octave.org>
parents:
8536
diff
changeset
|
1854 goto done; |
3427 | 1855 } |
1019 | 1856 } |
1857 else | |
1858 { | |
1859 switch (c) | |
991 | 1860 { |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1861 case ' ': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1862 case '\t': |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1863 break; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1864 |
4037 | 1865 case '#': |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1866 if (! warned_incompatible) |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1867 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1868 warned_incompatible = true; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1869 maybe_gripe_matlab_incompatible_comment (c); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1870 } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1871 // fall through... |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1872 |
1019 | 1873 case '%': |
2300 | 1874 in_comment = true; |
1875 begin_comment = true; | |
1019 | 1876 break; |
777 | 1877 |
1019 | 1878 default: |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1879 current_input_column--; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1880 reader.ungetc (c); |
1019 | 1881 goto done; |
1 | 1882 } |
1883 } | |
1019 | 1884 } |
991 | 1885 |
1019 | 1886 done: |
991 | 1887 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1888 if (c == EOF) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1889 eof = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1890 |
4426 | 1891 return buf; |
1 | 1892 } |
1893 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1894 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1895 flex_stream_reader : public stream_reader |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1896 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1897 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1898 flex_stream_reader (char *buf_arg) : stream_reader (), buf (buf_arg) { } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1899 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1900 int getc (void) { return ::text_yyinput (); } |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1901 int ungetc (int c) { ::xunput (c, buf); return 0; } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1902 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1903 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1904 char *buf; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1905 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1906 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1907 static int |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1908 process_comment (bool start_in_block, bool& eof) |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1909 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1910 eof = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1911 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1912 std::string help_txt; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1913 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1914 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1915 help_txt = help_buf.top (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1916 |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1917 flex_stream_reader flex_reader (yytext); |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1918 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1919 // process_comment is only supposed to be called when we are not |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1920 // initially looking at a block comment. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1921 |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1922 std::string txt = start_in_block |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1923 ? grab_block_comment (flex_reader, eof) |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
1924 : grab_comment_block (flex_reader, false, eof); |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1925 |
8535 | 1926 if (lexer_debug_flag) |
8536
de1b944d5306
lex.l: finish previous change
John W. Eaton <jwe@octave.org>
parents:
8535
diff
changeset
|
1927 std::cerr << "C: " << txt << std::endl; |
8535 | 1928 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1929 if (help_txt.empty () && nesting_level.none ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1930 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1931 if (! help_buf.empty ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1932 help_buf.pop (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1933 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1934 help_buf.push (txt); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1935 } |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1936 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
1937 octave_comment_buffer::append (txt); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1938 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1939 current_input_column = 1; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1940 lexer_flags.quote_is_transpose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1941 lexer_flags.convert_spaces_to_comma = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1942 lexer_flags.at_beginning_of_statement = true; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1943 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1944 if (YY_START == COMMAND_START) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1945 BEGIN (INITIAL); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1946 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1947 if (nesting_level.none ()) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
1948 return '\n'; |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1949 else if (nesting_level.is_bracket_or_brace ()) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1950 return ';'; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1951 else |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1952 return 0; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1953 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
1954 |
767 | 1955 // Return 1 if the given character matches any character in the given |
1956 // string. | |
1957 | |
2857 | 1958 static bool |
2804 | 1959 match_any (char c, const char *s) |
1 | 1960 { |
1961 char tmp; | |
1962 while ((tmp = *s++) != '\0') | |
1963 { | |
1964 if (c == tmp) | |
2857 | 1965 return true; |
1 | 1966 } |
2857 | 1967 return false; |
1 | 1968 } |
1969 | |
767 | 1970 // Given information about the spacing surrounding an operator, |
1971 // return 1 if it looks like it should be treated as a binary | |
1972 // operator. For example, | |
1973 // | |
3774 | 1974 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary |
1975 // | |
1976 // [ 1 +2 ] ==> unary | |
767 | 1977 |
2857 | 1978 static bool |
3246 | 1979 looks_like_bin_op (bool spc_prev, int next_char) |
1 | 1980 { |
3246 | 1981 bool spc_next = (next_char == ' ' || next_char == '\t'); |
1982 | |
608 | 1983 return ((spc_prev && spc_next) || ! spc_prev); |
1 | 1984 } |
1985 | |
3263 | 1986 // Recognize separators. If the separator is a CRLF pair, it is |
1987 // replaced by a single LF. | |
1988 | |
1989 static bool | |
1990 next_token_is_sep_op (void) | |
1991 { | |
1992 bool retval = false; | |
1993 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1994 int c = text_yyinput (); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1995 |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1996 retval = match_any (c, ",;\n]"); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
1997 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
1998 xunput (c, yytext); |
3263 | 1999 |
2000 return retval; | |
2001 } | |
2002 | |
767 | 2003 // Try to determine if the next token should be treated as a postfix |
2004 // unary operator. This is ugly, but it seems to do the right thing. | |
2005 | |
2857 | 2006 static bool |
3246 | 2007 next_token_is_postfix_unary_op (bool spc_prev) |
1 | 2008 { |
2857 | 2009 bool un_op = false; |
1 | 2010 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2011 int c0 = text_yyinput (); |
1 | 2012 |
3246 | 2013 if (c0 == '\'' && ! spc_prev) |
2014 { | |
2015 un_op = true; | |
2016 } | |
2017 else if (c0 == '.') | |
2018 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2019 int c1 = text_yyinput (); |
3246 | 2020 un_op = (c1 == '\''); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2021 xunput (c1, yytext); |
3246 | 2022 } |
4613 | 2023 else if (c0 == '+') |
2024 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2025 int c1 = text_yyinput (); |
4613 | 2026 un_op = (c1 == '+'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2027 xunput (c1, yytext); |
4613 | 2028 } |
2029 else if (c0 == '-') | |
2030 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2031 int c1 = text_yyinput (); |
4613 | 2032 un_op = (c1 == '-'); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2033 xunput (c1, yytext); |
4613 | 2034 } |
1 | 2035 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2036 xunput (c0, yytext); |
1 | 2037 |
2038 return un_op; | |
2039 } | |
2040 | |
767 | 2041 // Try to determine if the next token should be treated as a binary |
3246 | 2042 // operator. |
1521 | 2043 // |
3246 | 2044 // This kluge exists because whitespace is not always ignored inside |
3774 | 2045 // the square brackets that are used to create matrix objects (though |
2046 // spacing only really matters in the cases that can be interpreted | |
2047 // either as binary ops or prefix unary ops: currently just +, -). | |
2048 // | |
3779 | 2049 // Note that a line continuation directly following a + or - operator |
2050 // (e.g., the characters '[' 'a' ' ' '+' '\' LFD 'b' ']') will be | |
2051 // parsed as a binary operator. | |
767 | 2052 |
2857 | 2053 static bool |
3246 | 2054 next_token_is_bin_op (bool spc_prev) |
1 | 2055 { |
2857 | 2056 bool bin_op = false; |
1 | 2057 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2058 int c0 = text_yyinput (); |
1 | 2059 |
2060 switch (c0) | |
2061 { | |
777 | 2062 case '+': |
2063 case '-': | |
3774 | 2064 { |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2065 int c1 = text_yyinput (); |
3774 | 2066 |
2067 switch (c1) | |
2068 { | |
2069 case '+': | |
2070 case '-': | |
2071 // Unary ops, spacing doesn't matter. | |
2072 break; | |
2073 | |
2074 case '=': | |
2075 // Binary ops, spacing doesn't matter. | |
2076 bin_op = true; | |
2077 break; | |
2078 | |
2079 default: | |
2080 // Could be either, spacing matters. | |
2081 bin_op = looks_like_bin_op (spc_prev, c1); | |
2082 break; | |
2083 } | |
2084 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2085 xunput (c1, yytext); |
3774 | 2086 } |
2087 break; | |
2088 | |
2089 case ':': | |
3246 | 2090 case '/': |
2091 case '\\': | |
2092 case '^': | |
3774 | 2093 // Always a binary op (may also include /=, \=, and ^=). |
2094 bin_op = true; | |
1276 | 2095 break; |
2096 | |
3246 | 2097 // .+ .- ./ .\ .^ .* .** |
1554 | 2098 case '.': |
2099 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2100 int c1 = text_yyinput (); |
3246 | 2101 |
3774 | 2102 if (match_any (c1, "+-/\\^*")) |
2103 // Always a binary op (may also include .+=, .-=, ./=, ...). | |
2104 bin_op = true; | |
3698 | 2105 else if (! isdigit (c1) && c1 != ' ' && c1 != '\t' && c1 != '.') |
3774 | 2106 // A structure element reference is a binary op. |
2107 bin_op = true; | |
3246 | 2108 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2109 xunput (c1, yytext); |
1554 | 2110 } |
2111 break; | |
2112 | |
3246 | 2113 // = == & && | || * ** |
2114 case '=': | |
1 | 2115 case '&': |
3246 | 2116 case '|': |
1 | 2117 case '*': |
3774 | 2118 // Always a binary op (may also include ==, &&, ||, **). |
2119 bin_op = true; | |
3246 | 2120 break; |
2121 | |
3774 | 2122 // < <= <> > >= |
1 | 2123 case '<': |
2124 case '>': | |
3774 | 2125 // Always a binary op (may also include <=, <>, >=). |
2126 bin_op = true; | |
2127 break; | |
2128 | |
2129 // ~= != | |
777 | 2130 case '~': |
2131 case '!': | |
3246 | 2132 { |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2133 int c1 = text_yyinput (); |
3246 | 2134 |
3774 | 2135 // ~ and ! can be unary ops, so require following =. |
2136 if (c1 == '=') | |
2137 bin_op = true; | |
3246 | 2138 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2139 xunput (c1, yytext); |
3246 | 2140 } |
1 | 2141 break; |
2142 | |
2143 default: | |
1276 | 2144 break; |
1 | 2145 } |
2146 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2147 xunput (c0, yytext); |
1 | 2148 |
2149 return bin_op; | |
2150 } | |
2151 | |
767 | 2152 // Used to delete trailing white space from tokens. |
2153 | |
3536 | 2154 static std::string |
1 | 2155 strip_trailing_whitespace (char *s) |
2156 { | |
3523 | 2157 std::string retval = s; |
1 | 2158 |
1823 | 2159 size_t pos = retval.find_first_of (" \t"); |
1 | 2160 |
8021 | 2161 if (pos != std::string::npos) |
1823 | 2162 retval.resize (pos); |
1 | 2163 |
2164 return retval; | |
2165 } | |
2166 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2167 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2168 |
3665 | 2169 static void |
2170 scan_for_comments (const char *text) | |
2171 { | |
2172 std::string comment_buf; | |
2173 | |
2174 bool in_comment = false; | |
2175 bool beginning_of_comment = false; | |
2176 | |
2177 int len = strlen (text); | |
2178 int i = 0; | |
2179 | |
2180 while (i < len) | |
2181 { | |
2182 char c = text[i++]; | |
2183 | |
2184 switch (c) | |
2185 { | |
2186 case '%': | |
2187 case '#': | |
2188 if (in_comment) | |
2189 { | |
2190 if (! beginning_of_comment) | |
3802 | 2191 comment_buf += static_cast<char> (c); |
3665 | 2192 } |
2193 else | |
2194 { | |
4037 | 2195 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2196 in_comment = true; |
2197 beginning_of_comment = true; | |
2198 } | |
2199 break; | |
2200 | |
2201 case '\n': | |
2202 if (in_comment) | |
2203 { | |
3802 | 2204 comment_buf += static_cast<char> (c); |
3665 | 2205 octave_comment_buffer::append (comment_buf); |
2206 comment_buf.resize (0); | |
2207 in_comment = false; | |
2208 beginning_of_comment = false; | |
2209 } | |
2210 break; | |
2211 | |
2212 default: | |
2213 if (in_comment) | |
2214 { | |
3802 | 2215 comment_buf += static_cast<char> (c); |
3665 | 2216 beginning_of_comment = false; |
2217 } | |
2218 break; | |
2219 } | |
2220 } | |
2221 | |
2222 if (! comment_buf.empty ()) | |
2223 octave_comment_buffer::append (comment_buf); | |
2224 } | |
2225 | |
1001 | 2226 // Discard whitespace, including comments and continuations. |
1088 | 2227 // |
2228 // Return value is logical OR of the following values: | |
2229 // | |
1826 | 2230 // ATE_NOTHING : no spaces to eat |
1088 | 2231 // ATE_SPACE_OR_TAB : space or tab in input |
2232 // ATE_NEWLINE : bare new line in input | |
1001 | 2233 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2234 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2235 |
1826 | 2236 static yum_yum |
975 | 2237 eat_whitespace (void) |
2238 { | |
1826 | 2239 yum_yum retval = ATE_NOTHING; |
3665 | 2240 |
2241 std::string comment_buf; | |
2242 | |
2857 | 2243 bool in_comment = false; |
3665 | 2244 bool beginning_of_comment = false; |
2245 | |
2246 int c = 0; | |
2247 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2248 while ((c = text_yyinput ()) != EOF) |
975 | 2249 { |
2250 current_input_column++; | |
2251 | |
2252 switch (c) | |
2253 { | |
2254 case ' ': | |
2255 case '\t': | |
3665 | 2256 if (in_comment) |
2257 { | |
3802 | 2258 comment_buf += static_cast<char> (c); |
3665 | 2259 beginning_of_comment = false; |
2260 } | |
1088 | 2261 retval |= ATE_SPACE_OR_TAB; |
975 | 2262 break; |
2263 | |
2264 case '\n': | |
1088 | 2265 retval |= ATE_NEWLINE; |
3665 | 2266 if (in_comment) |
2267 { | |
3802 | 2268 comment_buf += static_cast<char> (c); |
3665 | 2269 octave_comment_buffer::append (comment_buf); |
2270 comment_buf.resize (0); | |
2271 in_comment = false; | |
2272 beginning_of_comment = false; | |
2273 } | |
975 | 2274 current_input_column = 0; |
2275 break; | |
2276 | |
2277 case '#': | |
2278 case '%': | |
3665 | 2279 if (in_comment) |
2280 { | |
2281 if (! beginning_of_comment) | |
3802 | 2282 comment_buf += static_cast<char> (c); |
3665 | 2283 } |
2284 else | |
2285 { | |
4037 | 2286 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2287 in_comment = true; |
2288 beginning_of_comment = true; | |
2289 } | |
975 | 2290 break; |
2291 | |
1001 | 2292 case '.': |
2293 if (in_comment) | |
3665 | 2294 { |
3802 | 2295 comment_buf += static_cast<char> (c); |
3665 | 2296 beginning_of_comment = false; |
2297 break; | |
2298 } | |
1001 | 2299 else |
2300 { | |
2301 if (have_ellipsis_continuation ()) | |
2302 break; | |
2303 else | |
2304 goto done; | |
2305 } | |
2306 | |
2307 case '\\': | |
2308 if (in_comment) | |
3665 | 2309 { |
3802 | 2310 comment_buf += static_cast<char> (c); |
3665 | 2311 beginning_of_comment = false; |
2312 break; | |
2313 } | |
1001 | 2314 else |
2315 { | |
3105 | 2316 if (have_continuation ()) |
1001 | 2317 break; |
2318 else | |
2319 goto done; | |
2320 } | |
2321 | |
975 | 2322 default: |
2323 if (in_comment) | |
3665 | 2324 { |
3802 | 2325 comment_buf += static_cast<char> (c); |
3665 | 2326 beginning_of_comment = false; |
2327 break; | |
2328 } | |
975 | 2329 else |
2330 goto done; | |
2331 } | |
2332 } | |
2333 | |
3665 | 2334 if (! comment_buf.empty ()) |
2335 octave_comment_buffer::append (comment_buf); | |
2336 | |
975 | 2337 done: |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2338 xunput (c, yytext); |
1082 | 2339 current_input_column--; |
1001 | 2340 return retval; |
975 | 2341 } |
2342 | |
3220 | 2343 static inline bool |
2344 looks_like_hex (const char *s, int len) | |
2345 { | |
2346 return (len > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')); | |
2347 } | |
2348 | |
975 | 2349 static void |
3246 | 2350 handle_number (void) |
972 | 2351 { |
3220 | 2352 double value = 0.0; |
2353 int nread = 0; | |
2354 | |
3598 | 2355 if (looks_like_hex (yytext, strlen (yytext))) |
3220 | 2356 { |
2357 unsigned long ival; | |
3598 | 2358 |
2359 nread = sscanf (yytext, "%lx", &ival); | |
2360 | |
3220 | 2361 value = static_cast<double> (ival); |
2362 } | |
2363 else | |
3598 | 2364 { |
2365 char *tmp = strsave (yytext); | |
2366 | |
2367 char *idx = strpbrk (tmp, "Dd"); | |
2621 | 2368 |
3598 | 2369 if (idx) |
2370 *idx = 'e'; | |
2371 | |
2372 nread = sscanf (tmp, "%lf", &value); | |
2373 | |
2374 delete [] tmp; | |
2375 } | |
972 | 2376 |
1826 | 2377 // If yytext doesn't contain a valid number, we are in deep doo doo. |
985 | 2378 |
972 | 2379 assert (nread == 1); |
2380 | |
3988 | 2381 lexer_flags.quote_is_transpose = true; |
2382 lexer_flags.convert_spaces_to_comma = true; | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2383 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2384 lexer_flags.at_beginning_of_statement = false; |
972 | 2385 |
2386 yylval.tok_val = new token (value, yytext, input_line_number, | |
2387 current_input_column); | |
2388 | |
2389 token_stack.push (yylval.tok_val); | |
2390 | |
2391 current_input_column += yyleng; | |
2392 | |
2393 do_comma_insert_check (); | |
2394 } | |
2395 | |
1001 | 2396 // We have seen a backslash and need to find out if it should be |
2397 // treated as a continuation character. If so, this eats it, up to | |
2398 // and including the new line character. | |
2399 // | |
973 | 2400 // Match whitespace only, followed by a comment character or newline. |
2401 // Once a comment character is found, discard all input until newline. | |
2402 // If non-whitespace characters are found before comment | |
2403 // characters, return 0. Otherwise, return 1. | |
2404 | |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2405 // FIXME -- we need to handle block comments here. |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7722
diff
changeset
|
2406 |
2857 | 2407 static bool |
3096 | 2408 have_continuation (bool trailing_comments_ok) |
973 | 2409 { |
5765 | 2410 std::ostringstream buf; |
973 | 2411 |
3665 | 2412 std::string comment_buf; |
2413 | |
2857 | 2414 bool in_comment = false; |
3665 | 2415 bool beginning_of_comment = false; |
2416 | |
2417 int c = 0; | |
2418 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2419 while ((c = text_yyinput ()) != EOF) |
973 | 2420 { |
3802 | 2421 buf << static_cast<char> (c); |
973 | 2422 |
2423 switch (c) | |
2424 { | |
2425 case ' ': | |
2426 case '\t': | |
3665 | 2427 if (in_comment) |
2428 { | |
3802 | 2429 comment_buf += static_cast<char> (c); |
3665 | 2430 beginning_of_comment = false; |
2431 } | |
973 | 2432 break; |
2433 | |
2434 case '%': | |
2435 case '#': | |
1091 | 2436 if (trailing_comments_ok) |
3665 | 2437 { |
2438 if (in_comment) | |
2439 { | |
2440 if (! beginning_of_comment) | |
3802 | 2441 comment_buf += static_cast<char> (c); |
3665 | 2442 } |
2443 else | |
2444 { | |
4037 | 2445 maybe_gripe_matlab_incompatible_comment (c); |
3665 | 2446 in_comment = true; |
2447 beginning_of_comment = true; | |
2448 } | |
2449 } | |
1091 | 2450 else |
2451 goto cleanup; | |
973 | 2452 break; |
2453 | |
2454 case '\n': | |
3665 | 2455 if (in_comment) |
2456 { | |
3802 | 2457 comment_buf += static_cast<char> (c); |
3665 | 2458 octave_comment_buffer::append (comment_buf); |
2459 } | |
975 | 2460 current_input_column = 0; |
1001 | 2461 promptflag--; |
4037 | 2462 gripe_matlab_incompatible_continuation (); |
2857 | 2463 return true; |
973 | 2464 |
2465 default: | |
3665 | 2466 if (in_comment) |
2467 { | |
3802 | 2468 comment_buf += static_cast<char> (c); |
3665 | 2469 beginning_of_comment = false; |
2470 } | |
2471 else | |
1091 | 2472 goto cleanup; |
2473 break; | |
973 | 2474 } |
2475 } | |
2476 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2477 xunput (c, yytext); |
2857 | 2478 return false; |
973 | 2479 |
3096 | 2480 cleanup: |
4051 | 2481 |
5765 | 2482 std::string s = buf.str (); |
4051 | 2483 |
2484 int len = s.length (); | |
2485 while (len--) | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2486 xunput (s[len], yytext); |
3096 | 2487 |
2857 | 2488 return false; |
973 | 2489 } |
2490 | |
1001 | 2491 // We have seen a `.' and need to see if it is the start of a |
2492 // continuation. If so, this eats it, up to and including the new | |
2493 // line character. | |
2494 | |
2857 | 2495 static bool |
3096 | 2496 have_ellipsis_continuation (bool trailing_comments_ok) |
973 | 2497 { |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2498 char c1 = text_yyinput (); |
973 | 2499 if (c1 == '.') |
2500 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2501 char c2 = text_yyinput (); |
1091 | 2502 if (c2 == '.' && have_continuation (trailing_comments_ok)) |
2857 | 2503 return true; |
973 | 2504 else |
2505 { | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2506 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2507 xunput (c1, yytext); |
973 | 2508 } |
2509 } | |
2510 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2511 xunput (c1, yytext); |
973 | 2512 |
2857 | 2513 return false; |
973 | 2514 } |
2515 | |
1001 | 2516 // See if we have a continuation line. If so, eat it and the leading |
2517 // whitespace on the next line. | |
1088 | 2518 // |
2519 // Return value is the same as described for eat_whitespace(). | |
1001 | 2520 |
1826 | 2521 static yum_yum |
1001 | 2522 eat_continuation (void) |
2523 { | |
1826 | 2524 int retval = ATE_NOTHING; |
3665 | 2525 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2526 int c = text_yyinput (); |
3665 | 2527 |
1001 | 2528 if ((c == '.' && have_ellipsis_continuation ()) |
3105 | 2529 || (c == '\\' && have_continuation ())) |
1001 | 2530 retval = eat_whitespace (); |
2531 else | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2532 xunput (c, yytext); |
1001 | 2533 |
2534 return retval; | |
2535 } | |
2536 | |
973 | 2537 static int |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2538 handle_string (char delim) |
973 | 2539 { |
5765 | 2540 std::ostringstream buf; |
973 | 2541 |
3805 | 2542 int bos_line = input_line_number; |
2543 int bos_col = current_input_column; | |
2544 | |
973 | 2545 int c; |
1031 | 2546 int escape_pending = 0; |
973 | 2547 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2548 while ((c = text_yyinput ()) != EOF) |
973 | 2549 { |
2550 current_input_column++; | |
2551 | |
3105 | 2552 if (c == '\\') |
973 | 2553 { |
5359 | 2554 if (delim == '\'' || escape_pending) |
1053 | 2555 { |
3802 | 2556 buf << static_cast<char> (c); |
1053 | 2557 escape_pending = 0; |
2558 } | |
2559 else | |
2560 { | |
3096 | 2561 if (have_continuation (false)) |
1053 | 2562 escape_pending = 0; |
2563 else | |
2564 { | |
3802 | 2565 buf << static_cast<char> (c); |
1053 | 2566 escape_pending = 1; |
2567 } | |
2568 } | |
1031 | 2569 continue; |
973 | 2570 } |
2571 else if (c == '.') | |
2572 { | |
5359 | 2573 if (delim == '\'' || ! have_ellipsis_continuation (false)) |
3802 | 2574 buf << static_cast<char> (c); |
973 | 2575 } |
2576 else if (c == '\n') | |
2577 { | |
1053 | 2578 error ("unterminated string constant"); |
973 | 2579 break; |
2580 } | |
2581 else if (c == delim) | |
2582 { | |
1031 | 2583 if (escape_pending) |
3802 | 2584 buf << static_cast<char> (c); |
973 | 2585 else |
2586 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2587 c = text_yyinput (); |
973 | 2588 if (c == delim) |
5102 | 2589 { |
2590 buf << static_cast<char> (c); | |
2591 } | |
973 | 2592 else |
2593 { | |
5102 | 2594 std::string s; |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2595 xunput (c, yytext); |
5765 | 2596 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2597 if (delim == '\'') |
5765 | 2598 s = buf.str (); |
5102 | 2599 else |
5765 | 2600 s = do_string_escapes (buf.str ()); |
975 | 2601 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2602 lexer_flags.quote_is_transpose = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2603 lexer_flags.convert_spaces_to_comma = true; |
975 | 2604 |
3805 | 2605 yylval.tok_val = new token (s, bos_line, bos_col); |
973 | 2606 token_stack.push (yylval.tok_val); |
3400 | 2607 |
4037 | 2608 if (delim == '"') |
2609 gripe_matlab_incompatible ("\" used as string delimiter"); | |
2610 else if (delim == '\'') | |
3400 | 2611 gripe_single_quote_string (); |
2612 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2613 lexer_flags.looking_for_object_index = true; |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2614 lexer_flags.at_beginning_of_statement = false; |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2615 |
5279 | 2616 return delim == '"' ? DQ_STRING : SQ_STRING; |
973 | 2617 } |
2618 } | |
2619 } | |
2620 else | |
2621 { | |
3802 | 2622 buf << static_cast<char> (c); |
973 | 2623 } |
2624 | |
1031 | 2625 escape_pending = 0; |
973 | 2626 } |
2627 | |
2628 return LEXICAL_ERROR; | |
2629 } | |
2630 | |
3208 | 2631 static bool |
2632 next_token_is_assign_op (void) | |
2633 { | |
2634 bool retval = false; | |
2635 | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2636 int c0 = text_yyinput (); |
3208 | 2637 |
2638 switch (c0) | |
2639 { | |
2640 case '=': | |
2641 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2642 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2643 xunput (c1, yytext); |
3208 | 2644 if (c1 != '=') |
2645 retval = true; | |
2646 } | |
2647 break; | |
2648 | |
2649 case '+': | |
2650 case '-': | |
2651 case '*': | |
2652 case '/': | |
2653 case '\\': | |
2654 case '&': | |
2655 case '|': | |
2656 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2657 int c1 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2658 xunput (c1, yytext); |
3208 | 2659 if (c1 == '=') |
2660 retval = true; | |
2661 } | |
2662 break; | |
2663 | |
2664 case '.': | |
2665 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2666 int c1 = text_yyinput (); |
3208 | 2667 if (match_any (c1, "+-*/\\")) |
2668 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2669 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2670 xunput (c2, yytext); |
3208 | 2671 if (c2 == '=') |
2672 retval = true; | |
2673 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2674 xunput (c1, yytext); |
3208 | 2675 } |
2676 break; | |
2677 | |
2678 case '>': | |
2679 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2680 int c1 = text_yyinput (); |
3208 | 2681 if (c1 == '>') |
2682 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2683 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2684 xunput (c2, yytext); |
3208 | 2685 if (c2 == '=') |
2686 retval = true; | |
2687 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2688 xunput (c1, yytext); |
3208 | 2689 } |
2690 break; | |
2691 | |
2692 case '<': | |
2693 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2694 int c1 = text_yyinput (); |
3208 | 2695 if (c1 == '<') |
2696 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2697 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2698 xunput (c2, yytext); |
3208 | 2699 if (c2 == '=') |
2700 retval = true; | |
2701 } | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2702 xunput (c1, yytext); |
3208 | 2703 } |
2704 break; | |
2705 | |
2706 default: | |
2707 break; | |
2708 } | |
2709 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2710 xunput (c0, yytext); |
3208 | 2711 |
2712 return retval; | |
2713 } | |
2714 | |
4633 | 2715 static bool |
2716 next_token_is_index_op (void) | |
2717 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2718 int c = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2719 xunput (c, yytext); |
4633 | 2720 return c == '(' || c == '{'; |
2721 } | |
2722 | |
4612 | 2723 static int |
2724 handle_close_bracket (bool spc_gobbled, int bracket_type) | |
971 | 2725 { |
4612 | 2726 int retval = bracket_type; |
3208 | 2727 |
1826 | 2728 if (! nesting_level.none ()) |
971 | 2729 { |
1826 | 2730 nesting_level.remove (); |
4613 | 2731 |
2732 if (bracket_type == ']') | |
2733 lexer_flags.bracketflag--; | |
2734 else if (bracket_type == '}') | |
2735 lexer_flags.braceflag--; | |
2736 else | |
2737 panic_impossible (); | |
971 | 2738 } |
2739 | |
4613 | 2740 if (lexer_flags.bracketflag == 0 && lexer_flags.braceflag == 0) |
4323 | 2741 BEGIN (INITIAL); |
1001 | 2742 |
4608 | 2743 if (bracket_type == ']' |
2744 && next_token_is_assign_op () | |
2745 && ! lexer_flags.looking_at_return_list) | |
971 | 2746 { |
3208 | 2747 retval = CLOSE_BRACE; |
971 | 2748 } |
4613 | 2749 else if ((lexer_flags.bracketflag || lexer_flags.braceflag) |
2750 && lexer_flags.convert_spaces_to_comma | |
2751 && (nesting_level.is_bracket () | |
2752 || (nesting_level.is_brace () | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2753 && ! lexer_flags.looking_at_object_index.front ()))) |
971 | 2754 { |
4633 | 2755 bool index_op = next_token_is_index_op (); |
2756 | |
2757 // Don't insert comma if we are looking at something like | |
2758 // | |
2759 // [x{i}{j}] or [x{i}(j)] | |
2760 // | |
2761 // but do if we are looking at | |
2762 // | |
2763 // [x{i} {j}] or [x{i} (j)] | |
2764 | |
2765 if (spc_gobbled || ! (bracket_type == '}' && index_op)) | |
971 | 2766 { |
4633 | 2767 bool bin_op = next_token_is_bin_op (spc_gobbled); |
2768 | |
2769 bool postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); | |
2770 | |
2771 bool sep_op = next_token_is_sep_op (); | |
2772 | |
2773 if (! (postfix_un_op || bin_op || sep_op)) | |
2774 { | |
2775 maybe_warn_separator_insert (','); | |
2776 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2777 xunput (',', yytext); |
4633 | 2778 return retval; |
2779 } | |
971 | 2780 } |
2781 } | |
2782 | |
2857 | 2783 lexer_flags.quote_is_transpose = true; |
2784 lexer_flags.convert_spaces_to_comma = true; | |
3208 | 2785 |
2786 return retval; | |
971 | 2787 } |
2788 | |
1072 | 2789 static void |
2790 maybe_unput_comma (int spc_gobbled) | |
2791 { | |
4613 | 2792 if (nesting_level.is_bracket () |
2793 || (nesting_level.is_brace () | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2794 && ! lexer_flags.looking_at_object_index.front ())) |
1072 | 2795 { |
3246 | 2796 int bin_op = next_token_is_bin_op (spc_gobbled); |
1072 | 2797 |
3246 | 2798 int postfix_un_op = next_token_is_postfix_unary_op (spc_gobbled); |
1072 | 2799 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2800 int c1 = text_yyinput (); |
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
2801 int c2 = text_yyinput (); |
2970 | 2802 |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2803 xunput (c2, yytext); |
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
2804 xunput (c1, yytext); |
2970 | 2805 |
3263 | 2806 int sep_op = next_token_is_sep_op (); |
2970 | 2807 |
1072 | 2808 int dot_op = (c1 == '.' |
2809 && (isalpha (c2) || isspace (c2) || c2 == '_')); | |
2970 | 2810 |
3388 | 2811 if (postfix_un_op || bin_op || sep_op || dot_op) |
2812 return; | |
2813 | |
3985 | 2814 int index_op = (c1 == '(' || c1 == '{'); |
3388 | 2815 |
4476 | 2816 // If there is no space before the indexing op, we don't insert |
2817 // a comma. | |
2818 | |
2819 if (index_op && ! spc_gobbled) | |
2820 return; | |
2821 | |
2822 maybe_warn_separator_insert (','); | |
2823 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
2824 xunput (',', yytext); |
1072 | 2825 } |
2826 } | |
2827 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2828 static bool |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2829 next_token_can_follow_bin_op (void) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2830 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2831 std::stack<char> buf; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2832 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2833 int c = EOF; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2834 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2835 // Skip whitespace in current statement on current line |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2836 while (true) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2837 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2838 c = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2839 |
8767
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2840 buf.push (c); |
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2841 |
026c6732ec7a
lex.l (next_token_can_follow_bin_op): push all characters read on to buffer stack
John W. Eaton <jwe@octave.org>
parents:
8746
diff
changeset
|
2842 if (match_any (c, ",;\n") || (c != ' ' && c != '\t')) |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2843 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2844 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2845 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2846 // Restore input. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2847 while (! buf.empty ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2848 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2849 xunput (buf.top (), yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2850 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2851 buf.pop (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2852 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2853 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2854 return (isalnum (c) || match_any (c, "!\"'(-[_{~")); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2855 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2856 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2857 static bool |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2858 looks_like_command_arg (void) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2859 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2860 bool retval = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2861 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2862 int c0 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2863 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2864 switch (c0) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2865 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2866 // = == |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2867 case '=': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2868 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2869 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2870 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2871 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2872 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2873 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2874 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2875 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2876 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2877 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2878 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2879 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2880 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2881 else |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2882 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2883 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2884 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2885 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2886 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2887 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2888 case '(': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2889 case '{': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2890 // Indexing. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2891 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2892 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2893 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2894 case '\n': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2895 // EOL. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2896 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2897 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2898 case '\'': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2899 case '"': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2900 // Beginning of a character string. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2901 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2902 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2903 // + - ++ -- += -= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2904 case '+': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2905 case '-': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2906 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2907 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2908 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2909 switch (c1) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2910 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2911 case '\n': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2912 // EOL. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2913 case '+': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2914 case '-': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2915 // Unary ops, spacing doesn't matter. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2916 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2917 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2918 case '\t': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2919 case ' ': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2920 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2921 if (next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2922 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2923 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2924 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2925 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2926 case '=': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2927 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2928 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2929 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2930 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2931 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2932 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2933 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2934 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2935 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2936 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2937 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2938 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2939 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2940 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2941 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2942 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2943 case ':': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2944 case '/': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2945 case '\\': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2946 case '^': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2947 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2948 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2949 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2950 if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2951 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2952 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2953 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2954 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2955 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2956 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2957 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2958 // .+ .- ./ .\ .^ .* .** |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2959 case '.': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2960 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2961 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2962 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2963 if (match_any (c1, "+-/\\^*")) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2964 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2965 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2966 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2967 if (c2 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2968 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2969 int c3 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2970 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2971 if (! match_any (c3, ",;\n") && (c3 == ' ' || c3 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2972 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2973 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2974 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2975 xunput (c3, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2976 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2977 else if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2978 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2979 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2980 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2981 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2982 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2983 else if (! match_any (c1, ",;\n") |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2984 && (! isdigit (c1) && c1 != ' ' && c1 != '\t' |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2985 && c1 != '.')) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2986 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2987 // Structure reference. FIXME -- is this a complete check? |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2988 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2989 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2990 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2991 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2992 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2993 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2994 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2995 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2996 // & && | || * ** |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2997 case '&': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2998 case '|': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
2999 case '*': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3000 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3001 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3002 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3003 if (c1 == c0) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3004 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3005 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3006 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3007 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3008 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3009 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3010 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3011 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3012 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3013 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3014 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3015 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3016 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3017 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3018 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3019 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3020 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3021 // < <= > >= |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3022 case '<': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3023 case '>': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3024 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3025 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3026 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3027 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3028 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3029 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3030 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3031 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3032 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3033 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3034 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3035 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3036 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3037 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3038 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3039 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3040 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3041 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3042 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3043 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3044 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3045 // ~= != |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3046 case '~': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3047 case '!': |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3048 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3049 int c1 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3050 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3051 // ~ and ! can be unary ops, so require following =. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3052 if (c1 == '=') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3053 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3054 int c2 = text_yyinput (); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3055 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3056 if (! match_any (c2, ",;\n") && (c2 == ' ' || c2 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3057 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3058 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3059 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3060 xunput (c2, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3061 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3062 else if (! match_any (c1, ",;\n") && (c1 == ' ' || c1 == '\t') |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3063 && next_token_can_follow_bin_op ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3064 retval = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3065 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3066 xunput (c1, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3067 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3068 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3069 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3070 default: |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3071 break; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3072 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3073 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3074 xunput (c0, yytext); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3075 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3076 return retval; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3077 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3078 |
767 | 3079 // Figure out exactly what kind of token to return when we have seen |
4238 | 3080 // an identifier. Handles keywords. Return -1 if the identifier |
3081 // should be ignored. | |
767 | 3082 |
146 | 3083 static int |
3974 | 3084 handle_identifier (void) |
146 | 3085 { |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3086 bool at_bos = lexer_flags.at_beginning_of_statement; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3087 |
3974 | 3088 std::string tok = strip_trailing_whitespace (yytext); |
3089 | |
3090 int c = yytext[yyleng-1]; | |
3091 | |
3092 int cont_is_spc = eat_continuation (); | |
3093 | |
3094 int spc_gobbled = (cont_is_spc || c == ' ' || c == '\t'); | |
3095 | |
2970 | 3096 // If we are expecting a structure element, avoid recognizing |
3097 // keywords and other special names and return STRUCT_ELT, which is | |
3098 // a string that is also a valid identifier. But first, we have to | |
3099 // decide whether to insert a comma. | |
747 | 3100 |
1826 | 3101 if (lexer_flags.looking_at_indirect_ref) |
1072 | 3102 { |
2970 | 3103 do_comma_insert_check (); |
3104 | |
1072 | 3105 maybe_unput_comma (spc_gobbled); |
2819 | 3106 |
3107 yylval.tok_val = new token (tok, input_line_number, | |
3108 current_input_column); | |
3109 | |
3110 token_stack.push (yylval.tok_val); | |
3111 | |
2857 | 3112 lexer_flags.quote_is_transpose = true; |
3113 lexer_flags.convert_spaces_to_comma = true; | |
2819 | 3114 |
3115 current_input_column += yyleng; | |
3116 | |
2970 | 3117 return STRUCT_ELT; |
1072 | 3118 } |
747 | 3119 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3120 lexer_flags.at_beginning_of_statement = false; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3121 |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3122 // The is_keyword_token may reset |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3123 // lexer_flags.at_beginning_of_statement. For example, if it sees |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3124 // an else token, then the next token is at the beginning of a |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3125 // statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3126 |
4930 | 3127 int kw_token = is_keyword_token (tok); |
3128 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3129 // If we found a keyword token, then the beginning_of_statement flag |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3130 // is already set. Otherwise, we won't be at the beginning of a |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3131 // statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3132 |
4930 | 3133 if (lexer_flags.looking_at_function_handle) |
3134 { | |
3135 if (kw_token) | |
3136 { | |
3137 error ("function handles may not refer to keywords"); | |
3138 | |
3139 return LEXICAL_ERROR; | |
3140 } | |
3141 else | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3142 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3143 yylval.tok_val = new token (tok, input_line_number, |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3144 current_input_column); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3145 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3146 token_stack.push (yylval.tok_val); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3147 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3148 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3149 lexer_flags.quote_is_transpose = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3150 lexer_flags.convert_spaces_to_comma = true; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3151 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3152 return FCN_HANDLE; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3153 } |
4930 | 3154 } |
3155 | |
5102 | 3156 // If we have a regular keyword, return it. |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3157 // Keywords can be followed by identifiers. |
146 | 3158 |
3159 if (kw_token) | |
3160 { | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3161 if (kw_token >= 0) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3162 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3163 current_input_column += yyleng; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3164 lexer_flags.quote_is_transpose = false; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3165 lexer_flags.convert_spaces_to_comma = true; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3166 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3167 |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3168 return kw_token; |
146 | 3169 } |
3170 | |
1826 | 3171 // See if we have a plot keyword (title, using, with, or clear). |
146 | 3172 |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
3173 int c1 = text_yyinput (); |
3480 | 3174 |
3175 bool next_tok_is_eq = false; | |
3176 if (c1 == '=') | |
3177 { | |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
3178 int c2 = text_yyinput (); |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
3179 xunput (c2, yytext); |
3480 | 3180 |
3181 if (c2 != '=') | |
3182 next_tok_is_eq = true; | |
3183 } | |
3184 | |
8447
adab48231a03
make input_line_number work again
John W. Eaton <jwe@octave.org>
parents:
8312
diff
changeset
|
3185 xunput (c1, yytext); |
1001 | 3186 |
2702 | 3187 // Kluge alert. |
3188 // | |
3189 // If we are looking at a text style function, set up to gobble its | |
2745 | 3190 // arguments. |
3191 // | |
3192 // If the following token is `=', or if we are parsing a function | |
3189 | 3193 // return list or function parameter list, or if we are looking at |
3194 // something like [ab,cd] = foo (), force the symbol to be inserted | |
3195 // as a variable in the current symbol table. | |
2702 | 3196 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3197 if (! is_variable (tok)) |
2702 | 3198 { |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3199 if (at_bos && spc_gobbled && looks_like_command_arg ()) |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3200 { |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3201 BEGIN (COMMAND_START); |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3202 } |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3203 else if (next_tok_is_eq |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3204 || lexer_flags.looking_at_decl_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3205 || lexer_flags.looking_at_return_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3206 || (lexer_flags.looking_at_parameter_list |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3207 && ! lexer_flags.looking_at_initializer_expression)) |
2745 | 3208 { |
3209 force_local_variable (tok); | |
3210 } | |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3211 else if (lexer_flags.looking_at_matrix_or_assign_lhs) |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3212 { |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3213 lexer_flags.pending_local_variables.insert (tok); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3214 } |
2702 | 3215 } |
3216 | |
4234 | 3217 // Find the token in the symbol table. Beware the magic |
3218 // transformation of the end keyword... | |
3219 | |
3220 if (tok == "end") | |
3221 tok = "__end__"; | |
146 | 3222 |
7336 | 3223 yylval.tok_val = new token (&(symbol_table::insert (tok)), |
3224 input_line_number, current_input_column); | |
3225 | |
146 | 3226 token_stack.push (yylval.tok_val); |
3227 | |
1826 | 3228 // After seeing an identifer, it is ok to convert spaces to a comma |
3229 // (if needed). | |
146 | 3230 |
2857 | 3231 lexer_flags.convert_spaces_to_comma = true; |
146 | 3232 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3233 if (! (next_tok_is_eq || YY_START == COMMAND_START)) |
2877 | 3234 { |
3235 lexer_flags.quote_is_transpose = true; | |
146 | 3236 |
2877 | 3237 do_comma_insert_check (); |
3238 | |
3239 maybe_unput_comma (spc_gobbled); | |
146 | 3240 } |
3241 | |
2877 | 3242 current_input_column += yyleng; |
146 | 3243 |
3244 return NAME; | |
3245 } | |
3246 | |
1826 | 3247 void |
3248 lexical_feedback::init (void) | |
3249 { | |
3250 // Not initially defining a matrix list. | |
3351 | 3251 bracketflag = 0; |
1826 | 3252 |
4613 | 3253 // Not initially defining a cell array list. |
3254 braceflag = 0; | |
3255 | |
1826 | 3256 // Not initially inside a loop or if statement. |
3257 looping = 0; | |
3258 | |
2857 | 3259 // Not initially defining a function. |
3260 defining_func = false; | |
2877 | 3261 parsed_function_name = false; |
4240 | 3262 parsing_nested_function = 0; |
7336 | 3263 parsing_class_method = false; |
2857 | 3264 |
4930 | 3265 // Not initiallly looking at a function handle. |
3266 looking_at_function_handle = 0; | |
3267 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8537
diff
changeset
|
3268 // Not parsing a function return, parameter, or declaration list. |
2857 | 3269 looking_at_return_list = false; |
3270 looking_at_parameter_list = false; | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8537
diff
changeset
|
3271 looking_at_decl_list = false; |
2857 | 3272 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3273 // Not looking at an argument list initializer expression. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3274 looking_at_initializer_expression = false; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7587
diff
changeset
|
3275 |
3796 | 3276 // Not parsing a matrix or the left hand side of multi-value |
3277 // assignment statement. | |
3278 looking_at_matrix_or_assign_lhs = false; | |
3279 | |
4234 | 3280 // Not parsing an object index. |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3281 while (! looking_at_object_index.empty ()) |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3282 looking_at_object_index.pop_front (); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3283 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3284 looking_at_object_index.push_front (false); |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3285 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3286 // Object index not possible until we've seen something. |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
3287 looking_for_object_index = false; |
4234 | 3288 |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3289 // Yes, we are at the beginning of a statement. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3290 at_beginning_of_statement = true; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3291 |
2857 | 3292 // No need to do comma insert or convert spaces to comma at |
3293 // beginning of input. | |
3294 convert_spaces_to_comma = true; | |
3295 do_comma_insert = false; | |
3296 | |
1826 | 3297 // Not initially looking at indirect references. |
2857 | 3298 looking_at_indirect_ref = false; |
1826 | 3299 |
3300 // Quote marks strings intially. | |
2857 | 3301 quote_is_transpose = false; |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3302 |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3303 // Set of identifiers that might be local variable names is empty. |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7898
diff
changeset
|
3304 pending_local_variables.clear (); |
1826 | 3305 } |
3306 | |
4867 | 3307 bool |
3308 is_keyword (const std::string& s) | |
3309 { | |
5088 | 3310 return octave_kw_hash::in_word_set (s.c_str (), s.length ()) != 0; |
4867 | 3311 } |
3312 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
3313 DEFUN (iskeyword, args, , |
4264 | 3314 "-*- texinfo -*-\n\ |
3315 @deftypefn {Built-in Function} {} iskeyword (@var{name})\n\ | |
3316 Return true if @var{name} is an Octave keyword. If @var{name}\n\ | |
3317 is omitted, return a list of keywords.\n\ | |
3318 @end deftypefn") | |
3319 { | |
3320 octave_value retval; | |
3321 | |
3322 int argc = args.length () + 1; | |
3323 | |
4867 | 3324 string_vector argv = args.make_argv ("iskeyword"); |
4264 | 3325 |
3326 if (error_state) | |
3327 return retval; | |
3328 | |
3329 if (argc == 1) | |
3330 { | |
3331 string_vector lst (TOTAL_KEYWORDS); | |
3332 | |
3333 for (int i = 0; i < TOTAL_KEYWORDS; i++) | |
3334 lst[i] = wordlist[i].name; | |
3335 | |
8504
0e0bd07e6ae2
omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
8447
diff
changeset
|
3336 retval = Cell (lst.sort ()); |
4264 | 3337 } |
3338 else if (argc == 2) | |
3339 { | |
4867 | 3340 retval = is_keyword (argv[1]); |
4264 | 3341 } |
3342 else | |
5823 | 3343 print_usage (); |
4264 | 3344 |
3345 return retval; | |
3346 } | |
3347 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3348 void |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3349 prep_lexer_for_script (void) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3350 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3351 BEGIN (SCRIPT_FILE_BEGIN); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
3352 } |
4264 | 3353 |
3388 | 3354 static void |
3355 maybe_warn_separator_insert (char sep) | |
3356 { | |
3523 | 3357 std::string nm = curr_fcn_file_full_name; |
3388 | 3358 |
5794 | 3359 if (nm.empty ()) |
3360 warning_with_id ("Octave:separator-insert", | |
3361 "potential auto-insertion of `%c' near line %d", | |
3362 sep, input_line_number); | |
3363 else | |
3364 warning_with_id ("Octave:separator-insert", | |
3365 "potential auto-insertion of `%c' near line %d of file %s", | |
3366 sep, input_line_number, nm.c_str ()); | |
3388 | 3367 } |
3368 | |
3400 | 3369 static void |
3370 gripe_single_quote_string (void) | |
3371 { | |
3523 | 3372 std::string nm = curr_fcn_file_full_name; |
3400 | 3373 |
5794 | 3374 if (nm.empty ()) |
3375 warning_with_id ("Octave:single-quote-string", | |
3376 "single quote delimited string near line %d", | |
3377 input_line_number); | |
3378 else | |
3379 warning_with_id ("Octave:single-quote-string", | |
3380 "single quote delimited string near line %d of file %s", | |
3381 input_line_number, nm.c_str ()); | |
3400 | 3382 } |
3383 | |
4037 | 3384 static void |
3385 gripe_matlab_incompatible (const std::string& msg) | |
3386 { | |
5794 | 3387 warning_with_id ("Octave:matlab-incompatible", |
3388 "potential Matlab compatibility problem: %s", | |
3389 msg.c_str ()); | |
4037 | 3390 } |
3391 | |
3392 static void | |
3393 maybe_gripe_matlab_incompatible_comment (char c) | |
3394 { | |
3395 if (c == '#') | |
3396 gripe_matlab_incompatible ("# used as comment character"); | |
3397 } | |
3398 | |
3399 static void | |
3400 gripe_matlab_incompatible_continuation (void) | |
3401 { | |
3402 gripe_matlab_incompatible ("\\ used as line continuation marker"); | |
3403 } | |
3404 | |
3405 static void | |
3406 gripe_matlab_incompatible_operator (const std::string& op) | |
3407 { | |
3408 std::string t = op; | |
3409 int n = t.length (); | |
3410 if (t[n-1] == '\n') | |
3411 t.resize (n-1); | |
3412 gripe_matlab_incompatible (t + " used as operator"); | |
3413 } | |
3414 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3415 static void |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3416 display_token (int tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3417 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3418 switch (tok) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3419 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3420 case '=': std::cerr << "'='\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3421 case ':': std::cerr << "':'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3422 case '-': std::cerr << "'-'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3423 case '+': std::cerr << "'+'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3424 case '*': std::cerr << "'*'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3425 case '/': std::cerr << "'/'\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3426 case ADD_EQ: std::cerr << "ADD_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3427 case SUB_EQ: std::cerr << "SUB_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3428 case MUL_EQ: std::cerr << "MUL_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3429 case DIV_EQ: std::cerr << "DIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3430 case LEFTDIV_EQ: std::cerr << "LEFTDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3431 case POW_EQ: std::cerr << "POW_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3432 case EMUL_EQ: std::cerr << "EMUL_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3433 case EDIV_EQ: std::cerr << "EDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3434 case ELEFTDIV_EQ: std::cerr << "ELEFTDIV_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3435 case EPOW_EQ: std::cerr << "EPOW_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3436 case AND_EQ: std::cerr << "AND_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3437 case OR_EQ: std::cerr << "OR_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3438 case LSHIFT_EQ: std::cerr << "LSHIFT_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3439 case RSHIFT_EQ: std::cerr << "RSHIFT_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3440 case LSHIFT: std::cerr << "LSHIFT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3441 case RSHIFT: std::cerr << "RSHIFT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3442 case EXPR_AND_AND: std::cerr << "EXPR_AND_AND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3443 case EXPR_OR_OR: std::cerr << "EXPR_OR_OR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3444 case EXPR_AND: std::cerr << "EXPR_AND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3445 case EXPR_OR: std::cerr << "EXPR_OR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3446 case EXPR_NOT: std::cerr << "EXPR_NOT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3447 case EXPR_LT: std::cerr << "EXPR_LT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3448 case EXPR_LE: std::cerr << "EXPR_LE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3449 case EXPR_EQ: std::cerr << "EXPR_EQ\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3450 case EXPR_NE: std::cerr << "EXPR_NE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3451 case EXPR_GE: std::cerr << "EXPR_GE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3452 case EXPR_GT: std::cerr << "EXPR_GT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3453 case LEFTDIV: std::cerr << "LEFTDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3454 case EMUL: std::cerr << "EMUL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3455 case EDIV: std::cerr << "EDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3456 case ELEFTDIV: std::cerr << "ELEFTDIV\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3457 case EPLUS: std::cerr << "EPLUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3458 case EMINUS: std::cerr << "EMINUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3459 case QUOTE: std::cerr << "QUOTE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3460 case TRANSPOSE: std::cerr << "TRANSPOSE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3461 case PLUS_PLUS: std::cerr << "PLUS_PLUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3462 case MINUS_MINUS: std::cerr << "MINUS_MINUS\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3463 case POW: std::cerr << "POW\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3464 case EPOW: std::cerr << "EPOW\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3465 case NUM: std::cerr << "NUM\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3466 case IMAG_NUM: std::cerr << "IMAG_NUM\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3467 case STRUCT_ELT: std::cerr << "STRUCT_ELT\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3468 case NAME: std::cerr << "NAME\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3469 case END: std::cerr << "END\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3470 case DQ_STRING: std::cerr << "DQ_STRING\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3471 case SQ_STRING: std::cerr << "SQ_STRING\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3472 case FOR: std::cerr << "FOR\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3473 case WHILE: std::cerr << "WHILE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3474 case DO: std::cerr << "DO\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3475 case UNTIL: std::cerr << "UNTIL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3476 case IF: std::cerr << "IF\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3477 case ELSEIF: std::cerr << "ELSEIF\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3478 case ELSE: std::cerr << "ELSE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3479 case SWITCH: std::cerr << "SWITCH\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3480 case CASE: std::cerr << "CASE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3481 case OTHERWISE: std::cerr << "OTHERWISE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3482 case BREAK: std::cerr << "BREAK\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3483 case CONTINUE: std::cerr << "CONTINUE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3484 case FUNC_RET: std::cerr << "FUNC_RET\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3485 case UNWIND: std::cerr << "UNWIND\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3486 case CLEANUP: std::cerr << "CLEANUP\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3487 case TRY: std::cerr << "TRY\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3488 case CATCH: std::cerr << "CATCH\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3489 case GLOBAL: std::cerr << "GLOBAL\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3490 case STATIC: std::cerr << "STATIC\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3491 case FCN_HANDLE: std::cerr << "FCN_HANDLE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3492 case END_OF_INPUT: std::cerr << "END_OF_INPUT\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3493 case LEXICAL_ERROR: std::cerr << "LEXICAL_ERROR\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3494 case FCN: std::cerr << "FCN\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3495 case CLOSE_BRACE: std::cerr << "CLOSE_BRACE\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3496 case '\n': std::cerr << "\\n\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3497 case '\r': std::cerr << "\\r\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3498 case '\t': std::cerr << "TAB\n"; break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3499 default: |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3500 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3501 if (tok < 256) |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3502 std::cerr << static_cast<char> (tok) << "\n"; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3503 else |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3504 std::cerr << "UNKNOWN(" << tok << ")\n"; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3505 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3506 break; |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3507 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3508 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3509 |
8535 | 3510 static void |
3511 display_state (void) | |
3512 { | |
3513 std::cerr << "S: "; | |
3514 | |
3515 switch (YY_START) | |
3516 { | |
3517 case INITIAL: | |
3518 std::cerr << "INITIAL" << std::endl; | |
3519 break; | |
3520 | |
3521 case COMMAND_START: | |
3522 std::cerr << "COMMAND_START" << std::endl; | |
3523 break; | |
3524 | |
3525 case MATRIX_START: | |
3526 std::cerr << "MATRIX_START" << std::endl; | |
3527 break; | |
3528 | |
3529 case SCRIPT_FILE_BEGIN: | |
3530 std::cerr << "SCRIPT_FILE_BEGIN" << std::endl; | |
3531 break; | |
3532 | |
3533 case NESTED_FUNCTION_END: | |
3534 std::cerr << "NESTED_FUNCTION_END" << std::endl; | |
3535 break; | |
3536 | |
3537 case NESTED_FUNCTION_BEGIN: | |
3538 std::cerr << "NESTED_FUNCTION_BEGIN" << std::endl; | |
3539 break; | |
3540 | |
3541 default: | |
3542 std::cerr << "UNKNOWN START STATE!" << std::endl; | |
3543 break; | |
3544 } | |
3545 } | |
3546 | |
3547 static void | |
3548 lexer_debug (const char *pattern, const char *text) | |
3549 { | |
3550 std::cerr << std::endl; | |
3551 | |
3552 display_state (); | |
3553 | |
3554 std::cerr << "P: " << pattern << std::endl; | |
3555 std::cerr << "T: " << text << std::endl; | |
3556 } | |
3557 | |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3558 DEFUN (__display_tokens__, args, nargout, |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3559 "-*- texinfo -*-\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3560 @deftypefn {Built-in Function} {} __display_tokens__ ()\n\ |
7722
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3561 Query or set the internal variable that determines whether Octave's\n\ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3562 lexer displays tokens as they are read.\n\ |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3563 @end deftypefn") |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3564 { |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3565 return SET_INTERNAL_VARIABLE (display_tokens); |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3566 } |
c3bb0b7a4261
lex.l: allow tokens to be displayed when parsed
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
3567 |
4910 | 3568 DEFUN (__token_count__, , , |
3569 "-*- texinfo -*-\n\ | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3570 @deftypefn {Built-in Function} {} __token_count__ ()\n\ |
4910 | 3571 Number of language tokens processed since Octave startup.\n\ |
3572 @end deftypefn") | |
3573 { | |
3574 return octave_value (Vtoken_count); | |
3575 } | |
3576 | |
8535 | 3577 DEFUN (__lexer_debug_flag__, args, nargout, |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3578 "-*- texinfo -*-\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3579 @deftypefn {Built-in Function} {@var{old_val} =} __lexer_debug_flag__ (@var{new_val}))\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3580 Undocumented internal function.\n\ |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8767
diff
changeset
|
3581 @end deftypefn") |
8535 | 3582 { |
3583 octave_value retval; | |
3584 | |
3585 retval = set_internal_variable (lexer_debug_flag, args, nargout, | |
3586 "__lexer_debug_flag__"); | |
3587 | |
3588 return retval; | |
3589 } | |
3590 | |
1994 | 3591 /* |
3592 ;;; Local Variables: *** | |
3593 ;;; mode: C++ *** | |
3594 ;;; End: *** | |
3595 */ |