Back to index

courier  0.68.2
recipe.h
Go to the documentation of this file.
00001 #ifndef recipe_h
00002 #define       recipe_h
00003 
00004 
00005 #include      "config.h"
00006 #include      "recipenode.h"
00007 #include      "token.h"
00008 
00009 class Lexer;
00010 class Token;
00011 
00013 //
00014 // Class Recipe - parsed structure of a recipe file.
00015 // This class reads tokens from the Lexer class, and arranges them in a
00016 // logical structure that represents the recipe file.  The Recipe object
00017 // maints a list of RecipeNode objects, which roughly represent individual
00018 // statements, and elements of a recipe file.  There is more or less a
00019 // one-to-one relationship between Tokens and Recipenodes.  Usually one
00020 // RecipeNode is created for each token - but not always.  The RecipeNode
00021 // objects are automatically created by the Recipe object when ParseRecipe()
00022 // is called to translate the tokens returned by the Lexer class into
00023 // the RecipeNode structure.  When the Recipe object is destroyed, it
00024 // automatically destroys all RecipeNode objects it has allocated.
00025 // The RecipeNode objects are created using a simple recursive-descent
00026 // parser.
00027 //
00028 // The ExecuteRecipe() function actually starts the ball rolling by
00029 // calling the Evaluate() function of the first RecipeNode object in the
00030 // structure.
00031 //
00033 
00034 
00035 #include      "../dbobj.h"
00036 
00037 class Recipe {
00038 
00039        RecipeNode *firstNode, *lastNode;  // All nodes in this recipe.
00040        RecipeNode *topNode;               // Topmost node.
00041 
00042        RecipeNode *alloc(RecipeNode::RecipeNodeType);
00043 
00044        Lexer  *lex;
00045        Token  cur_tok;
00046 
00047 public:
00048        Recipe();
00049        ~Recipe();
00050 
00051        int ParseRecipe(Lexer &);
00052        void ExecuteRecipe();
00053        void errmsg(RecipeNode &, const char *);
00054 
00055 #ifdef DbObj
00056        DbObj  gdbm_file;
00057 #endif
00058 
00059 private:
00060        // This is, essentially, a recursive-descent parser that builds
00061        // the RecipeNode tree.
00062        RecipeNode *ParseExpr()
00063               {
00064                      return (ParseAssign());
00065               }
00066        RecipeNode *ParseAssign();
00067        RecipeNode *ParseLogicalOr();
00068        RecipeNode *ParseLogicalAnd();
00069        RecipeNode *ParseComparison();
00070        RecipeNode *ParseBitwiseOr();
00071        RecipeNode *ParseBitwiseAnd();
00072        RecipeNode *ParseAddSub();
00073        RecipeNode *ParseMultDiv();
00074        RecipeNode *ParseStrRegExp();
00075        RecipeNode *ParseStatementList();
00076        RecipeNode *ParseStatement();
00077        RecipeNode *ParseSubStatement();
00078        RecipeNode *ParseString();
00079        RecipeNode *ParseElement();
00080 } ;
00081 
00082 #endif