|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.czt.print.z.AstToPrintTreeVisitor
public class AstToPrintTreeVisitor
This visitor transforms an AST into a print tree, that is an AST prepared for printing.
In order to print, precedences and associativity of operators needs to be known. This information is provided by an SectInfo object.
Note that fixed precedences and associativities are defined in the Z standard in Table 31; user defined precedences and associativities are obtained from an operator table. This implies that this visitor cannot be used for an arbitrary term, like an expression, without providing the operator table as well.
The recommended way to use this visitor is via the #run(ZSect) or #run(Spec) methods. In this case, the operator table is obtained from the SectInfo object (provided in the constructor of this class) as soon as the name of the current section to be visited becomes available (which happens when visiting a ZSect).
It is also possible to provide an operator table explicitly via
the #run(Term, OpTable) method. This method enables the handling
of arbitrary terms where the name of the section is not apparent.
Note that this explicity provided operator table is discarded when
a ZSect is visited. As soon as a ZSect is visited, the SectInfo
object is consulted to provide an operator table for the given
section and this operator table is used instead of the explicitly
provided one (even if the new one is null).
It is not recommended to call the accept method of a term to use this visitor since it is not guaranteed that the correct operator table is used.
| Nested Class Summary | |
|---|---|
static class |
AstToPrintTreeVisitor.CannotPrintAstException
|
| Field Summary | |
|---|---|
protected WarningManager |
warningManager_
|
| Constructor Summary | |
|---|---|
AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo)
|
|
AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo,
WarningManager wm)
Creates a new ast to print tree visitor. |
|
| Method Summary | |
|---|---|
protected Precedence |
getPrec(net.sourceforge.czt.base.ast.Term term)
|
protected net.sourceforge.czt.z.ast.ZFactory |
getZFactory()
|
protected PrintFactory |
getZPrintFactory()
|
protected PrintParagraph |
handleOldZ(java.util.List<java.lang.Object> anns,
PrintParagraph pp)
|
protected boolean |
isInfix(net.sourceforge.czt.z.util.OperatorName opName)
|
net.sourceforge.czt.base.ast.Term |
run(java.lang.String sectionName)
|
net.sourceforge.czt.base.ast.Term |
run(net.sourceforge.czt.base.ast.Term term,
OpTable opTable)
Visits a term and transforms it into a printable tree. |
net.sourceforge.czt.base.ast.Term |
run(net.sourceforge.czt.base.ast.Term term,
java.lang.String sectionName)
Visits a term and transforms it into a printable tree. |
void |
setOldZ(boolean value)
|
protected net.sourceforge.czt.base.ast.Term |
visit(net.sourceforge.czt.base.ast.Term term)
|
net.sourceforge.czt.base.ast.Term |
visitAndPred(net.sourceforge.czt.z.ast.AndPred andPred)
|
net.sourceforge.czt.base.ast.Term |
visitApplExpr(net.sourceforge.czt.z.ast.ApplExpr applExpr)
Transforms each function application (an application expression with Mixfix set to true) into an
OperatorApplication, and each application (an application
expression with Mixfix set to false) into an
Application. |
net.sourceforge.czt.base.ast.Term |
visitAxPara(net.sourceforge.czt.z.ast.AxPara axPara)
|
net.sourceforge.czt.base.ast.Term |
visitMemPred(net.sourceforge.czt.z.ast.MemPred memPred)
|
net.sourceforge.czt.base.ast.Term |
visitRefExpr(net.sourceforge.czt.z.ast.RefExpr refExpr)
Transforms each generic operator application, that is each reference expression with Mixfix set to true into an
OperatorApplication. |
net.sourceforge.czt.base.ast.Term |
visitTerm(net.sourceforge.czt.base.ast.Term term)
Visits all children of a term. |
net.sourceforge.czt.base.ast.Term |
visitZSect(net.sourceforge.czt.z.ast.ZSect zSect)
Sets up the operator table for this Z section. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final WarningManager warningManager_
| Constructor Detail |
|---|
public AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo)
public AstToPrintTreeVisitor(net.sourceforge.czt.session.SectionInfo sectInfo,
WarningManager wm)
net.sourceforge.czt.parser.util.OpTable.class.
| Method Detail |
|---|
protected net.sourceforge.czt.z.ast.ZFactory getZFactory()
protected PrintFactory getZPrintFactory()
public net.sourceforge.czt.base.ast.Term run(java.lang.String sectionName)
throws net.sourceforge.czt.session.CommandException
net.sourceforge.czt.session.CommandException
public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term,
OpTable opTable)
Visits a term and transforms it into a printable tree. The given operator table is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term.
For instance, the given operator table is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.
public net.sourceforge.czt.base.ast.Term run(net.sourceforge.czt.base.ast.Term term,
java.lang.String sectionName)
throws net.sourceforge.czt.session.CommandException
Visits a term and transforms it into a printable tree. The given section name is used to lookup precedence and associativity of user defined operators, but only if the name of the section is not apparent from the term itself.
For instance, the given section name is used if the given term is an expression, predicate, or paragraph, but not if the given term is a Z section or specification.
net.sourceforge.czt.session.CommandExceptionpublic void setOldZ(boolean value)
public net.sourceforge.czt.base.ast.Term visitTerm(net.sourceforge.czt.base.ast.Term term)
visitTerm in interface net.sourceforge.czt.base.visitor.TermVisitor<net.sourceforge.czt.base.ast.Term>public net.sourceforge.czt.base.ast.Term visitAndPred(net.sourceforge.czt.z.ast.AndPred andPred)
visitAndPred in interface net.sourceforge.czt.z.visitor.AndPredVisitor<net.sourceforge.czt.base.ast.Term>public net.sourceforge.czt.base.ast.Term visitApplExpr(net.sourceforge.czt.z.ast.ApplExpr applExpr)
true) into an
OperatorApplication, and each application (an application
expression with Mixfix set to false) into an
Application.
visitApplExpr in interface net.sourceforge.czt.z.visitor.ApplExprVisitor<net.sourceforge.czt.base.ast.Term>
protected PrintParagraph handleOldZ(java.util.List<java.lang.Object> anns,
PrintParagraph pp)
public net.sourceforge.czt.base.ast.Term visitAxPara(net.sourceforge.czt.z.ast.AxPara axPara)
visitAxPara in interface net.sourceforge.czt.z.visitor.AxParaVisitor<net.sourceforge.czt.base.ast.Term>public net.sourceforge.czt.base.ast.Term visitMemPred(net.sourceforge.czt.z.ast.MemPred memPred)
visitMemPred in interface net.sourceforge.czt.z.visitor.MemPredVisitor<net.sourceforge.czt.base.ast.Term>public net.sourceforge.czt.base.ast.Term visitRefExpr(net.sourceforge.czt.z.ast.RefExpr refExpr)
true into an
OperatorApplication.
visitRefExpr in interface net.sourceforge.czt.z.visitor.RefExprVisitor<net.sourceforge.czt.base.ast.Term>public net.sourceforge.czt.base.ast.Term visitZSect(net.sourceforge.czt.z.ast.ZSect zSect)
visitZSect in interface net.sourceforge.czt.z.visitor.ZSectVisitor<net.sourceforge.czt.base.ast.Term>protected boolean isInfix(net.sourceforge.czt.z.util.OperatorName opName)
protected net.sourceforge.czt.base.ast.Term visit(net.sourceforge.czt.base.ast.Term term)
protected Precedence getPrec(net.sourceforge.czt.base.ast.Term term)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||