Octave-Forge - Extra packages for GNU Octave | |
Home · Packages · Developers · Documentation · FAQ · Bugs · Mailing Lists · Links · Code |
00001 /* 00002 00003 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 00004 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton 00005 00006 This file is part of Octave. 00007 00008 Octave is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU General Public License as published by the 00010 Free Software Foundation; either version 3 of the License, or (at your 00011 option) any later version. 00012 00013 Octave is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00016 for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Octave; see the file COPYING. If not, see 00020 <http://www.gnu.org/licenses/>. 00021 00022 */ 00023 00024 #if !defined (octave_lex_h) 00025 #define octave_lex_h 1 00026 00027 #include <list> 00028 00029 // FIXME -- these input buffer things should be members of a 00030 // parser input stream class. 00031 00032 typedef struct yy_buffer_state *YY_BUFFER_STATE; 00033 00034 // Associate a buffer with a new file to read. 00035 extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); 00036 00037 // Report the current buffer. 00038 extern OCTINTERP_API YY_BUFFER_STATE current_buffer (void); 00039 00040 // Connect to new buffer buffer. 00041 extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); 00042 00043 // Delete a buffer. 00044 extern OCTINTERP_API void delete_buffer (YY_BUFFER_STATE buf); 00045 00046 // Is the given string a keyword? 00047 extern bool is_keyword (const std::string& s); 00048 00049 extern void prep_lexer_for_script_file (void); 00050 extern void prep_lexer_for_function_file (void); 00051 00052 // For communication between the lexer and parser. 00053 00054 class 00055 lexical_feedback 00056 { 00057 public: 00058 00059 lexical_feedback (void) { init (); } 00060 00061 ~lexical_feedback (void) { } 00062 00063 void init (void); 00064 00065 // Square bracket level count. 00066 int bracketflag; 00067 00068 // Curly brace level count. 00069 int braceflag; 00070 00071 // TRUE means we're in the middle of defining a loop. 00072 int looping; 00073 00074 // TRUE means that we should convert spaces to a comma inside a 00075 // matrix definition. 00076 bool convert_spaces_to_comma; 00077 00078 // TRUE means we are at the beginning of a statement, where a 00079 // command name is possible. 00080 bool at_beginning_of_statement; 00081 00082 // TRUE means we're in the middle of defining a function. 00083 bool defining_func; 00084 00085 // Nonzero means we are parsing a function handle. 00086 int looking_at_function_handle; 00087 00088 // TRUE means we're parsing the return list for a function. 00089 bool looking_at_return_list; 00090 00091 // TRUE means we're parsing the parameter list for a function. 00092 bool looking_at_parameter_list; 00093 00094 // TRUE means we're parsing a declaration list (global or 00095 // persistent). 00096 bool looking_at_decl_list; 00097 00098 // TRUE means we are looking at the initializer expression for a 00099 // parameter list element. 00100 bool looking_at_initializer_expression; 00101 00102 // TRUE means we're parsing a matrix or the left hand side of 00103 // multi-value assignment statement. 00104 bool looking_at_matrix_or_assign_lhs; 00105 00106 // If the front of the list is TRUE, the closest paren, brace, or 00107 // bracket nesting is an index for an object. 00108 std::list<bool> looking_at_object_index; 00109 00110 // Object index not possible until we've seen something. 00111 bool looking_for_object_index; 00112 00113 // GAG. Stupid kludge so that [[1,2][3,4]] will work. 00114 bool do_comma_insert; 00115 00116 // TRUE means we're looking at an indirect reference to a 00117 // structure element. 00118 bool looking_at_indirect_ref; 00119 00120 // TRUE means that we've already seen the name of this function. 00121 // Should only matter if current_function_level > 0 00122 bool parsed_function_name; 00123 00124 // TRUE means we are parsing a class method in function or classdef file. 00125 bool parsing_class_method; 00126 00127 // TRUE means we are parsing a class method declaration line in a 00128 // classdef file and can accept a property get or set method name. 00129 // For example, "get.PropertyName" is recognized as a function name. 00130 bool maybe_classdef_get_set_method; 00131 00132 // TRUE means we are parsing a classdef file 00133 bool parsing_classdef; 00134 00135 // Return transpose or start a string? 00136 bool quote_is_transpose; 00137 00138 // Set of identifiers that might be local variable names. 00139 std::set<std::string> pending_local_variables; 00140 00141 private: 00142 00143 lexical_feedback (const lexical_feedback&); 00144 00145 lexical_feedback& operator = (const lexical_feedback&); 00146 }; 00147 00148 class 00149 stream_reader 00150 { 00151 public: 00152 virtual int getc (void) = 0; 00153 virtual int ungetc (int c) = 0; 00154 00155 protected: 00156 stream_reader (void) { } 00157 ~stream_reader (void) { } 00158 00159 private: 00160 00161 // No copying! 00162 stream_reader (const stream_reader&); 00163 stream_reader& operator = (const stream_reader&); 00164 }; 00165 00166 extern std::string 00167 grab_comment_block (stream_reader& reader, bool at_bol, bool& eof); 00168 00169 // TRUE means that we have encountered EOF on the input stream. 00170 extern bool parser_end_of_input; 00171 00172 // Flags that need to be shared between the lexer and parser. 00173 extern lexical_feedback lexer_flags; 00174 00175 #endif 00176 00177 /* 00178 ;;; Local Variables: *** 00179 ;;; mode: C++ *** 00180 ;;; End: *** 00181 */