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