|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
JJTree nodes: fields for specific childs.Hi all!
I have a question regarding JJTree. For instance, take a grammar for simple expressions (like that in examples\JJTreeExamples\eg4.jjt example). (With the proper options set) JJTree generates the corresponding visitor interface and the specific nodes. So far as I've seen, these specific nodes have nothing specific but theirs type; I mean, they only have the mandatory constructors, and the jjtAcept method. I think (maybe I'm wrong) that it would be useful to have more specific things (fields or methods) on each (generated) node class. After all, in the visitor interface each Visit overload (for every kind of node) receives an specific node. Fundamentally, what seems to be useful is to have specifics fields (or accessors) to the childs, in accordance to the production. For instance, having void AdditiveExpression() : {} { ( MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* ) #Add(>1) } it would be nice to the able to retrieve the left hand side, the right hand side and the operator with those specific. Currently, as I see it, one has to browse the childs and have knowledge of the meaning of a child in a given position. When writting a visitor that evaluates the tree it would be nice to be able to write something like public Object visit(AdditiveExpression node, Object data) { int t1 = getLHS().jjtAccept(this, data).intValue(); int t2 = getRHS().jjtAccept(this, data).intValue(); if(getOp().equals("+")) { t1+= t2; } else { t1-= t2; } return new Integer(t1); } Any advice on this issue will be appreciated. Thanks a lot to you all. -- Rodolfo Federico Gamarra --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: JJTree nodes: fields for specific childs.Hi
What you ask for is something that JTB (Java Tree Builder) offers (generates for you) and that JJTree does not offer directly (you have to code it yourself). With JTB, you write a JavaCC grammar, process it through JTB, a get a new ("annotated") grammar and syntax tree files in which each node will have generated fields referring to its node children. Each node will be of one of the following base types : NodeToken ("blabla"), NodeChoice (A|B), NodeOptional ([A] or ((A)?), NodeList ((A)+), NodeListOptional ((A)*) or NodeSequence (x y ... nested within a choice, list, optional list or optional node). In the example the AdditiveExpression node will be a "NodeSequence" node with 3 children nodes, a MultiplicativeExpression node (also itself a "NodeSequence" node) (refered by f0), a "NodeChoice" node (which children will be "NodeToken" nodes : "+" and "-") (refered by f1), and another MultiplicativeExpression node (refered by f2). In the visit methode of AdditiveExpression, you can visit f0 and f2 (to get their values, by any mechanism you want : global variables, visit method with a user argument or user return type), find the operator (f1.which will be 0 if "+" or 1 if "-", f1.choice will be the NodeToken in which the token.image will be the String "+" or "-"), and perform the operation. Marc MAZAS -----Message d'origine----- De : Rodolfo Federico Gamarra [mailto:rgamarra@...] Envoyé : mercredi 15 juillet 2009 19:14 À : users@... Objet : [JavaCC] JJTree nodes: fields for specific childs. Hi all! I have a question regarding JJTree. For instance, take a grammar for simple expressions (like that in examples\JJTreeExamples\eg4.jjt example). (With the proper options set) JJTree generates the corresponding visitor interface and the specific nodes. So far as I've seen, these specific nodes have nothing specific but theirs type; I mean, they only have the mandatory constructors, and the jjtAcept method. I think (maybe I'm wrong) that it would be useful to have more specific things (fields or methods) on each (generated) node class. After all, in the visitor interface each Visit overload (for every kind of node) receives an specific node. Fundamentally, what seems to be useful is to have specifics fields (or accessors) to the childs, in accordance to the production. For instance, having void AdditiveExpression() : {} { ( MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* ) #Add(>1) } it would be nice to the able to retrieve the left hand side, the right hand side and the operator with those specific. Currently, as I see it, one has to browse the childs and have knowledge of the meaning of a child in a given position. When writting a visitor that evaluates the tree it would be nice to be able to write something like public Object visit(AdditiveExpression node, Object data) { int t1 = getLHS().jjtAccept(this, data).intValue(); int t2 = getRHS().jjtAccept(this, data).intValue(); if(getOp().equals("+")) { t1+= t2; } else { t1-= t2; } return new Integer(t1); } Any advice on this issue will be appreciated. Thanks a lot to you all. -- Rodolfo Federico Gamarra --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: JJTree nodes: fields for specific childs.On Jul 15, 2009, at 1:13 PM, Rodolfo Federico Gamarra wrote: > Hi all! > > I have a question regarding JJTree. For instance, take a grammar for > simple expressions (like that in examples\JJTreeExamples\eg4.jjt > example). (With the proper options set) JJTree generates the > corresponding visitor interface and the specific nodes. > > So far as I've seen, these specific nodes have nothing specific but > theirs type; I mean, they only have the mandatory constructors, and > the jjtAcept method. > > I think (maybe I'm wrong) that it would be useful to have more > specific things (fields or methods) on each (generated) node class. > After all, in the visitor interface each Visit overload (for every > kind of node) receives an specific node. As you say, the generated node source code is very simple, so your grammar modifications usually do not require the node source code to be regenerated. So usually I just add my custom methods to the node source files after they are generated. Then I write the rest of my code to use those methods. Yours, Tom http://generatingparserswithjavacc.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: JJTree nodes: fields for specific childs.Hi Marc & Tom,
Thanks a lot for your answers. In regards to JTB, I've seen in the past that it offered that; returning to the subject of parse generators I had to choose (not definitively so far) between JJT and JTB. JJT has the pro that comes built-in with JCC. On the other hand, looking for JTB I saw these two pages: http://compilers.cs.ucla.edu/jtb/ http://compilers.cs.ucla.edu/jtb/jtb-2003/ On the first, it's said that "1.3.2" needs Java 1.5 (which I'd rather not use due to some non-functional constraints I have to cope with), and in the other it's said that version "1.2.2" was released in 2000; so some doubts about the developing status of JTB came to me: is it a dead project? In regards to modifying the generated sources, it's certainly true what you state and it's a good observation that is unlikely that they'll suffer modifications. So, despite that maybe these modifications will be kinda repetitive (and are, in some way, already expressed in the .jj) they would be done once and for all. Thanks again to you both. -- Rodolfo Federico Gamarra --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Re: JJTree nodes: fields for specific childs.On Jul 21, 2009, at 3:26 PM, Rodolfo Federico Gamarra wrote: > On the first, it's said that "1.3.2" needs Java 1.5 (which I'd rather > not use due to some non-functional constraints I have to cope with), > and in the other it's said that version "1.2.2" was released in 2000; > so some doubts about the developing status of JTB came to me: is it a > dead project? Yeah, that would be my main concern about JTB too. I exchanged a few email with Dr. Palsberg about it and he thought there were still a fair number of people using JTB... so who knows, it may rise again. > In regards to modifying the generated sources, it's certainly true > what you state and it's a good observation that is unlikely that > they'll suffer modifications. So, despite that maybe these > modifications will be kinda repetitive (and are, in some way, already > expressed in the .jj) they would be done once and for all. It does seem like it would be nicer to have them externalized somehow... but yeah, the current solution isn't too painful either. Yours, Tom http://generatingparserswithjavacc.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: Re: JJTree nodes: fields for specific childs.Hi Rodolfo
About JTB : it looks there is no maintenance activity on it ; so I decided to do what I wanted for it : I almost finished a bunch of modifications : - adapted it to JavaCC 4.2 grammar, - refactored a lot and fully upgraded it to JDK 1.5 (but that means compiler compliance level, generated .class file compatibility and source compatibility all at 1.5 level, so in your case it would mean to remove generics / enums and change StringBuilders in StringBuffers, which would be feasible but a little tedious), - removed java blocks / javacode sections / return types limitations, - enhanced generated visitors comments and code. I'll propose to add it as a side product to the JavaCC / JJTree / JJDoc project (but I have not looked at licences issues and authors permissions : if Paul or Tom can advice, I would be pleased). Marc MAZAS Phone : +33 (0)4 72 18 47.19 Mobile : +33 (0)6 89 86 50 56 -----Message d'origine----- De : Rodolfo Federico Gamarra [mailto:rgamarra@...] Envoyé : mardi 21 juillet 2009 21:26 À : users@... Objet : [JavaCC] Re: JJTree nodes: fields for specific childs. Hi Marc & Tom, Thanks a lot for your answers. In regards to JTB, I've seen in the past that it offered that; returning to the subject of parse generators I had to choose (not definitively so far) between JJT and JTB. JJT has the pro that comes built-in with JCC. On the other hand, looking for JTB I saw these two pages: http://compilers.cs.ucla.edu/jtb/ http://compilers.cs.ucla.edu/jtb/jtb-2003/ On the first, it's said that "1.3.2" needs Java 1.5 (which I'd rather not use due to some non-functional constraints I have to cope with), and in the other it's said that version "1.2.2" was released in 2000; so some doubts about the developing status of JTB came to me: is it a dead project? In regards to modifying the generated sources, it's certainly true what you state and it's a good observation that is unlikely that they'll suffer modifications. So, despite that maybe these modifications will be kinda repetitive (and are, in some way, already expressed in the .jj) they would be done once and for all. Thanks again to you both. -- Rodolfo Federico Gamarra --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
|
|
|
Re: Re: JJTree nodes: fields for specific childs.On Jul 22, 2009, at 3:29 AM, Mazas Marc wrote: > Hi Rodolfo > About JTB : it looks there is no maintenance activity on it ; so I > decided to do what I wanted for it : I almost finished a bunch of > modifications : > - adapted it to JavaCC 4.2 grammar, > - refactored a lot and fully upgraded it to JDK 1.5 (but that means > compiler compliance level, generated .class file compatibility and > source compatibility all at 1.5 level, so in your case it would mean > to remove generics / enums and change StringBuilders in > StringBuffers, which would be feasible but a little tedious), > - removed java blocks / javacode sections / return types limitations, > - enhanced generated visitors comments and code. Nice! > I'll propose to add it as a side product to the JavaCC / JJTree / > JJDoc project (but I have not looked at licences issues and authors > permissions : if Paul or Tom can advice, I would be pleased). Yeah, let's discuss over on javacc-dev... I'm not sure about all that license stuff either... and who knows, Dr. Palsberg might want to see if you'd fold those changes back into whereever the current JTB source code repo is... Yours, Tom --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |