sdr 0.7

net.cscott.sdr.calls.ast
Class AstNode

java.lang.Object
  extended by net.cscott.sdr.calls.ast.AstNode
Direct Known Subclasses:
Comp, Expr, OptCall, ParCall, SeqCall

public abstract class AstNode
extends Object

AstNode is the abstract base class for abstract syntax tree nodes representing parsed call definitions and components.

Author:
C. Scott Ananian

Field Summary
 int type
           
 
Constructor Summary
protected AstNode(int type)
           
protected AstNode(int type, String name)
           
 
Method Summary
abstract
<T> AstNode
accept(TransformVisitor<T> v, T t)
          Visitor pattern implementation for transformations.
abstract
<RESULT,CLOSURE>
RESULT
accept(ValueVisitor<RESULT,CLOSURE> v, CLOSURE cl)
          Visitor pattern implementation for computations.
protected  String argsToString()
           
 String toString()
          Output AST tree in lisp-like notation.
static AstNode valueOf(String s)
          Parse AST tree from string; inverse of toString().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public final int type
Constructor Detail

AstNode

protected AstNode(int type)

AstNode

protected AstNode(int type,
                  String name)
Method Detail

accept

public abstract <T> AstNode accept(TransformVisitor<T> v,
                                   T t)
Visitor pattern implementation for transformations. Each AstNode accepts a TransformVisitor and a value, and returns an instance of its own type (ie, Seq.accept(tv, "A") returns a Seq). The 't' parameter is a closure.

Tests:
Create a no-op transform visitor and apply it:
js> s = AstNode.valueOf("(Seq (Prim -1, 1, none, 1 1/2) (Prim 1, 1, none, 1 1/2))")
(Seq (Prim -1, 1, none, 1 1/2) (Prim 1, 1, none, 1 1/2))
js> s.accept(new net.cscott.sdr.calls.transform.TransformVisitor({}), "A")
(Seq (Prim -1, 1, none, 1 1/2) (Prim 1, 1, none, 1 1/2))

accept

public abstract <RESULT,CLOSURE> RESULT accept(ValueVisitor<RESULT,CLOSURE> v,
                                               CLOSURE cl)
Visitor pattern implementation for computations. Each AstNode accepts a ValueVisitor and a closure, and returns an object of the appropriate result type.


toString

public String toString()
Output AST tree in lisp-like notation.

Overrides:
toString in class Object

argsToString

protected String argsToString()

valueOf

public static AstNode valueOf(String s)
                       throws IllegalArgumentException
Parse AST tree from string; inverse of toString().

Throws:
IllegalArgumentException - if the given string value doesn't parse
See Also:
for examples and doc tests.

sdr 0.7

Copyright © 2006-2009 C. Scott Ananian