#ifndef AST_h
#define AST_h

#include "ASTBase.h"
#include "AToken.h"
#include "ATokPtr.h"

class AST : public ASTBase {
protected:
	ANTLRTokenPtr token;
public:
       
	AST(ANTLRTokenType tok, char *s) { token = new ANTLRToken(tok, s); }
	AST(ANTLRTokenPtr t) { token = t; }
	void preorder_action() {
		cout <<  token->getText()  << " " ;
	}

        void preorder_before_action() {
		cout << "(" ;
	}

        void preorder_after_action() {
		cout <<  ")" ;
	}
	virtual int type() { return token->getType(); }
	char *getText()	   { return token->getText(); }

        void preorder () 
	{

	  AST * tree = this;

	  while (tree !=NULL) 
	  {
	    if (tree->down()!=NULL)
	      tree->preorder_before_action();

	    tree->preorder_action();
	  
	    if (tree->down()!=NULL) {
	      AST *d;
	      d=(AST*) tree->down();
	      d->preorder();
	      tree->preorder_after_action();
	    }
	    tree= (AST *) tree->right();
	  }
	 }
};

#endif

