Mercurial > hg > octave-lyh
annotate src/lex.h @ 9892:ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
author | Kacper Kowalik <xarthisius.kk@gmail.com> |
---|---|
date | Tue, 01 Dec 2009 00:49:07 +0100 |
parents | d9b25c5b8ee5 |
children | cd96d29c5efa |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, |
8920 | 4 2003, 2004, 2005, 2006, 2007, 2008, 2009 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 | |
383 | 24 #if !defined (octave_lex_h) |
25 #define octave_lex_h 1 | |
1 | 26 |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
27 #include <list> |
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 | |
59 lexical_feedback (void) { init (); } | |
60 | |
61 ~lexical_feedback (void) { } | |
62 | |
63 void init (void); | |
64 | |
3351 | 65 // Square bracket level count. |
66 int bracketflag; | |
1826 | 67 |
4613 | 68 // Curly brace level count. |
69 int braceflag; | |
70 | |
2877 | 71 // TRUE means we're in the middle of defining a loop. |
1826 | 72 int looping; |
73 | |
2877 | 74 // TRUE means that we should convert spaces to a comma inside a |
2857 | 75 // matrix definition. |
76 bool convert_spaces_to_comma; | |
77 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
78 // 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
|
79 // command name is possible. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
80 bool at_beginning_of_statement; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
81 |
2877 | 82 // TRUE means we're in the middle of defining a function. |
2857 | 83 bool defining_func; |
84 | |
4930 | 85 // Nonzero means we are parsing a function handle. |
86 int looking_at_function_handle; | |
87 | |
2877 | 88 // TRUE means we're parsing the return list for a function. |
2857 | 89 bool looking_at_return_list; |
90 | |
2877 | 91 // TRUE means we're parsing the parameter list for a function. |
2857 | 92 bool looking_at_parameter_list; |
93 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
94 // 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
|
95 // persistent). |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
96 bool looking_at_decl_list; |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
97 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
98 // 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
|
99 // parameter list element. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
100 bool looking_at_initializer_expression; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
101 |
3189 | 102 // TRUE means we're parsing a matrix or the left hand side of |
103 // multi-value assignment statement. | |
104 bool looking_at_matrix_or_assign_lhs; | |
105 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
106 // 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
|
107 // 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
|
108 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
|
109 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
110 // 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
|
111 bool looking_for_object_index; |
4234 | 112 |
2857 | 113 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
114 bool do_comma_insert; | |
115 | |
2877 | 116 // TRUE means we're looking at an indirect reference to a |
2857 | 117 // structure element. |
118 bool looking_at_indirect_ref; | |
119 | |
2877 | 120 // TRUE means that we've already seen the name of this function. |
9474
25ed2d6aacf6
Parse nested functions more accurately.
David Grundberg <individ@acc.umu.se>
parents:
9396
diff
changeset
|
121 // Should only matter if current_function_level > 0 |
2877 | 122 bool parsed_function_name; |
123 | |
9476 | 124 // TRUE means we are parsing a class method in function or classdef file. |
7336 | 125 bool parsing_class_method; |
126 | |
9476 | 127 // TRUE means we are parsing a class method declaration line in a |
128 // classdef file and can accept a property get or set method name. | |
129 // For example, "get.PropertyName" is recognized as a function name. | |
130 bool maybe_classdef_get_set_method; | |
131 | |
132 // TRUE means we are parsing a classdef file | |
133 bool parsing_classdef; | |
134 | |
1826 | 135 // Return transpose or start a string? |
2857 | 136 bool quote_is_transpose; |
1826 | 137 |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
138 // 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
|
139 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
|
140 |
1826 | 141 private: |
142 | |
143 lexical_feedback (const lexical_feedback&); | |
144 | |
145 lexical_feedback& operator = (const lexical_feedback&); | |
146 }; | |
147 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
148 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
149 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
|
150 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
151 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
152 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
|
153 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
|
154 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
155 protected: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
156 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
|
157 ~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
|
158 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
159 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
160 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
161 // 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
|
162 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
|
163 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
|
164 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
165 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
166 extern std::string |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
167 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
|
168 |
3883 | 169 // TRUE means that we have encountered EOF on the input stream. |
170 extern bool parser_end_of_input; | |
171 | |
1826 | 172 // Flags that need to be shared between the lexer and parser. |
173 extern lexical_feedback lexer_flags; | |
440 | 174 |
1 | 175 #endif |
176 | |
177 /* | |
178 ;;; Local Variables: *** | |
179 ;;; mode: C++ *** | |
180 ;;; End: *** | |
181 */ |