1 #ifndef recipe_h 2 #define recipe_h 3 4 5 #include "config.h" 6 #include "recipenode.h" 7 #include "token.h" 8 9 class Lexer; 10 class Token; 11 12 ////////////////////////////////////////////////////////////////////////// 13 // 14 // Class Recipe - parsed structure of a recipe file. 15 // This class reads tokens from the Lexer class, and arranges them in a 16 // logical structure that represents the recipe file. The Recipe object 17 // maints a list of RecipeNode objects, which roughly represent individual 18 // statements, and elements of a recipe file. There is more or less a 19 // one-to-one relationship between Tokens and Recipenodes. Usually one 20 // RecipeNode is created for each token - but not always. The RecipeNode 21 // objects are automatically created by the Recipe object when ParseRecipe() 22 // is called to translate the tokens returned by the Lexer class into 23 // the RecipeNode structure. When the Recipe object is destroyed, it 24 // automatically destroys all RecipeNode objects it has allocated. 25 // The RecipeNode objects are created using a simple recursive-descent 26 // parser. 27 // 28 // The ExecuteRecipe() function actually starts the ball rolling by 29 // calling the Evaluate() function of the first RecipeNode object in the 30 // structure. 31 // 32 ////////////////////////////////////////////////////////////////////////// 33 34 35 #include "../dbobj.h" 36 37 class Recipe { 38 39 RecipeNode *firstNode, *lastNode; // All nodes in this recipe. 40 RecipeNode *topNode; // Topmost node. 41 42 RecipeNode *alloc(RecipeNode::RecipeNodeType); 43 44 Lexer *lex; 45 Token cur_tok; 46 47 public: 48 Recipe(); 49 ~Recipe(); 50 51 int ParseRecipe(Lexer &); 52 void ExecuteRecipe(); 53 void errmsg(RecipeNode &, const char *); 54 55 #ifdef DbObj 56 DbObj gdbm_file; 57 #endif 58 59 private: 60 // This is, essentially, a recursive-descent parser that builds 61 // the RecipeNode tree. ParseExpr()62 RecipeNode *ParseExpr() 63 { 64 return (ParseAssign()); 65 } 66 RecipeNode *ParseAssign(); 67 RecipeNode *ParseLogicalOr(); 68 RecipeNode *ParseLogicalAnd(); 69 RecipeNode *ParseComparison(); 70 RecipeNode *ParseBitwiseOr(); 71 RecipeNode *ParseBitwiseAnd(); 72 RecipeNode *ParseAddSub(); 73 RecipeNode *ParseMultDiv(); 74 RecipeNode *ParseStrRegExp(); 75 RecipeNode *ParseStatementList(); 76 RecipeNode *ParseStatement(); 77 RecipeNode *ParseSubStatement(); 78 RecipeNode *ParseString(); 79 RecipeNode *ParseElement(); 80 } ; 81 82 #endif 83