dcsimg
How to create AST Node using AST Rule for optional arguments?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tapodyuti_Mandal
Posted On:   Monday, August 25, 2003 09:18 AM

I want to implement an AST for the following grammar: and_expr : atom ((MULT^)? atom)*; I have alraedy defined a MULTNode class as follow: #define INC_MULTNode_hpp__ #include "BinaryOperatorAST.hpp" /** A simple node to represent MULT operation */ class MULTNode : public BinaryOperatorAST { public: MULTNode(ANTLR_USE_NAMESPACE(antlr)RefCount oken> token) : BinaryOperatorAST(token) { } int value() const { return left()->value() * right()->value(); } ANTLR_USE_NAMESPACE(std)string toString() const { return " *"; } void initialize(int t, const   More>>

I want to implement an AST for the following grammar:

and_expr : atom ((MULT^)? atom)*;

I have alraedy defined a MULTNode class as follow:

#define INC_MULTNode_hpp__

#include "BinaryOperatorAST.hpp"

/** A simple node to represent MULT operation */
class MULTNode : public BinaryOperatorAST {
public:
MULTNode(ANTLR_USE_NAMESPACE(antlr)RefCount
oken> token) : BinaryOperatorAST(token)
{
}

int value() const
{
return left()->value() * right()->value();
}

ANTLR_USE_NAMESPACE(std)string toString() const
{
return " *";
}

void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt)
{
CalcAST::initialize(t, txt);
}
void initialize(ANTLR_USE_NAMESPACE(antlr)RefAST t)
{
CalcAST::initialize(t);
}
void initialize(ANTLR_USE_NAMESPACE(antlr)RefToken tok)
{
CalcAST::initialize(tok);
}
};

typedef ANTLR_USE_NAMESPACE(antlr)ASTRefCount RefMULTNode;

#endif //INC_MULTNode_hpp__


Please, let me know the approach.

   <<Less
About | Sitemap | Contact