Mercurial > hg > octave-lyh
annotate src/lex.h @ 8746:5dd06f19e9be
handle commands in the lexer
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 15 Feb 2009 23:49:15 -0500 |
parents | 6dc61981d18b |
children | 8ed42c679af5 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, |
4 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
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. | |
35 extern YY_BUFFER_STATE create_buffer (FILE *f); | |
36 | |
37 // Report the current buffer. | |
38 extern YY_BUFFER_STATE current_buffer (void); | |
39 | |
40 // Connect to new buffer buffer. | |
41 extern void switch_to_buffer (YY_BUFFER_STATE buf); | |
42 | |
43 // Delete a buffer. | |
44 extern void delete_buffer (YY_BUFFER_STATE buf); | |
45 | |
46 // Restore a buffer (for unwind-prot). | |
47 extern void restore_input_buffer (void *buf); | |
48 | |
49 // Delete a buffer (for unwind-prot). | |
50 extern void delete_input_buffer (void *buf); | |
51 | |
4867 | 52 // Is the given string a keyword? |
53 extern bool is_keyword (const std::string& s); | |
54 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
55 extern void prep_lexer_for_script (void); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7634
diff
changeset
|
56 |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
57 extern void force_local_variable (const std::string& name); |
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
58 |
1826 | 59 // For communication between the lexer and parser. |
60 | |
3585 | 61 class |
62 lexical_feedback | |
1826 | 63 { |
64 public: | |
65 | |
66 lexical_feedback (void) { init (); } | |
67 | |
68 ~lexical_feedback (void) { } | |
69 | |
70 void init (void); | |
71 | |
3351 | 72 // Square bracket level count. |
73 int bracketflag; | |
1826 | 74 |
4613 | 75 // Curly brace level count. |
76 int braceflag; | |
77 | |
2877 | 78 // TRUE means we're in the middle of defining a loop. |
1826 | 79 int looping; |
80 | |
2877 | 81 // TRUE means that we should convert spaces to a comma inside a |
2857 | 82 // matrix definition. |
83 bool convert_spaces_to_comma; | |
84 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
85 // 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
|
86 // command name is possible. |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
87 bool at_beginning_of_statement; |
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8745
diff
changeset
|
88 |
2877 | 89 // TRUE means we're in the middle of defining a function. |
2857 | 90 bool defining_func; |
91 | |
4930 | 92 // Nonzero means we are parsing a function handle. |
93 int looking_at_function_handle; | |
94 | |
2877 | 95 // TRUE means we're parsing the return list for a function. |
2857 | 96 bool looking_at_return_list; |
97 | |
2877 | 98 // TRUE means we're parsing the parameter list for a function. |
2857 | 99 bool looking_at_parameter_list; |
100 | |
8701
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
101 // 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
|
102 // persistent). |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
103 bool looking_at_decl_list; |
1652e39b934e
handle command names in declaration lists
John W. Eaton <jwe@octave.org>
parents:
8001
diff
changeset
|
104 |
7634
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
105 // 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
|
106 // parameter list element. |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
107 bool looking_at_initializer_expression; |
ae90e05ad299
fix parameter list initializer bug
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
108 |
3189 | 109 // TRUE means we're parsing a matrix or the left hand side of |
110 // multi-value assignment statement. | |
111 bool looking_at_matrix_or_assign_lhs; | |
112 | |
8745
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
113 // 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
|
114 // 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
|
115 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
|
116 |
6dc61981d18b
better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents:
8701
diff
changeset
|
117 // 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
|
118 bool looking_for_object_index; |
4234 | 119 |
2857 | 120 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
121 bool do_comma_insert; | |
122 | |
2877 | 123 // TRUE means we're looking at an indirect reference to a |
2857 | 124 // structure element. |
125 bool looking_at_indirect_ref; | |
126 | |
2877 | 127 // TRUE means that we've already seen the name of this function. |
128 // Should only matter if defining_func is also TRUE. | |
129 bool parsed_function_name; | |
130 | |
4240 | 131 // Are we parsing a nested function? |
132 // 1 ==> Yes. | |
133 // 0 ==> No. | |
134 // -1 ==> Yes, but it is the last one because we have seen EOF. | |
135 int parsing_nested_function; | |
4238 | 136 |
7336 | 137 // TRUE means we are parsing a class method. |
138 bool parsing_class_method; | |
139 | |
1826 | 140 // Return transpose or start a string? |
2857 | 141 bool quote_is_transpose; |
1826 | 142 |
8001
ff9e7873f8ea
improve handling of command-style names in matrix_or_assign_lhs context
John W. Eaton <jwe@octave.org>
parents:
7723
diff
changeset
|
143 // 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
|
144 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
|
145 |
1826 | 146 private: |
147 | |
148 lexical_feedback (const lexical_feedback&); | |
149 | |
150 lexical_feedback& operator = (const lexical_feedback&); | |
151 }; | |
152 | |
7720
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
153 class |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
154 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
|
155 { |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
156 public: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
157 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
|
158 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
|
159 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
160 protected: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
161 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
|
162 ~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
|
163 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
164 private: |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
165 |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
166 // 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
|
167 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
|
168 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
|
169 }; |
4e2eafef689c
unify comment and help text processing in lex.l and parse.y
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
170 |
7723
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
171 extern std::string |
74f5e0c7de9e
first pass at handling block comments
John W. Eaton <jwe@octave.org>
parents:
7720
diff
changeset
|
172 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
|
173 |
3883 | 174 // TRUE means that we have encountered EOF on the input stream. |
175 extern bool parser_end_of_input; | |
176 | |
1826 | 177 // Flags that need to be shared between the lexer and parser. |
178 extern lexical_feedback lexer_flags; | |
440 | 179 |
1 | 180 #endif |
181 | |
182 /* | |
183 ;;; Local Variables: *** | |
184 ;;; mode: C++ *** | |
185 ;;; End: *** | |
186 */ |