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