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