00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Interpreter.h 00006 * 00007 * Interpreter.h,v 1.15 2006/03/14 06:14:35 jtc Exp 00008 * 00009 * @author Seth Widoff <sbw1@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_TCL_INTERPRETER_H 00014 #define TAO_TCL_INTERPRETER_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include "orbsvcs/Trader/Constraint_Nodes.h" 00018 #include "orbsvcs/Trader/Constraint_Visitors.h" 00019 #include "orbsvcs/Trader/trading_serv_export.h" 00020 00021 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00022 00023 class TAO_Constraint_Evaluator; 00024 class TAO_Constraint_Validator; 00025 00026 /** 00027 * @class TAO_Interpreter 00028 * 00029 * @brief TAO_Interpreter is the superclass for all interpreters. Its 00030 * build tree method invokes the yacc parser to parse a constraint 00031 * or preference string. 00032 */ 00033 class TAO_Trading_Serv_Export TAO_Interpreter 00034 { 00035 protected: 00036 // = Initialization and termination methods. 00037 /// Constructor. 00038 TAO_Interpreter (void); 00039 00040 /// Destructor. 00041 ~TAO_Interpreter (void); 00042 00043 /// Using the Yacc generated parser, construct an expression tree 00044 /// representing <constraints> from the tokens returned by it. 00045 int build_tree (const char* preferences); 00046 00047 static int is_empty_string (const char* str); 00048 00049 /// The root of the expression tree, not equal to null if build_tree 00050 /// successfully builds a tree from the constraints. 00051 TAO_Constraint* root_; 00052 private: 00053 /// This mutex protects the <build_tree> method from reentrance. 00054 static TAO_SYNCH_MUTEX parserMutex__; 00055 }; 00056 00057 00058 // Functions we need for parsing. 00059 extern int yyparse (void); 00060 extern void yyrestart (FILE*); 00061 extern int yylex (void); 00062 00063 // Have yylex read from the constraint string, not from stdin. 00064 #undef YY_INPUT 00065 #define YY_INPUT(b, r, ms) (r = TAO_Lex_String_Input::copy_into(b, ms)) 00066 00067 #undef yyerror 00068 #define yyerror(x) 00069 00070 /** 00071 * @class TAO_Lex_String_Input 00072 * 00073 * @brief Have Lex read from a string and not from stdin. Essentially, 00074 * the interpreter needs to call yylex() until EOF, and call 00075 * TAO_Lex_String_Input::reset() with the new string, prior to 00076 * calling yyparse. 00077 */ 00078 class TAO_Lex_String_Input 00079 { 00080 public: 00081 /// Reset the lex input. 00082 static void reset (char* input_string); 00083 00084 /// Method lex will call to read from the input string. 00085 static int copy_into (char* buf, int max_size); 00086 00087 private: 00088 00089 /// Pointers to keep track of the input string. 00090 static char* string_; 00091 static char* current_; 00092 static char* end_; 00093 }; 00094 00095 // The union used by lex and yacc to build the Abstract Syntax Tree. 00096 typedef union 00097 { 00098 TAO_Constraint* constraint_; 00099 } YYSTYPE; 00100 00101 extern YYSTYPE yylval; 00102 extern YYSTYPE yyval; 00103 00104 TAO_END_VERSIONED_NAMESPACE_DECL 00105 00106 #include /**/ "ace/post.h" 00107 #endif /* TAO_TCL_INTERPRETER_H */