00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file ETCL_Interpreter.h 00006 * 00007 * $Id: ETCL_Interpreter.h 82434 2008-07-28 11:40:36Z johnnyw $ 00008 * 00009 * @author Jeff Parsons <parsons@cs.wustl.edu> based on previous work by 00010 * @author Seth Widoff <sbw1@cs.wustl.edu> 00011 */ 00012 //============================================================================= 00013 00014 00015 #ifndef ETCL_INTERPRETER_H 00016 #define ETCL_INTERPRETER_H 00017 00018 #include /**/ "ace/pre.h" 00019 00020 #include "ace/Thread_Mutex.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 #include "ace/Synch_Traits.h" 00027 00028 #include "etcl_parser_export.h" 00029 00030 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00031 00032 class ETCL_Constraint; 00033 00034 ACE_END_VERSIONED_NAMESPACE_DECL 00035 00036 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00037 00038 /** 00039 * @class ETCL_Interpreter 00040 * 00041 * @brief ETCL_Interpreter is the superclass for all ETCL interpreters. 00042 * Its build tree method invokes the yacc parser to parse a constraint 00043 * or preference string. 00044 */ 00045 class ETCL_Parser_Export ETCL_Interpreter 00046 { 00047 protected: 00048 // = Initialization and termination methods. 00049 /// Constructor. 00050 ETCL_Interpreter (void); 00051 00052 /// Destructor. 00053 virtual ~ETCL_Interpreter (void); 00054 00055 /// Using the Yacc generated parser, construct an expression tree 00056 /// representing @a constraints from the tokens returned by it. 00057 int build_tree (const char* constraints); 00058 00059 static int is_empty_string (const char* str); 00060 00061 /// The root of the expression tree, not equal to null if build_tree 00062 /// successfully builds a tree from the constraints. 00063 ETCL_Constraint* root_; 00064 private: 00065 /// This mutex protects the <build_tree> method from reentrance. 00066 static ACE_SYNCH_MUTEX parserMutex__; 00067 }; 00068 00069 00070 // Functions we need for parsing. 00071 extern int yyparse (void); 00072 extern void yyrestart (FILE*); 00073 extern int yylex (void); 00074 00075 // Have yylex read from the constraint string, not from stdin. 00076 #undef YY_INPUT 00077 #define YY_INPUT(b, r, ms) (r = Lex_String_Input::copy_into(b, ms)) 00078 00079 /** 00080 * @class Lex_String_Input 00081 * 00082 * @brief Have Lex read from a string and not from stdin. Essentially, 00083 * the interpreter needs to call yylex() until EOF, and call 00084 * TAO_Lex_String_Input::reset() with the new string, prior to 00085 * calling yyparse. 00086 */ 00087 class Lex_String_Input 00088 { 00089 public: 00090 /// Reset the lex input. 00091 static void reset (char* input_string); 00092 00093 /// Method lex will call to read from the input string. 00094 static int copy_into (char* buf, int max_size); 00095 00096 private: 00097 00098 /// Pointers to keep track of the input string. 00099 static char* string_; 00100 static char* current_; 00101 static char* end_; 00102 }; 00103 00104 /// The union used by lex and bison to build the Abstract Syntax Tree. 00105 typedef union 00106 { 00107 ACE_VERSIONED_NAMESPACE_NAME::ETCL_Constraint* constraint; 00108 } YYSTYPE; 00109 00110 extern YYSTYPE yylval; 00111 extern YYSTYPE yyval; 00112 00113 ACE_END_VERSIONED_NAMESPACE_DECL 00114 00115 #include /**/ "ace/post.h" 00116 00117 #endif // ETCL_INTERPRETER_H