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