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 |
4753
|
26 // XXX FIXME XXX -- these input buffer things should be members of a |
1826
|
27 // parser input stream class. |
|
28 |
1
|
29 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
|
30 |
|
31 // Associate a buffer with a new file to read. |
|
32 extern YY_BUFFER_STATE create_buffer (FILE *f); |
|
33 |
|
34 // Report the current buffer. |
|
35 extern YY_BUFFER_STATE current_buffer (void); |
|
36 |
|
37 // Connect to new buffer buffer. |
|
38 extern void switch_to_buffer (YY_BUFFER_STATE buf); |
|
39 |
|
40 // Delete a buffer. |
|
41 extern void delete_buffer (YY_BUFFER_STATE buf); |
|
42 |
|
43 // Restore a buffer (for unwind-prot). |
|
44 extern void restore_input_buffer (void *buf); |
|
45 |
|
46 // Delete a buffer (for unwind-prot). |
|
47 extern void delete_input_buffer (void *buf); |
|
48 |
4867
|
49 // Is the given string a keyword? |
|
50 extern bool is_keyword (const std::string& s); |
|
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 we think we are looking at the beginning of a |
2857
|
75 // function definition. |
|
76 bool beginning_of_function; |
|
77 |
|
78 // Another context hack, this time for the plot command's `using', |
|
79 // `title', and `with' keywords. |
|
80 bool cant_be_identifier; |
|
81 |
2877
|
82 // TRUE means that we should convert spaces to a comma inside a |
2857
|
83 // matrix definition. |
|
84 bool convert_spaces_to_comma; |
|
85 |
2877
|
86 // TRUE means we're in the middle of defining a function. |
2857
|
87 bool defining_func; |
|
88 |
2877
|
89 // TRUE means we're parsing the return list for a function. |
2857
|
90 bool looking_at_return_list; |
|
91 |
2877
|
92 // TRUE means we're parsing the parameter list for a function. |
2857
|
93 bool looking_at_parameter_list; |
|
94 |
3189
|
95 // TRUE means we're parsing a matrix or the left hand side of |
|
96 // multi-value assignment statement. |
|
97 bool looking_at_matrix_or_assign_lhs; |
|
98 |
4237
|
99 // Nonzero means we're parsing an indexing operation for an object. |
|
100 int looking_at_object_index; |
4234
|
101 |
2857
|
102 // GAG. Stupid kludge so that [[1,2][3,4]] will work. |
|
103 bool do_comma_insert; |
|
104 |
2877
|
105 // TRUE means we think we are looking at a set command. |
2857
|
106 bool doing_set; |
|
107 |
2877
|
108 // TRUE means we're looking at the range part of a plot command. |
2857
|
109 bool in_plot_range; |
|
110 |
2877
|
111 // TRUE means we're looking at the using part of a plot command. |
2857
|
112 bool in_plot_using; |
|
113 |
2877
|
114 // TRUE means we're looking at the style part of a plot command. |
2857
|
115 bool in_plot_style; |
|
116 |
3165
|
117 // TRUE means we're looking at the axes part of a plot command. |
|
118 bool in_plot_axes; |
|
119 |
2877
|
120 // TRUE means we're looking at an indirect reference to a |
2857
|
121 // structure element. |
|
122 bool looking_at_indirect_ref; |
|
123 |
2877
|
124 // TRUE means that we've already seen the name of this function. |
|
125 // Should only matter if defining_func is also TRUE. |
|
126 bool parsed_function_name; |
|
127 |
4240
|
128 // Are we parsing a nested function? |
|
129 // 1 ==> Yes. |
|
130 // 0 ==> No. |
|
131 // -1 ==> Yes, but it is the last one because we have seen EOF. |
|
132 int parsing_nested_function; |
4238
|
133 |
2877
|
134 // TRUE means we've seen something that means we must be past the |
1826
|
135 // range part of a plot command. |
2857
|
136 bool past_plot_range; |
1826
|
137 |
2877
|
138 // TRUE means we're working on a plot command. |
2857
|
139 bool plotting; |
1826
|
140 |
|
141 // Return transpose or start a string? |
2857
|
142 bool quote_is_transpose; |
1826
|
143 |
|
144 private: |
|
145 |
|
146 lexical_feedback (const lexical_feedback&); |
|
147 |
|
148 lexical_feedback& operator = (const lexical_feedback&); |
|
149 }; |
|
150 |
3883
|
151 // TRUE means that we have encountered EOF on the input stream. |
|
152 extern bool parser_end_of_input; |
|
153 |
1826
|
154 // Flags that need to be shared between the lexer and parser. |
|
155 extern lexical_feedback lexer_flags; |
440
|
156 |
1
|
157 #endif |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; End: *** |
|
163 */ |