annotate libinterp/parse-tree/lex.h @ 16183:359d56094efa

handle lexer input buffering with class * lex.h, lex.ll (octave_lexer::input_buffer): New class. (octave_lexer::input_buf): New data member. (octave_lexer::octave_lexer): Initialize it. (octave_lexer::octave_read): Use input_buf to simplify function and replace static data.
author John W. Eaton <jwe@octave.org>
date Sun, 03 Mar 2013 14:02:41 -0500
parents c5bfdc4c0963
children e810e7d941a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13973
diff changeset
3 Copyright (C) 1993-2012 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
10 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
19 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
383
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 247
diff changeset
23 #if !defined (octave_lex_h)
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 247
diff changeset
24 #define octave_lex_h 1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
26 #include <list>
16101
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
27 #include <set>
11464
21b5284fa78d avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents: 11367
diff changeset
28 #include <stack>
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
29
13973
2c664266e9d0 clean up parser memory on exit
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
30 extern OCTINTERP_API void cleanup_parser (void);
2c664266e9d0 clean up parser memory on exit
John W. Eaton <jwe@octave.org>
parents: 13237
diff changeset
31
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
32 // Is the given string a keyword?
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
33 extern bool is_keyword (const std::string& s);
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
34
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
35 class
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
36 stream_reader
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
37 {
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
38 public:
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
39 virtual int getc (void) = 0;
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
40 virtual int ungetc (int c) = 0;
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
41
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
42 protected:
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
43 stream_reader (void) { }
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
44 ~stream_reader (void) { }
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
45
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
46 private:
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
47
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
48 // No copying!
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
49 stream_reader (const stream_reader&);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
50 stream_reader& operator = (const stream_reader&);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
51 };
16111
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
52
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
53 // Forward decl for octave_lexer::token_stack.
16111
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
54 class token;
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
55
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
56 // For communication between the lexer and parser.
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
57
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3351
diff changeset
58 class
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
59 octave_lexer
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
60 {
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
61 public:
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
62
16106
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
63 // Did eat_whitespace or eat_continuation eat a space or tab, or a
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
64 // newline, or both?
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
65 //
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
66 // Functions that return this type will return a logical OR of the
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
67 // following values:
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
68 //
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
69 // NO_WHITESPACE no spaces to eat
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
70 // SPACE_OR_TAB space or tab in input
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
71 // NEWLINE bare new line in input
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
72
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
73 enum whitespace_type
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
74 {
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
75 NO_WHITESPACE = 1,
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
76 SPACE_OR_TAB = 2,
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
77 NEWLINE = 4
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
78 };
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
79
031117f4db7c use enum for values returned by eat_continuation and eat_whitespace
John W. Eaton <jwe@octave.org>
parents: 16105
diff changeset
80
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
81 // Track nesting of square brackets, curly braces, and parentheses.
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
82
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
83 class bbp_nesting_level
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
84 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
85 private:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
86
16107
3b791008b88e give name to anonymous enum
John W. Eaton <jwe@octave.org>
parents: 16106
diff changeset
87 enum bracket_type
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
88 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
89 BRACKET = 1,
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
90 BRACE = 2,
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
91 PAREN = 3
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
92 };
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
93
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
94 public:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
95
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
96 bbp_nesting_level (void) : context () { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
97
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
98 bbp_nesting_level (const bbp_nesting_level& nl) : context (nl.context) { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
99
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
100 bbp_nesting_level& operator = (const bbp_nesting_level& nl)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
101 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
102 if (&nl != this)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
103 context = nl.context;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
105 return *this;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
106 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
107
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
108 ~bbp_nesting_level (void) { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
109
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
110 void bracket (void) { context.push (BRACKET); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
111
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
112 bool is_bracket (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
113 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
114 return ! context.empty () && context.top () == BRACKET;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
115 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
116
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
117 void brace (void) { context.push (BRACE); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
118
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
119 bool is_brace (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
120 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
121 return ! context.empty () && context.top () == BRACE;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
122 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
123
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
124 void paren (void) { context.push (PAREN); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
125
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
126 bool is_paren (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
127 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
128 return ! context.empty () && context.top () == PAREN;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
129 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
130
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
131 bool is_bracket_or_brace (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
132 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
133 return (! context.empty ()
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
134 && (context.top () == BRACKET || context.top () == BRACE));
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
135 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
136
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
137 bool none (void) { return context.empty (); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
138
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
139 void remove (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
140 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
141 if (! context.empty ())
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
142 context.pop ();
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
143 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
144
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
145 void clear (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
146 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
147 while (! context.empty ())
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
148 context.pop ();
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
149 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
150
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
151 private:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
152
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
153 std::stack<int> context;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
154 };
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
155
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
156 // Handle buffering of input for lexer.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
157
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
158 class input_buffer
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
159 {
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
160 public:
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
161
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
162 input_buffer (void)
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
163 : buffer (), pos (0), chars_left (0), eof (false)
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
164 { }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
165
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
166 // Grab more input from the current input source.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
167 void read (void);
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
168
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
169 // Copy at most max_size characters to buf.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
170 int copy_chunk (char *buf, size_t max_size);
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
171
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
172 bool empty (void) const { return chars_left == 0; }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
173
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
174 bool at_eof (void) const { return eof; }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
175
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
176 private:
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
177
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
178 std::string buffer;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
179 const char *pos;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
180 size_t chars_left;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
181 bool eof;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
182 };
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
183
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
184 octave_lexer (void)
16164
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
185 : scanner (0), end_of_input (false), convert_spaces_to_comma (true),
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
186 do_comma_insert (false), at_beginning_of_statement (true),
16101
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
187 looking_at_anon_fcn_args (false), looking_at_return_list (false),
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
188 looking_at_parameter_list (false), looking_at_decl_list (false),
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
189 looking_at_initializer_expression (false),
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
190 looking_at_matrix_or_assign_lhs (false),
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
191 looking_for_object_index (false),
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
192 looking_at_indirect_ref (false), parsing_class_method (false),
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
193 maybe_classdef_get_set_method (false), parsing_classdef (false),
16139
2fd39ab12209 move a function and data member from lexical_feedback to octave_parser
John W. Eaton <jwe@octave.org>
parents: 16130
diff changeset
194 quote_is_transpose (false),
16103
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
195 input_line_number (1), current_input_column (1),
16102
679a54d274d9 move global parser_end_of_input variable to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16101
diff changeset
196 bracketflag (0), braceflag (0),
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
197 looping (0), defining_func (0), looking_at_function_handle (0),
16105
b7de58feb2d3 move block_comment_nesting_level to lexical_feedback_class
John W. Eaton <jwe@octave.org>
parents: 16104
diff changeset
198 block_comment_nesting_level (0),
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
199 looking_at_object_index (), parsed_function_name (),
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
200 pending_local_variables (), nesting_level (), input_buf ()
16101
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
201 {
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
202 init ();
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
203 }
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
204
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
205 ~octave_lexer (void);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
206
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
207 void init (void);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
208
16139
2fd39ab12209 move a function and data member from lexical_feedback to octave_parser
John W. Eaton <jwe@octave.org>
parents: 16130
diff changeset
209 void reset (void);
16122
6884401b2fbb move reset_parser lexer helper function to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16120
diff changeset
210
16124
3be725cd195b move more lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16122
diff changeset
211 void prep_for_script_file (void);
3be725cd195b move more lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16122
diff changeset
212
3be725cd195b move more lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16122
diff changeset
213 void prep_for_function_file (void);
3be725cd195b move more lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16122
diff changeset
214
16120
4b68eb9b98b0 move octave_read lexer helper function to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16118
diff changeset
215 int octave_read (char *buf, unsigned int max_size);
4b68eb9b98b0 move octave_read lexer helper function to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16118
diff changeset
216
16164
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
217 int handle_end_of_input (void);
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
218
16128
210039e91ad6 localize use of yytext with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16126
diff changeset
219 char *flex_yytext (void);
210039e91ad6 localize use of yytext with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16126
diff changeset
220
16130
421dea028bbf localize use of yyleng with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16129
diff changeset
221 int flex_yyleng (void);
421dea028bbf localize use of yyleng with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16129
diff changeset
222
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
223 void do_comma_insert_check (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
224
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
225 int text_yyinput (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
226
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
227 void xunput (char c, char *buf);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
228
16125
96a58f197f93 allow xunput to be called without buffer argument
John W. Eaton <jwe@octave.org>
parents: 16124
diff changeset
229 void xunput (char c);
96a58f197f93 allow xunput to be called without buffer argument
John W. Eaton <jwe@octave.org>
parents: 16124
diff changeset
230
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
231 void fixup_column_count (char *s);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
232
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
233 bool inside_any_object_index (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
234
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
235 int is_keyword_token (const std::string& s);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
236
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
237 bool is_variable (const std::string& name);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
238
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
239 std::string grab_block_comment (stream_reader& reader, bool& eof);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
240
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
241 std::string grab_comment_block (stream_reader& reader, bool at_bol,
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
242 bool& eof);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
243
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
244 int process_comment (bool start_in_block, bool& eof);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
245
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
246 bool next_token_is_sep_op (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
247
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
248 bool next_token_is_postfix_unary_op (bool spc_prev);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
249
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
250 bool next_token_is_bin_op (bool spc_prev);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
251
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
252 void scan_for_comments (const char *text);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
253
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
254 int eat_whitespace (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
255
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
256 void handle_number (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
257
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
258 bool have_continuation (bool trailing_comments_ok = true);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
259
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
260 bool have_ellipsis_continuation (bool trailing_comments_ok = true);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
261
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
262 int eat_continuation (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
263
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
264 int handle_string (char delim);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
265
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
266 bool next_token_is_assign_op (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
267
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
268 bool next_token_is_index_op (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
269
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
270 int handle_close_bracket (bool spc_gobbled, int bracket_type);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
271
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
272 void maybe_unput_comma (int spc_gobbled);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
273
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
274 bool next_token_can_follow_bin_op (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
275
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
276 bool looks_like_command_arg (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
277
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
278 int handle_superclass_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
279
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
280 int handle_meta_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
281
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
282 int handle_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
283
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
284 void maybe_warn_separator_insert (char sep);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
285
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
286 void gripe_single_quote_string (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
287
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
288 void gripe_matlab_incompatible (const std::string& msg);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
289
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
290 void maybe_gripe_matlab_incompatible_comment (char c);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
291
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
292 void gripe_matlab_incompatible_continuation (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
293
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
294 void gripe_matlab_incompatible_operator (const std::string& op);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
295
16126
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
296 void push_token (token *);
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
297
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
298 token *current_token (void);
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
299
16118
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
300 void display_token (int tok);
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
301
16129
053b0364b507 localize use of yy_fatal_error with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16128
diff changeset
302 void fatal_error (const char *msg);
053b0364b507 localize use of yy_fatal_error with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16128
diff changeset
303
16118
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
304 void lexer_debug (const char *pattern, const char *text);
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
305
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
306 // Internal state of the flex-generated lexer.
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
307 void *scanner;
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
308
16164
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
309 // TRUE means that we have encountered EOF on the input stream.
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
310 bool end_of_input;
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
311
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2857
diff changeset
312 // TRUE means that we should convert spaces to a comma inside a
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
313 // matrix definition.
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
314 bool convert_spaces_to_comma;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
315
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
316 // GAG. Stupid kludge so that [[1,2][3,4]] will work.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
317 bool do_comma_insert;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
318
8746
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
319 // TRUE means we are at the beginning of a statement, where a
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
320 // command name is possible.
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
321 bool at_beginning_of_statement;
5dd06f19e9be handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents: 8745
diff changeset
322
13237
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
323 // TRUE means we are parsing an anonymous function argument list.
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
324 bool looking_at_anon_fcn_args;
1bfca2bbea8b fix parsing of anonymous functions inside cell array lists.
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
325
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2857
diff changeset
326 // TRUE means we're parsing the return list for a function.
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
327 bool looking_at_return_list;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
328
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2857
diff changeset
329 // TRUE means we're parsing the parameter list for a function.
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
330 bool looking_at_parameter_list;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
331
8701
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
332 // TRUE means we're parsing a declaration list (global or
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
333 // persistent).
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
334 bool looking_at_decl_list;
1652e39b934e handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents: 8001
diff changeset
335
7634
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
336 // TRUE means we are looking at the initializer expression for a
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
337 // parameter list element.
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
338 bool looking_at_initializer_expression;
ae90e05ad299 fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
339
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3165
diff changeset
340 // TRUE means we're parsing a matrix or the left hand side of
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3165
diff changeset
341 // multi-value assignment statement.
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3165
diff changeset
342 bool looking_at_matrix_or_assign_lhs;
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3165
diff changeset
343
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
344 // Object index not possible until we've seen something.
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
345 bool looking_for_object_index;
4234
90e44267e8cf [project @ 2002-12-21 17:15:25 by jwe]
jwe
parents: 4182
diff changeset
346
2877
5c1b9e545dd1 [project @ 1997-04-24 09:07:39 by jwe]
jwe
parents: 2857
diff changeset
347 // TRUE means we're looking at an indirect reference to a
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
348 // structure element.
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
349 bool looking_at_indirect_ref;
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
350
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
351 // TRUE means we are parsing a class method in function or classdef file.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
352 bool parsing_class_method;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
353
9476
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
354 // TRUE means we are parsing a class method declaration line in a
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
355 // classdef file and can accept a property get or set method name.
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
356 // For example, "get.PropertyName" is recognized as a function name.
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
357 bool maybe_classdef_get_set_method;
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
358
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
359 // TRUE means we are parsing a classdef file
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
360 bool parsing_classdef;
d9b25c5b8ee5 handle classdef syntax in lexer and parser
Ryan Rusaw
parents: 9474
diff changeset
361
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
362 // Return transpose or start a string?
2857
5448c8cba402 [project @ 1997-03-31 07:06:10 by jwe]
jwe
parents: 2847
diff changeset
363 bool quote_is_transpose;
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
364
16103
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
365 // The current input line number.
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
366 int input_line_number;
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
367
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
368 // The column of the current token.
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
369 int current_input_column;
6434f70f0ee0 move input_line_number and current_input_column to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16102
diff changeset
370
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
371 // Square bracket level count.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
372 int bracketflag;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
373
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
374 // Curly brace level count.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
375 int braceflag;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
376
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
377 // TRUE means we're in the middle of defining a loop.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
378 int looping;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
379
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
380 // Nonzero means we're in the middle of defining a function.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
381 int defining_func;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
382
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
383 // Nonzero means we are parsing a function handle.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
384 int looking_at_function_handle;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
385
16105
b7de58feb2d3 move block_comment_nesting_level to lexical_feedback_class
John W. Eaton <jwe@octave.org>
parents: 16104
diff changeset
386 // Nestng level for blcok comments.
b7de58feb2d3 move block_comment_nesting_level to lexical_feedback_class
John W. Eaton <jwe@octave.org>
parents: 16104
diff changeset
387 int block_comment_nesting_level;
b7de58feb2d3 move block_comment_nesting_level to lexical_feedback_class
John W. Eaton <jwe@octave.org>
parents: 16104
diff changeset
388
16100
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
389 // If the front of the list is TRUE, the closest paren, brace, or
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
390 // bracket nesting is an index for an object.
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
391 std::list<bool> looking_at_object_index;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
392
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
393 // If the top of the stack is TRUE, then we've already seen the name
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
394 // of the current function. Should only matter if
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
395 // current_function_level > 0
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
396 std::stack<bool> parsed_function_name;
6b26e18d1dcb reorder data members in lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
397
8001
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7723
diff changeset
398 // Set of identifiers that might be local variable names.
ff9e7873f8ea improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents: 7723
diff changeset
399 std::set<std::string> pending_local_variables;
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
400
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
401 // Is the closest nesting level a square bracket, squiggly brace or
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
402 // a paren?
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
403 bbp_nesting_level nesting_level;
16110
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
404
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
405 // Object that reads and buffers input.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
406 input_buffer input_buf;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
407
16126
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
408 // For unwind protect.
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
409 static void cleanup (octave_lexer *lexer) { delete lexer; }
16126
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
410
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
411 private:
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
412
16111
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
413 // Stack to hold tokens so that we can delete them when the parser is
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
414 // reset and avoid growing forever just because we are stashing some
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
415 // information.
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
416 std::stack <token*> token_stack;
3ec4f6488569 move token stack to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16110
diff changeset
417
16110
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
418 // No copying!
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
419
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
420 octave_lexer (const octave_lexer&);
16110
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
421
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
422 octave_lexer& operator = (const octave_lexer&);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
423 };
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
424
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
425 #endif