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