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