/* * These types and functions effectively define the structure of parse trees * for J- programs. */ #include #include typedef unsigned char bool; #define TRUE 1 #define FALSE 0 #ifndef STREENODE_H #define STREENODE_H #define MAXCHILDREN 4 typedef enum { n_id, /* identifier - string (extra) */ n_class, /* class - id, id of extended class, decs */ n_fdec, /* field dec - type, ids */ n_constrdec, /* constructor dec - id, param decs, compound stmt */ n_methdec, /* method dec - type, id, param decs, compound stmt */ n_paramdec, /* param dec - type, id */ n_vardec, /* var dec - type, ids */ n_empty, /* empty stmt */ n_ret, /* return stmt - exp */ n_cond, /* if stmt - condition, then part, else part */ n_while, /* while stmt - condition, compound stmt */ n_assign, /* assignment stmt - var, exp */ n_compexp, /* compound exp - opr, exp, exp */ n_opr, /* operator - string (extra) */ n_intval, /* int val - val (extra) */ n_doubleval, /* double val - val (extra) */ n_stringval, /* string val - val (extra) */ n_boolval, /* bool val - val (extra) */ n_fieldref, /* obj.field - object, field */ n_methcall, /* method call: m(...) = this.m(...) or obj.m(...) * - object, id, params */ n_constrcall, /* constructor call - id, arguments */ n_cast, /* cast exp - type, exp */ n_null, /* null */ n_this /* this */ } NodeType; struct STreeNode; typedef struct STreeNode* STreePtr; struct STreeNode { NodeType type; STreePtr children[MAXCHILDREN]; STreePtr sibling; char* extrainfo; }; STreePtr Create(NodeType t, const STreePtr c0, const STreePtr c1, const STreePtr c2, const STreePtr c3); STreePtr CreateString(NodeType t, const char *s); void Destroy(STreePtr n); bool HasChild(const STreePtr n); STreePtr GetChild(const STreePtr n, const unsigned int i); void SetChild(STreePtr n, const unsigned int i, const STreePtr c); void SetSibling(STreePtr n, const STreePtr c); void SetLastSibling(STreePtr n, const STreePtr c); void SetExtraInfo(STreePtr n, const char *s); void Print(const STreePtr n, FILE *os, const unsigned int indent); #endif