Package org.jostraca.comp.antlr.collections

Examples of org.jostraca.comp.antlr.collections.AST


        return getText();
    }

    /** Print out a child-sibling tree in LISP notation */
    public String toStringList() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        if (t.getNextSibling() != null) {
            ts += ((BaseAST)t.getNextSibling()).toStringList();
        }
        return ts;
    }
View Full Code Here


        }
        return ts;
    }

    public String toStringTree() {
        AST t = this;
        String ts = "";
        if (t.getFirstChild() != null) ts += " (";
        ts += " " + this.toString();
        if (t.getFirstChild() != null) {
            ts += ((BaseAST)t.getFirstChild()).toStringList();
        }
        if (t.getFirstChild() != null) ts += " )";
        return ts;
    }
View Full Code Here

    if ( step<=0 ) {
      buf.append(' ');
      buf.append(toString());
      return numReplacements;
    }
    AST child = getFirstChild();
    numReplacements = 1;
    // walk child printing them out, descending into at most one
    while ( child!=null ) {
      if ( numReplacements>=step || child instanceof ParseTreeToken ) {
        buf.append(' ');
        buf.append(child.toString());
      }
      else {
        // descend for at least one more derivation; update count
        int remainingReplacements = step-numReplacements;
        int n = ((ParseTree)child).getLeftmostDerivation(buf,
                                 remainingReplacements);
        numReplacements += n;
      }
      child = child.getNextSibling();
    }
    return numReplacements;
  }
View Full Code Here

    }

    public void visit(AST node) {
        // Flatten this level of the tree if it has no children
        boolean flatten = /*true*/ false;
        AST node2;
        for (node2 = node; node2 != null; node2 = node2.getNextSibling()) {
            if (node2.getFirstChild() != null) {
                flatten = false;
                break;
            }
        }

        for (node2 = node; node2 != null; node2 = node2.getNextSibling()) {
            if (!flatten || node2 == node) {
                tabs();
            }
            if (node2.getText() == null) {
                System.out.print("nil");
            }
            else {
                System.out.print(node2.getText());
            }

            System.out.print(" [" + node2.getType() + "] ");

            if (flatten) {
                System.out.print(" ");
            }
            else {
                System.out.println("");
            }

            if (node2.getFirstChild() != null) {
                level++;
                visit(node2.getFirstChild());
                level--;
            }
        }

        if (flatten) {
View Full Code Here

}

  public final boolean  expr(AST _t) throws RecognitionException {
    boolean r;
   
    AST expr_AST_in = (_t == ASTNULL) ? null : (AST)_t;
   
      boolean a,b;
      r = false;
   
   
    try {      // for error handling
      if (_t==null) _t=ASTNULL;
      switch ( _t.getType()) {
      case XOR:
      {
        AST __t31 = _t;
        AST tmp1_AST_in = (AST)_t;
        match(_t,XOR);
        _t = _t.getFirstChild();
        a=expr(_t);
        _t = _retTree;
        b=expr(_t);
        _t = _retTree;
        _t = __t31;
        _t = _t.getNextSibling();
        r = !(a && b) && (a || b);
        break;
      }
      case OR:
      {
        AST __t32 = _t;
        AST tmp2_AST_in = (AST)_t;
        match(_t,OR);
        _t = _t.getFirstChild();
        a=expr(_t);
        _t = _retTree;
        b=expr(_t);
        _t = _retTree;
        _t = __t32;
        _t = _t.getNextSibling();
        r = a || b;
        break;
      }
      case AND:
      {
        AST __t33 = _t;
        AST tmp3_AST_in = (AST)_t;
        match(_t,AND);
        _t = _t.getFirstChild();
        a=expr(_t);
        _t = _retTree;
        b=expr(_t);
        _t = _retTree;
        _t = __t33;
        _t = _t.getNextSibling();
        r = a && b;
        break;
      }
      case NOT:
      {
        AST __t34 = _t;
        AST tmp4_AST_in = (AST)_t;
        match(_t,NOT);
        _t = _t.getFirstChild();
        a=expr(_t);
        _t = _retTree;
        _t = __t34;
        _t = _t.getNextSibling();
        r = !a;
        break;
      }
      case TRUE:
      {
        AST tmp5_AST_in = (AST)_t;
        match(_t,TRUE);
        _t = _t.getNextSibling();
        r = true;
        break;
      }
      case FALSE:
      {
        AST tmp6_AST_in = (AST)_t;
        match(_t,FALSE);
        _t = _t.getNextSibling();
        r = false;
        break;
      }
View Full Code Here

  public final void expr() throws RecognitionException, TokenStreamException {
   
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST expr_AST = null;
   
    try {      // for error handling
      xorexpr();
      astFactory.addASTChild(currentAST, returnAST);
      expr_AST = (AST)currentAST.root;
View Full Code Here

 
  public final void xorexpr() throws RecognitionException, TokenStreamException {
   
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST xorexpr_AST = null;
   
    try {      // for error handling
      orexpr();
      astFactory.addASTChild(currentAST, returnAST);
      {
      _loop21:
      do {
        if ((LA(1)==XOR)) {
          AST tmp7_AST = null;
          tmp7_AST = astFactory.create(LT(1));
          astFactory.makeASTRoot(currentAST, tmp7_AST);
          match(XOR);
          orexpr();
          astFactory.addASTChild(currentAST, returnAST);
View Full Code Here

 
  public final void orexpr() throws RecognitionException, TokenStreamException {
   
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST orexpr_AST = null;
   
    try {      // for error handling
      andexpr();
      astFactory.addASTChild(currentAST, returnAST);
      {
      _loop24:
      do {
        if ((LA(1)==OR)) {
          AST tmp8_AST = null;
          tmp8_AST = astFactory.create(LT(1));
          astFactory.makeASTRoot(currentAST, tmp8_AST);
          match(OR);
          andexpr();
          astFactory.addASTChild(currentAST, returnAST);
View Full Code Here

 
  public final void andexpr() throws RecognitionException, TokenStreamException {
   
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST andexpr_AST = null;
   
    try {      // for error handling
      nexpr();
      astFactory.addASTChild(currentAST, returnAST);
      {
      _loop27:
      do {
        if ((LA(1)==AND)) {
          AST tmp9_AST = null;
          tmp9_AST = astFactory.create(LT(1));
          astFactory.makeASTRoot(currentAST, tmp9_AST);
          match(AND);
          nexpr();
          astFactory.addASTChild(currentAST, returnAST);
View Full Code Here

 
  public final void nexpr() throws RecognitionException, TokenStreamException {
   
    returnAST = null;
    ASTPair currentAST = new ASTPair();
    AST nexpr_AST = null;
   
    try {      // for error handling
      switch ( LA(1)) {
      case NOT:
      {
        AST tmp10_AST = null;
        tmp10_AST = astFactory.create(LT(1));
        astFactory.makeASTRoot(currentAST, tmp10_AST);
        match(NOT);
        pexpr();
        astFactory.addASTChild(currentAST, returnAST);
View Full Code Here

TOP

Related Classes of org.jostraca.comp.antlr.collections.AST

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.