// File: parsemain.C // // Using the parser to create an expression tree. #include #include "token.h" #include "tokenitem.h" #include "tokenizer.h" #include "etree.h" #include "parse.h" #define BUFLEN 256 main() { Tokenizer *T ; ETree *Expr ; char str[BUFLEN] ; printf("Enter an expression: ") ; fgets(str, BUFLEN, stdin) ; fflush(stdin) ; T = new Tokenizer(str) ; Expr = ParseEverything(T) ; if (Expr != NULL) { printf("\nInorder Walk:\n") ; Expr->Inorder() ; printf(" = %d\n", Expr->Evaluate()) ; printf("\nPreorder Walk:\n") ; Expr->Preorder() ; printf("\n") ; printf("\nPreorder Walk:\n") ; Expr->Preorder() ; printf("\n") ; } delete T ; }