|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.czt.print.z.PrecedenceParenAnnVisitor
public class PrecedenceParenAnnVisitor
This visitor visits an printable AST and adds necessary parentheses.
The input tree must be a tree created by the AstToPrintTreeVisitor. This visitor adds parenthesis annotations to terms where parenthesis are needed to preserve the syntactical structure of the operators when printed. That is, parenthesis annotations are added when a term does not already has one, and either the parent term has a higher priority, or the parent has the same priority but the parenthesis is enforced by associativity.
For instance, a conjunction where one of the arguments is an implication needs parenthesis around the implication, since conjunction has higher priority than implication. For the second example, recall that implication is right associative. An implication that has an implication as its first (left) argument needs parenthesis around, whereas an implication as second (right) argument does not need parenthesis.
| Constructor Summary | |
|---|---|
PrecedenceParenAnnVisitor()
|
|
| Method Summary | |
|---|---|
protected void |
addParenAnn(net.sourceforge.czt.base.ast.Term term)
|
protected void |
addParenAnnIfNecessary(java.lang.Object object,
Precedence parentPrec)
Adds parenthesis annotations to the given object if it is an annotable term and the precedence of the parent is greater than the precedence of the given term. |
protected void |
addParenAnnIfNecessary(net.sourceforge.czt.base.ast.Term term,
Precedence parentPrec)
Adds parenthesis annotations to the given term if the precedence of the parent is greater than the precedence of the given term. |
protected boolean |
isInfix(net.sourceforge.czt.z.util.OperatorName opName)
|
Precedence |
precedence(net.sourceforge.czt.base.ast.Term term)
|
protected void |
preservePrecedence(net.sourceforge.czt.base.ast.Term term)
|
void |
run(net.sourceforge.czt.base.ast.Term term)
Visits a term and its children and adds ParenAnn to terms where this is needed to enforce the given precedence and associativity. |
java.lang.Object |
visitApplication(Application appl)
|
java.lang.Object |
visitExpr(net.sourceforge.czt.z.ast.Expr term)
|
java.lang.Object |
visitOperatorApplication(OperatorApplication appl)
|
java.lang.Object |
visitPred(net.sourceforge.czt.z.ast.Pred term)
|
java.lang.Object |
visitProdExpr(net.sourceforge.czt.z.ast.ProdExpr prodExpr)
|
java.lang.Object |
visitTerm(net.sourceforge.czt.base.ast.Term term)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PrecedenceParenAnnVisitor()
| Method Detail |
|---|
public void run(net.sourceforge.czt.base.ast.Term term)
Visits a term and its children and adds ParenAnn to terms where this is needed to enforce the given precedence and associativity.
public java.lang.Object visitTerm(net.sourceforge.czt.base.ast.Term term)
visitTerm in interface net.sourceforge.czt.base.visitor.TermVisitorpublic java.lang.Object visitPred(net.sourceforge.czt.z.ast.Pred term)
visitPred in interface net.sourceforge.czt.z.visitor.PredVisitorpublic java.lang.Object visitExpr(net.sourceforge.czt.z.ast.Expr term)
visitExpr in interface net.sourceforge.czt.z.visitor.ExprVisitorprotected void preservePrecedence(net.sourceforge.czt.base.ast.Term term)
public java.lang.Object visitApplication(Application appl)
visitApplication in interface ApplicationVisitorprotected boolean isInfix(net.sourceforge.czt.z.util.OperatorName opName)
public java.lang.Object visitOperatorApplication(OperatorApplication appl)
visitOperatorApplication in interface OperatorApplicationVisitorpublic java.lang.Object visitProdExpr(net.sourceforge.czt.z.ast.ProdExpr prodExpr)
visitProdExpr in interface net.sourceforge.czt.z.visitor.ProdExprVisitor
protected void addParenAnnIfNecessary(java.lang.Object object,
Precedence parentPrec)
object - the term to which annotations are added, if necesasry.parentPrec - the precedence of the parent.
protected void addParenAnnIfNecessary(net.sourceforge.czt.base.ast.Term term,
Precedence parentPrec)
term - the term to which annotations are added, if necessary.parentPrec - the precedence of the parent.protected void addParenAnn(net.sourceforge.czt.base.ast.Term term)
public Precedence precedence(net.sourceforge.czt.base.ast.Term term)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||