[antlr-interest] Seperating Grammar and Actions..

Ruslan Zasukhin sunshine at public.kherson.ua
Sun Jan 12 02:57:58 PST 2003


on 1/11/03 6:12 PM, cintyram <cintyram at yahoo.com> at cintyram at yahoo.com
wrote:

> hi ,
> this is with reference to the discussion on this list a few weeks ago
> on the same topic. then i was of the opinion that, using an abstract
> class could help. but now having dipped my fingers into mfc to write
> some user interface for my translator , i have begun wondering if some
> thing like message maps works for antlr too ;
> each rule match can fire an event/message , which can be handled by
> the assigned event-handler . the information on which handler handles
> which event can be put in message-maps ;
> 
> when writing the grammar we can exclude all action code from the
> grammar [ whose purpose is to match the input stream ( of tokens,chars
> or whatever ) ], but fire events ..
> 
> how to name the events if we want to have seperate events for each
> subrule ? other wise as antlr generated code now has, the name of the
> rule can be the name of the event also [now it is the name of the
> function ]
> 
> how to handle cases where rules return values?
> 
> also passing the matched content thru the event to the handler , can
> be an implementation  decision . [ passing by copy might not be a very
> attractive option etc .. ]
> 
> also now we will have more flexibility .. we can pass around the
> grammar exclusively of the actions taken, and the handlers can be
> completely  decoupled from the grammar!
> 
> your views please,

Interesting idea, and it may works I think.
Payment slow down on each call, because we will have switch with about
100-500 cases.

Then I'd prefer little modification of your idea.
-- We write actions in separate file,
-- We write them using special name, okay let this will be Events, or may be
the same tokens...
-- So we get the next structure of files
        MyGrammar.g
        MyTreeGrammar.g
        MyCppActions    -- on events from Tree grammar
        myJavaActions   -- on events from Tree grammar

And now ANTLR can take TreeGrammar and Action files parse them. And produce
THE SAME output as it do now. I.e. We do not get penalty for big switch and
additional indirect call.

------
But As you have note self problem is how do in this way thing as

Rule
    : n1 = rule2 { use n1 here }
    
-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list
send a letter to valentina-on at lists.macserve.net
-------------------------------------------------------------


 

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



More information about the antlr-interest mailing list