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. |
|
36 |
|
37 #ifdef YY_FATAL_ERROR |
|
38 #undef YY_FATAL_ERROR |
247
|
39 #endif |
143
|
40 #define YY_FATAL_ERROR(msg) \ |
|
41 do \ |
|
42 { \ |
|
43 error (msg); \ |
|
44 jump_to_top_level (); \ |
|
45 } \ |
|
46 while (0) |
|
47 |
|
48 #define TOK_RETURN(tok) \ |
|
49 do \ |
|
50 { \ |
|
51 current_input_column += yyleng; \ |
2857
|
52 lexer_flags.quote_is_transpose = false; \ |
|
53 lexer_flags.cant_be_identifier = false; \ |
|
54 lexer_flags.convert_spaces_to_comma = true; \ |
143
|
55 return (tok); \ |
|
56 } \ |
|
57 while (0) |
|
58 |
2857
|
59 #define TOK_PUSH_AND_RETURN(name, tok) \ |
1060
|
60 do \ |
|
61 { \ |
1061
|
62 yylval.tok_val = new token (name, input_line_number, \ |
|
63 current_input_column); \ |
1060
|
64 token_stack.push (yylval.tok_val); \ |
|
65 TOK_RETURN (tok); \ |
|
66 } \ |
|
67 while (0) |
|
68 |
2857
|
69 #define BIN_OP_RETURN(tok, convert) \ |
143
|
70 do \ |
|
71 { \ |
|
72 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
73 token_stack.push (yylval.tok_val); \ |
|
74 current_input_column += yyleng; \ |
2857
|
75 lexer_flags.quote_is_transpose = false; \ |
|
76 lexer_flags.cant_be_identifier = true; \ |
1826
|
77 lexer_flags.convert_spaces_to_comma = convert; \ |
143
|
78 return (tok); \ |
|
79 } \ |
|
80 while (0) |
|
81 |
1826
|
82 // XXX FIXME XXX -- these input buffer things should be members of an |
|
83 // parser input stream class. |
|
84 |
1
|
85 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
|
86 |
|
87 // Associate a buffer with a new file to read. |
|
88 extern YY_BUFFER_STATE create_buffer (FILE *f); |
|
89 |
|
90 // Report the current buffer. |
|
91 extern YY_BUFFER_STATE current_buffer (void); |
|
92 |
|
93 // Connect to new buffer buffer. |
|
94 extern void switch_to_buffer (YY_BUFFER_STATE buf); |
|
95 |
|
96 // Delete a buffer. |
|
97 extern void delete_buffer (YY_BUFFER_STATE buf); |
|
98 |
|
99 // Restore a buffer (for unwind-prot). |
|
100 extern void restore_input_buffer (void *buf); |
|
101 |
|
102 // Delete a buffer (for unwind-prot). |
|
103 extern void delete_input_buffer (void *buf); |
|
104 |
|
105 // See if a function file has extra garbage after the end statement. |
1826
|
106 // This needs to be defined in lex.l so that it can use yyinput() but |
|
107 // it must be called from parse.y. |
1
|
108 extern void check_for_garbage_after_fcn_def (void); |
|
109 |
1826
|
110 // For communication between the lexer and parser. |
|
111 |
|
112 class lexical_feedback |
|
113 { |
|
114 public: |
|
115 |
|
116 lexical_feedback (void) { init (); } |
|
117 |
|
118 ~lexical_feedback (void) { } |
|
119 |
|
120 void init (void); |
|
121 |
|
122 // Brace level count. |
|
123 int braceflag; |
|
124 |
2877
|
125 // TRUE means we're in the middle of defining a loop. |
1826
|
126 int looping; |
|
127 |
2877
|
128 // TRUE means we think we are looking at the beginning of a |
2857
|
129 // function definition. |
|
130 bool beginning_of_function; |
|
131 |
|
132 // Another context hack, this time for the plot command's `using', |
|
133 // `title', and `with' keywords. |
|
134 bool cant_be_identifier; |
|
135 |
2877
|
136 // TRUE means that we should convert spaces to a comma inside a |
2857
|
137 // matrix definition. |
|
138 bool convert_spaces_to_comma; |
|
139 |
2877
|
140 // TRUE means we're in the middle of defining a function. |
2857
|
141 bool defining_func; |
|
142 |
2877
|
143 // TRUE means we're parsing the return list for a function. |
2857
|
144 bool looking_at_return_list; |
|
145 |
2877
|
146 // TRUE means we're parsing the parameter list for a function. |
2857
|
147 bool looking_at_parameter_list; |
|
148 |
|
149 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
|
150 bool do_comma_insert; |
|
151 |
2877
|
152 // TRUE means we think we are looking at a set command. |
2857
|
153 bool doing_set; |
|
154 |
2877
|
155 // TRUE means we're looking at the range part of a plot command. |
2857
|
156 bool in_plot_range; |
|
157 |
2877
|
158 // TRUE means we're looking at the using part of a plot command. |
2857
|
159 bool in_plot_using; |
|
160 |
2877
|
161 // TRUE means we're looking at the style part of a plot command. |
2857
|
162 bool in_plot_style; |
|
163 |
3165
|
164 // TRUE means we're looking at the axes part of a plot command. |
|
165 bool in_plot_axes; |
|
166 |
2877
|
167 // TRUE means we're looking at an indirect reference to a |
2857
|
168 // structure element. |
|
169 bool looking_at_indirect_ref; |
|
170 |
2877
|
171 // TRUE means that we've already seen the name of this function. |
|
172 // Should only matter if defining_func is also TRUE. |
|
173 bool parsed_function_name; |
|
174 |
|
175 // TRUE means we've seen something that means we must be past the |
1826
|
176 // range part of a plot command. |
2857
|
177 bool past_plot_range; |
1826
|
178 |
2877
|
179 // TRUE means we're working on a plot command. |
2857
|
180 bool plotting; |
1826
|
181 |
|
182 // Return transpose or start a string? |
2857
|
183 bool quote_is_transpose; |
1826
|
184 |
|
185 private: |
|
186 |
|
187 lexical_feedback (const lexical_feedback&); |
|
188 |
|
189 lexical_feedback& operator = (const lexical_feedback&); |
|
190 }; |
|
191 |
|
192 // Flags that need to be shared between the lexer and parser. |
|
193 extern lexical_feedback lexer_flags; |
440
|
194 |
1
|
195 #endif |
|
196 |
|
197 /* |
|
198 ;;; Local Variables: *** |
|
199 ;;; mode: C++ *** |
|
200 ;;; End: *** |
|
201 */ |