Mercurial > hg > octave-lyh
annotate src/lex.h @ 12164:18e9a8da7d18
eliminate some -Weffc++ warnings
author | Pascal Dupuis <Pascal.Dupuis@uclouvain.be> |
---|---|
date | Wed, 26 Jan 2011 05:20:33 -0500 |
parents | 12df7854fa7c |
children | 1bfca2bbea8b |
rev | line source |
---|---|
1 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1993-2011 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
383 | 23 #if !defined (octave_lex_h) |
24 #define octave_lex_h 1 | |
1 | 25 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
26 #include <list> |
11464
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11367
diff
changeset
|
27 #include <stack> |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
28 |
5775 | 29 // FIXME -- these input buffer things should be members of a |
1826 | 30 // parser input stream class. |
31 | |
1 | 32 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
33 | |
34 // Associate a buffer with a new file to read. | |
9247
b2790fd23800
More export symbols to allow usage from an IDE.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8920
diff
changeset
|
35 extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); |
1 | 36 |
37 // Report the current buffer. | |
9247
b2790fd23800
More export symbols to allow usage from an IDE.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8920
diff
changeset
|
38 extern OCTINTERP_API YY_BUFFER_STATE current_buffer (void); |
1 | 39 |
40 // Connect to new buffer buffer. | |
9247
b2790fd23800
More export symbols to allow usage from an IDE.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8920
diff
changeset
|
41 extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); |
1 | 42 |
43 // Delete a buffer. | |
9247
b2790fd23800
More export symbols to allow usage from an IDE.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
8920
diff
changeset
|
44 extern OCTINTERP_API void delete_buffer (YY_BUFFER_STATE buf); |
1 | 45 |
4867 | 46 // Is the given string a keyword? |
47 extern bool is_keyword (const std::string& s); | |
48 | |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9396
diff
changeset
|
49 extern void prep_lexer_for_script_file (void); |
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9396
diff
changeset
|
50 extern void prep_lexer_for_function_file (void); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
51 |
1826 | 52 // For communication between the lexer and parser. |
53 | |
3585 | 54 class |
55 lexical_feedback | |
1826 | 56 { |
57 public: | |
58 | |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
59 lexical_feedback (void) |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
60 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
61 : bracketflag (0), braceflag (0), looping (0), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
62 convert_spaces_to_comma (true), at_beginning_of_statement (true), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
63 defining_func (0), looking_at_function_handle (false), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
64 looking_at_return_list (false), looking_at_parameter_list (false), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
65 looking_at_decl_list (false), looking_at_initializer_expression (false), |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
66 looking_at_matrix_or_assign_lhs (false), looking_at_object_index (), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
67 looking_for_object_index (false), do_comma_insert (false), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
68 looking_at_indirect_ref (false), parsed_function_name (), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
69 parsing_class_method (false), maybe_classdef_get_set_method (false), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
70 parsing_classdef (false), quote_is_transpose (false), |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
71 pending_local_variables () |
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
72 |
11515
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
73 { |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
74 init (); |
6dbf9bcce90e
more data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
11464
diff
changeset
|
75 } |
1826 | 76 |
77 ~lexical_feedback (void) { } | |
78 | |
79 void init (void); | |
80 | |
3351 | 81 // Square bracket level count. |
82 int bracketflag; | |
1826 | 83 |
4613 | 84 // Curly brace level count. |
85 int braceflag; | |
86 | |
2877 | 87 // TRUE means we're in the middle of defining a loop. |
1826 | 88 int looping; |
89 | |
2877 | 90 // TRUE means that we should convert spaces to a comma inside a |
2857 | 91 // matrix definition. |
92 bool convert_spaces_to_comma; | |
93 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
94 // 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
|
95 // command name is possible. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
96 bool at_beginning_of_statement; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
97 |
11367
b2191ebea12f
don't process input_event_hook when we are parsing a function
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
98 // Nonzero means we're in the middle of defining a function. |
b2191ebea12f
don't process input_event_hook when we are parsing a function
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
99 int defining_func; |
2857 | 100 |
4930 | 101 // Nonzero means we are parsing a function handle. |
102 int looking_at_function_handle; | |
103 | |
2877 | 104 // TRUE means we're parsing the return list for a function. |
2857 | 105 bool looking_at_return_list; |
106 | |
2877 | 107 // TRUE means we're parsing the parameter list for a function. |
2857 | 108 bool looking_at_parameter_list; |
109 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
110 // 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
|
111 // persistent). |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
112 bool looking_at_decl_list; |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
113 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
114 // 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
|
115 // parameter list element. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
116 bool looking_at_initializer_expression; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
117 |
3189 | 118 // TRUE means we're parsing a matrix or the left hand side of |
119 // multi-value assignment statement. | |
120 bool looking_at_matrix_or_assign_lhs; | |
121 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
122 // If the front of the list is TRUE, the closest paren, brace, or |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
123 // bracket nesting is an index for an object. |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
124 std::list<bool> looking_at_object_index; |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
125 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
126 // 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
|
127 bool looking_for_object_index; |
4234 | 128 |
2857 | 129 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
130 bool do_comma_insert; | |
131 | |
2877 | 132 // TRUE means we're looking at an indirect reference to a |
2857 | 133 // structure element. |
134 bool looking_at_indirect_ref; | |
135 | |
11464
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11367
diff
changeset
|
136 // If the top of the stack is TRUE, then we've already seen the name |
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11367
diff
changeset
|
137 // of the current function. Should only matter if |
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11367
diff
changeset
|
138 // current_function_level > 0 |
21b5284fa78d
avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents:
11367
diff
changeset
|
139 std::stack<bool> parsed_function_name; |
2877 | 140 |
9476 | 141 // TRUE means we are parsing a class method in function or classdef file. |
7336 | 142 bool parsing_class_method; |
143 | |
9476 | 144 // TRUE means we are parsing a class method declaration line in a |
145 // classdef file and can accept a property get or set method name. | |
146 // For example, "get.PropertyName" is recognized as a function name. | |
147 bool maybe_classdef_get_set_method; | |
148 | |
149 // TRUE means we are parsing a classdef file | |
150 bool parsing_classdef; | |
151 | |
1826 | 152 // Return transpose or start a string? |
2857 | 153 bool quote_is_transpose; |
1826 | 154 |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
155 // 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
|
156 std::set<std::string> pending_local_variables; |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
157 |
1826 | 158 private: |
159 | |
160 lexical_feedback (const lexical_feedback&); | |
161 | |
162 lexical_feedback& operator = (const lexical_feedback&); | |
163 }; | |
164 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
165 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
166 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
|
167 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
168 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
169 virtual int getc (void) = 0; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
170 virtual int ungetc (int c) = 0; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
171 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
172 protected: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
173 stream_reader (void) { } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
174 ~stream_reader (void) { } |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
175 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
176 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
177 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
178 // No copying! |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
179 stream_reader (const 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
|
180 stream_reader& operator = (const 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
|
181 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
182 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
183 extern std::string |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
184 grab_comment_block (stream_reader& reader, bool at_bol, bool& 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
|
185 |
3883 | 186 // TRUE means that we have encountered EOF on the input stream. |
187 extern bool parser_end_of_input; | |
188 | |
1826 | 189 // Flags that need to be shared between the lexer and parser. |
190 extern lexical_feedback lexer_flags; | |
440 | 191 |
1 | 192 #endif |