1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
383
|
23 #if !defined (octave_lex_h) |
|
24 #define octave_lex_h 1 |
1
|
25 |
143
|
26 // Arrange to get input via readline. |
|
27 |
|
28 #ifdef YY_INPUT |
|
29 #undef YY_INPUT |
247
|
30 #endif |
2857
|
31 #define YY_INPUT(buf, result, max_size) \ |
143
|
32 if ((result = octave_read (buf, max_size)) < 0) \ |
|
33 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); |
|
34 |
|
35 // Try to avoid crashing out completely on fatal scanner errors. |
3225
|
36 // The call to yy_fatal_error should never happen, but it avoids a |
|
37 // `static function defined but not used' warning from gcc. |
143
|
38 |
|
39 #ifdef YY_FATAL_ERROR |
|
40 #undef YY_FATAL_ERROR |
247
|
41 #endif |
143
|
42 #define YY_FATAL_ERROR(msg) \ |
|
43 do \ |
|
44 { \ |
|
45 error (msg); \ |
4182
|
46 OCTAVE_QUIT; \ |
3225
|
47 yy_fatal_error (msg); \ |
143
|
48 } \ |
|
49 while (0) |
|
50 |
|
51 #define TOK_RETURN(tok) \ |
|
52 do \ |
|
53 { \ |
|
54 current_input_column += yyleng; \ |
2857
|
55 lexer_flags.quote_is_transpose = false; \ |
|
56 lexer_flags.cant_be_identifier = false; \ |
|
57 lexer_flags.convert_spaces_to_comma = true; \ |
143
|
58 return (tok); \ |
|
59 } \ |
|
60 while (0) |
|
61 |
2857
|
62 #define TOK_PUSH_AND_RETURN(name, tok) \ |
1060
|
63 do \ |
|
64 { \ |
1061
|
65 yylval.tok_val = new token (name, input_line_number, \ |
|
66 current_input_column); \ |
1060
|
67 token_stack.push (yylval.tok_val); \ |
|
68 TOK_RETURN (tok); \ |
|
69 } \ |
|
70 while (0) |
|
71 |
2857
|
72 #define BIN_OP_RETURN(tok, convert) \ |
143
|
73 do \ |
|
74 { \ |
|
75 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
76 token_stack.push (yylval.tok_val); \ |
|
77 current_input_column += yyleng; \ |
2857
|
78 lexer_flags.quote_is_transpose = false; \ |
|
79 lexer_flags.cant_be_identifier = true; \ |
1826
|
80 lexer_flags.convert_spaces_to_comma = convert; \ |
143
|
81 return (tok); \ |
|
82 } \ |
|
83 while (0) |
|
84 |
4037
|
85 #define XBIN_OP_RETURN(tok, convert) \ |
|
86 do \ |
|
87 { \ |
|
88 gripe_matlab_incompatible_operator (yytext); \ |
|
89 BIN_OP_RETURN (tok, convert); \ |
|
90 } \ |
|
91 while (0) |
|
92 |
1826
|
93 // XXX FIXME XXX -- these input buffer things should be members of an |
|
94 // parser input stream class. |
|
95 |
1
|
96 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
|
97 |
|
98 // Associate a buffer with a new file to read. |
|
99 extern YY_BUFFER_STATE create_buffer (FILE *f); |
|
100 |
|
101 // Report the current buffer. |
|
102 extern YY_BUFFER_STATE current_buffer (void); |
|
103 |
|
104 // Connect to new buffer buffer. |
|
105 extern void switch_to_buffer (YY_BUFFER_STATE buf); |
|
106 |
|
107 // Delete a buffer. |
|
108 extern void delete_buffer (YY_BUFFER_STATE buf); |
|
109 |
|
110 // Restore a buffer (for unwind-prot). |
|
111 extern void restore_input_buffer (void *buf); |
|
112 |
|
113 // Delete a buffer (for unwind-prot). |
|
114 extern void delete_input_buffer (void *buf); |
|
115 |
1826
|
116 // For communication between the lexer and parser. |
|
117 |
3585
|
118 class |
|
119 lexical_feedback |
1826
|
120 { |
|
121 public: |
|
122 |
|
123 lexical_feedback (void) { init (); } |
|
124 |
|
125 ~lexical_feedback (void) { } |
|
126 |
|
127 void init (void); |
|
128 |
3351
|
129 // Square bracket level count. |
|
130 int bracketflag; |
1826
|
131 |
2877
|
132 // TRUE means we're in the middle of defining a loop. |
1826
|
133 int looping; |
|
134 |
2877
|
135 // TRUE means we think we are looking at the beginning of a |
2857
|
136 // function definition. |
|
137 bool beginning_of_function; |
|
138 |
|
139 // Another context hack, this time for the plot command's `using', |
|
140 // `title', and `with' keywords. |
|
141 bool cant_be_identifier; |
|
142 |
2877
|
143 // TRUE means that we should convert spaces to a comma inside a |
2857
|
144 // matrix definition. |
|
145 bool convert_spaces_to_comma; |
|
146 |
2877
|
147 // TRUE means we're in the middle of defining a function. |
2857
|
148 bool defining_func; |
|
149 |
2877
|
150 // TRUE means we're parsing the return list for a function. |
2857
|
151 bool looking_at_return_list; |
|
152 |
2877
|
153 // TRUE means we're parsing the parameter list for a function. |
2857
|
154 bool looking_at_parameter_list; |
|
155 |
3189
|
156 // TRUE means we're parsing a matrix or the left hand side of |
|
157 // multi-value assignment statement. |
|
158 bool looking_at_matrix_or_assign_lhs; |
|
159 |
4237
|
160 // Nonzero means we're parsing an indexing operation for an object. |
|
161 int looking_at_object_index; |
4234
|
162 |
2857
|
163 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
|
164 bool do_comma_insert; |
|
165 |
2877
|
166 // TRUE means we think we are looking at a set command. |
2857
|
167 bool doing_set; |
|
168 |
2877
|
169 // TRUE means we're looking at the range part of a plot command. |
2857
|
170 bool in_plot_range; |
|
171 |
2877
|
172 // TRUE means we're looking at the using part of a plot command. |
2857
|
173 bool in_plot_using; |
|
174 |
2877
|
175 // TRUE means we're looking at the style part of a plot command. |
2857
|
176 bool in_plot_style; |
|
177 |
3165
|
178 // TRUE means we're looking at the axes part of a plot command. |
|
179 bool in_plot_axes; |
|
180 |
2877
|
181 // TRUE means we're looking at an indirect reference to a |
2857
|
182 // structure element. |
|
183 bool looking_at_indirect_ref; |
|
184 |
2877
|
185 // TRUE means that we've already seen the name of this function. |
|
186 // Should only matter if defining_func is also TRUE. |
|
187 bool parsed_function_name; |
|
188 |
4238
|
189 // TRUE means that we're parsing a nested function definition. |
|
190 bool parsing_nested_function; |
|
191 |
2877
|
192 // TRUE means we've seen something that means we must be past the |
1826
|
193 // range part of a plot command. |
2857
|
194 bool past_plot_range; |
1826
|
195 |
2877
|
196 // TRUE means we're working on a plot command. |
2857
|
197 bool plotting; |
1826
|
198 |
|
199 // Return transpose or start a string? |
2857
|
200 bool quote_is_transpose; |
1826
|
201 |
|
202 private: |
|
203 |
|
204 lexical_feedback (const lexical_feedback&); |
|
205 |
|
206 lexical_feedback& operator = (const lexical_feedback&); |
|
207 }; |
|
208 |
3883
|
209 // TRUE means that we have encountered EOF on the input stream. |
|
210 extern bool parser_end_of_input; |
|
211 |
1826
|
212 // Flags that need to be shared between the lexer and parser. |
|
213 extern lexical_feedback lexer_flags; |
440
|
214 |
1
|
215 #endif |
|
216 |
|
217 /* |
|
218 ;;; Local Variables: *** |
|
219 ;;; mode: C++ *** |
|
220 ;;; End: *** |
|
221 */ |