Never mind... I think I found the problem; I had some subtle typo's in the names so I was not overriding the appropriate methods. It seems to be working as I expected now...
Thanks Roger > ----- Original Message ----- > From: "Roger Pomeroy" <[EMAIL PROTECTED]> > To: "Discussion mailing list for the SableCC project" > <[email protected]> > Subject: Re: Trying to understand cst->ast transformations > Date: Tue, 21 Oct 2008 21:30:40 -0800 > > > That was it, thanks! I was able to generate what I think is the > AST that I want... but when I try to use it, it isn't working the > way I expect. Apparently, I don't understand at least some of the > basic concepts here. If you could clarify some points, I'd > appreciate it. > > I have an ast that looks like : > Abstract Syntax Tree > > statements = statement statements > | {null} > ; > statement = > {empty} new_line > | {assignment} lhs assign_operator expression > | {postop} lhs post_operator > | {label} identifier > ; > lhs = {identifier} identifier > ; > assign_operator = {assign} equals > | {star_assign} star_assign > | {slash_assign} slash_assign > | {plus_assign} plus_assign > | {minus_assign} minus_assign > ; > > > And as I expected, SableCC generated various classes, including > (looking at the nodes) > AStatements.java > AAssignmentStatement.java > ALabelStatement.java > AAssignAssignOperator.java > and so on. > > I created a little routine Interperter that I just want to > simply echo the statements as it sees them going through the tree: > > public class Interperter extends DepthFirstAdapter { > > public void caseAEmptyStatement (AEmptyStatement node) { > System.out.print("." ); > } > public void caseAStatements (AStatements node) { > System.out.print(" Statements seen: " ); > System.out.println(node.getStatement().toString()); > } > public void caseAAssigmentStatement (AAssignmentStatement node) { > System.out.print(" Assignment Statement seen: " ); > System.out.print(node.getLhs().toString()); > System.out.print(node.getAssignOperator().toString()); > System.out.println(node.getExpression().toString()); > } > } > > But what I don't understand is that it appears that > CaseAAsignStatement is never called; Looking at AStatements.java, > I see getStatement() and getStatements(), but I don't seem to see > how AAssignmentStatement is invoked, or, for that matter, how any > of the other alternatives are accessed. > > Can someone explain to me what I am missing? > > Thanks ! > > Roger > > > > ----- Original Message ----- > > From: "Etienne M. Gagnon" <[EMAIL PROTECTED]> > > To: "Discussion mailing list for the SableCC project" > > <[email protected]> > > Subject: Re: Trying to understand cst->ast transformations > > Date: Mon, 20 Oct 2008 20:32:12 -0400 > > > > > > Hi Roger, > > > > SableCC 3 just caught a transformation bug in your grammar: > > > > unop {-> expression} = ... > > > > As unop is preserved in the AST, you should not transform it. Solution: > > Just remove the "{-> ...}". > > > > Have fun! > > > > Etienne > > > > Roger Pomeroy wrote: > > > I am now trying to understand how to do the CST->AST > > > transformations for my grammer. I was starting with just trying > > > to transform the expression section of my grammar (trying to > > > follow the sample in > > > http://nat.truemesh.com/archives/000531.html) I have a CST > > > section that looks like: > > > ... > > > > > > > -- > > Etienne M. Gagnon, Ph.D. > > SableCC: http://sablecc.org > > << signature.asc >> > > > > _______________________________________________ > > SableCC-Discussion mailing list > > [email protected] > > http://lists.sablecc.org/listinfo/sablecc-discussion > > > > > > -- > See Exclusive Video: Hollywood Life's 5th Annual Style Awards > http://www.hollywoodlife.net/Awards.aspx?AwardsID=style2008 > > > _______________________________________________ > SableCC-Discussion mailing list > [email protected] > http://lists.sablecc.org/listinfo/sablecc-discussion > -- See Exclusive Video: Hollywood Life's 5th Annual Style Awards http://www.hollywoodlife.net/Awards.aspx?AwardsID=style2008 _______________________________________________ SableCC-Discussion mailing list [email protected] http://lists.sablecc.org/listinfo/sablecc-discussion
