1
|
1 // lex.h -*- C++ -*- |
|
2 /* |
|
3 |
1884
|
4 Copyright (C) 1996 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_lex_h) |
|
25 #define octave_lex_h 1 |
1
|
26 |
143
|
27 // Arrange to get input via readline. |
|
28 |
|
29 #ifdef YY_INPUT |
|
30 #undef YY_INPUT |
247
|
31 #endif |
143
|
32 #define YY_INPUT(buf,result,max_size) \ |
|
33 if ((result = octave_read (buf, max_size)) < 0) \ |
|
34 YY_FATAL_ERROR ("octave_read () in flex scanner failed"); |
|
35 |
|
36 // Try to avoid crashing out completely on fatal scanner errors. |
|
37 |
|
38 #ifdef YY_FATAL_ERROR |
|
39 #undef YY_FATAL_ERROR |
247
|
40 #endif |
143
|
41 #define YY_FATAL_ERROR(msg) \ |
|
42 do \ |
|
43 { \ |
|
44 error (msg); \ |
|
45 jump_to_top_level (); \ |
|
46 } \ |
|
47 while (0) |
|
48 |
|
49 #define TOK_RETURN(tok) \ |
|
50 do \ |
|
51 { \ |
|
52 current_input_column += yyleng; \ |
1826
|
53 lexer_flags.quote_is_transpose = 0; \ |
|
54 lexer_flags.cant_be_identifier = 0; \ |
|
55 lexer_flags.convert_spaces_to_comma = 1; \ |
143
|
56 return (tok); \ |
|
57 } \ |
|
58 while (0) |
|
59 |
1060
|
60 #define TOK_PUSH_AND_RETURN(name,tok) \ |
|
61 do \ |
|
62 { \ |
1061
|
63 yylval.tok_val = new token (name, input_line_number, \ |
|
64 current_input_column); \ |
1060
|
65 token_stack.push (yylval.tok_val); \ |
|
66 TOK_RETURN (tok); \ |
|
67 } \ |
|
68 while (0) |
|
69 |
143
|
70 #define BIN_OP_RETURN(tok,convert) \ |
|
71 do \ |
|
72 { \ |
|
73 yylval.tok_val = new token (input_line_number, current_input_column); \ |
|
74 token_stack.push (yylval.tok_val); \ |
|
75 current_input_column += yyleng; \ |
1826
|
76 lexer_flags.quote_is_transpose = 0; \ |
|
77 lexer_flags.cant_be_identifier = 0; \ |
|
78 lexer_flags.convert_spaces_to_comma = convert; \ |
143
|
79 return (tok); \ |
|
80 } \ |
|
81 while (0) |
|
82 |
1826
|
83 // XXX FIXME XXX -- these input buffer things should be members of an |
|
84 // parser input stream class. |
|
85 |
1
|
86 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
|
87 |
|
88 // Associate a buffer with a new file to read. |
|
89 extern YY_BUFFER_STATE create_buffer (FILE *f); |
|
90 |
|
91 // Report the current buffer. |
|
92 extern YY_BUFFER_STATE current_buffer (void); |
|
93 |
|
94 // Connect to new buffer buffer. |
|
95 extern void switch_to_buffer (YY_BUFFER_STATE buf); |
|
96 |
|
97 // Delete a buffer. |
|
98 extern void delete_buffer (YY_BUFFER_STATE buf); |
|
99 |
|
100 // Restore a buffer (for unwind-prot). |
|
101 extern void restore_input_buffer (void *buf); |
|
102 |
|
103 // Delete a buffer (for unwind-prot). |
|
104 extern void delete_input_buffer (void *buf); |
|
105 |
|
106 // See if a function file has extra garbage after the end statement. |
1826
|
107 // This needs to be defined in lex.l so that it can use yyinput() but |
|
108 // it must be called from parse.y. |
1
|
109 extern void check_for_garbage_after_fcn_def (void); |
|
110 |
1826
|
111 // For communication between the lexer and parser. |
|
112 |
|
113 class lexical_feedback |
|
114 { |
|
115 public: |
|
116 |
|
117 lexical_feedback (void) { init (); } |
|
118 |
|
119 ~lexical_feedback (void) { } |
|
120 |
|
121 void init (void); |
|
122 |
1829
|
123 // Nonzero means we think we are looking at the beginning of a |
1826
|
124 // function definition. |
|
125 int beginning_of_function; |
|
126 |
|
127 // Brace level count. |
|
128 int braceflag; |
|
129 |
|
130 // Another context hack, this time for the plot command's `using', |
|
131 // `title', and `with' keywords. |
|
132 int cant_be_identifier; |
|
133 |
|
134 // Nonzero means that we should convert spaces to a comma inside a |
|
135 // matrix definition. |
|
136 int convert_spaces_to_comma; |
|
137 |
|
138 // Nonzero means we're in the middle of defining a function. |
|
139 int defining_func; |
|
140 |
|
141 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
|
142 int do_comma_insert; |
|
143 |
|
144 // Nonzero means we think we are looking at a set command. |
|
145 int doing_set; |
|
146 |
|
147 // Nonzero means we're in the middle of defining a conditional |
|
148 // expression. |
|
149 int iffing; |
240
|
150 |
1826
|
151 // Nonzero means we're looking at the range part of a plot command. |
|
152 int in_plot_range; |
|
153 |
|
154 // Nonzero means we're looking at the using part of a plot command. |
|
155 int in_plot_using; |
|
156 |
|
157 // Nonzero means we're looking at the style part of a plot command. |
|
158 int in_plot_style; |
|
159 |
|
160 // Nonzero means we're looking at an indirect reference to a |
|
161 // structure element. |
|
162 int looking_at_indirect_ref; |
|
163 |
|
164 // Nonzero means we're in the middle of defining a loop. |
|
165 int looping; |
|
166 |
|
167 // Nonzero means we need to do some extra lookahead to avoid being |
|
168 // screwed by bogus function syntax. |
|
169 int maybe_screwed; |
|
170 |
|
171 // Nonzero means we need to do some extra lookahead to avoid being |
|
172 // screwed by bogus function syntax. |
|
173 int maybe_screwed_again; |
|
174 |
|
175 // Nonzero means we've seen something that means we must be past the |
|
176 // range part of a plot command. |
|
177 int past_plot_range; |
|
178 |
|
179 // Nonzero means we're working on a plot command. |
|
180 int plotting; |
|
181 |
|
182 // Return transpose or start a string? |
|
183 int quote_is_transpose; |
|
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 ;;; page-delimiter: "^/\\*" *** |
|
201 ;;; End: *** |
|
202 */ |