[antlr-interest] Opinion of the professionals, please

Laat-de, Geert-Jan Geert-Jan.Laat-de at dsm.com
Thu Jun 10 01:07:57 PDT 2004


Hi,

I'm currently using ANTLR to build a tool to generate analytical partial
derivatives for equations. I successfully implemented the lexer and parser
bit, thanks to all the nice examples supplied with ANTLR. I'm generating the
derivatives by implementing a tree parser. Part of the source code you can
find below. Could you give me some feedback on the way I've implemented
stuff ? 

Thank you very much for the tool and your feedback,

Geert-Jan

[Start of Code snippet]
expr
        :       #(PLUS expr expr)        // Sum Rule: D[u+v] = D[u]+D[v]
        |       #(MINUS expr expr)       // Sum Rule: D[u+v] = D[u]+D[v]
        |!      #(MULT lm:expr rm:expr)  // Product Rule: D[u*v] = u*D[v]
+v*D[u]
                {
                    DerivativeWalker w_lm;
                    DerivativeWalker w_rm;

		        w_lm.setASTFactory(astFactory);
		        w_rm.setASTFactory(astFactory);

                    w_lm.derive_var = derive_var;
                    w_rm.derive_var = derive_var;

                    w_lm.expr( lm);

                    w_rm.expr( rm);

		        ANTLR_USE_NAMESPACE(antlr)RefAST m1 =
astFactory->create(MULT, "*");
		        ANTLR_USE_NAMESPACE(antlr)RefAST m2 =
astFactory->create(MULT, "*");

		        m1->addChild( astFactory->dupTree(lm));
		        m1->addChild( astFactory->dupTree(w_rm.getAST()));
		        m2->addChild( astFactory->dupTree(rm));
		        m2->addChild( astFactory->dupTree(w_lm.getAST()));

		        ANTLR_USE_NAMESPACE(antlr)RefAST p1 =
astFactory->create(PLUS, "+");
		        p1->addChild( m1);
		        p1->addChild( m2);

                    #expr = p1;
                }
	;

This e-mail is for the intended recipient only.
If you have received it by mistake please let us know by reply and then
delete it from your system; access, disclosure, copying, distribution or
reliance on any of it by anyone else is prohibited.
If you as intended recipient have received this e-mail incorrectly, please
notify the sender (via e-mail) immediately.


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list