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