dcsimg
Extending a Parser
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Patrick_Vachon
Posted On:   Tuesday, December 23, 2003 07:31 AM

Hi, How do we extend our own defined Parser? Take this sample myParser.g: class myParser extends Parser { options { importVocab=myLexer; } ... isATag {} : "TAG" {} ( t:NUMBER { _counter++; } )+ END; } I would like to extend myParser to provide a new isATag method. Here is myExtParser.g: class myExtParser extends myParser { options { importVocab=myLexer; } ... isATag {} : "TAG" {} ( t:NUMBER { _counter += 2; } )+ END; } I do not want to do it directly in Java, I prefer to use another .g file to implement myExtParser   More>>

Hi,



How do we extend our own defined Parser?

Take this sample myParser.g:

			
class myParser extends Parser {
options { importVocab=myLexer; }
...
isATag {} : "TAG" {}
( t:NUMBER { _counter++; } )+
END;
}



I would like to extend myParser to provide a new isATag method. Here is myExtParser.g:

			
class myExtParser extends myParser {
options { importVocab=myLexer; }
...
isATag {} : "TAG" {}
( t:NUMBER { _counter += 2; } )+
END;
}



I do not want to do it directly in Java, I prefer to use another .g file to implement myExtParser class to minimize maintenance.

The problem is when I try to generate myExtParser.java, I got an error:

error: grammar myParser not defined



Is there a way to do it in a separate .g file?
Thanks a lot for your help.


Patrick    <<Less

Re: Extending a Parser

Posted By:   Mick_Dundee  
Posted On:   Friday, January 2, 2004 11:24 AM

Howdy. You should be able to use the extends mechanism for grammars. Are you using the -glib option?




Terence

Re: Sorry this is not really an answer

Posted By:   Simon_Ablett  
Posted On:   Monday, December 29, 2003 05:23 AM

Re. posting new questions...

There should be an 'Ask a question' button on the right hand side of the screen. If you can't see it then maybe it is because you are not a premium member (!?).

Regards.

Sorry this is not really an answer

Posted By:   Mehdi_Mehdi  
Posted On:   Wednesday, December 24, 2003 11:42 AM

Sorry, but I can't figure out how to submit a NEW post in this stupid forum. I spent almost half an hour trying to find some "post new thread", "new", ...etc. It's either a stupid forum or I'm the stupid one :(.

Anyways,.. I'm investigating ANTLR. I need to know whether there is a viable C++ grammer as I want to be able to parse my C++ code and (let's say) generate some functions for every class (e.g. classA.toString(), classA.toSQL()).

Is that possible with ANTLR, if yes how do we go about it?

Please anyone help.... I really need it.
About | Sitemap | Contact