Examples of TerminalNode


Examples of org.antlr.v4.runtime.tree.TerminalNode

            listener.visitErrorNode(node);
          }
        }
      }
      else {
        TerminalNode node = _ctx.addChild(o);
        if (_parseListeners != null) {
          for (ParseTreeListener listener : _parseListeners) {
            listener.visitTerminal(node);
          }
        }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

      if ( t instanceof RuleContext) {
        RuleContext r = (RuleContext)t;
        nodes.add(parser.getRuleNames()[r.getRuleIndex()]);
      }
      else {
        TerminalNode token = (TerminalNode)t;
        nodes.add(token.getText());
      }
    }
    return nodes;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

    }

    int j = -1; // what token with ttype have we found?
    for (ParseTree o : children) {
      if ( o instanceof TerminalNode ) {
        TerminalNode tnode = (TerminalNode)o;
        Token symbol = tnode.getSymbol();
        if ( symbol.getType()==ttype ) {
          j++;
          if ( j == i ) {
            return tnode;
          }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

    }

    List<TerminalNode> tokens = null;
    for (ParseTree o : children) {
      if ( o instanceof TerminalNode ) {
        TerminalNode tnode = (TerminalNode)o;
        Token symbol = tnode.getSymbol();
        if ( symbol.getType()==ttype ) {
          if ( tokens==null ) {
            tokens = new ArrayList<TerminalNode>();
          }
          tokens.add(tnode);
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

      throw new IllegalArgumentException("patternTree cannot be null");
    }

    // x and <ID>, x and y, or x and x; or could be mismatched types
    if ( tree instanceof TerminalNode && patternTree instanceof TerminalNode ) {
      TerminalNode t1 = (TerminalNode)tree;
      TerminalNode t2 = (TerminalNode)patternTree;
      ParseTree mismatchedNode = null;
      // both are tokens and they have same type
      if ( t1.getSymbol().getType() == t2.getSymbol().getType() ) {
        if ( t2.getSymbol() instanceof TokenTagToken ) { // x and <ID>
          TokenTagToken tokenTagToken = (TokenTagToken)t2.getSymbol();
          // track label->list-of-nodes for both token name and label (if any)
          labels.map(tokenTagToken.getTokenName(), tree);
          if ( tokenTagToken.getLabel()!=null ) {
            labels.map(tokenTagToken.getLabel(), tree);
          }
        }
        else if ( t1.getText().equals(t2.getText()) ) {
          // x and x
        }
        else {
          // x and y
          if (mismatchedNode == null) {
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

  /** Is {@code t} {@code (expr <expr>)} subtree? */
  protected RuleTagToken getRuleTagToken(ParseTree t) {
    if ( t instanceof RuleNode ) {
      RuleNode r = (RuleNode)t;
      if ( r.getChildCount()==1 && r.getChild(0) instanceof TerminalNode ) {
        TerminalNode c = (TerminalNode)r.getChild(0);
        if ( c.getSymbol() instanceof RuleTagToken ) {
//          System.out.println("rule tag subtree "+t.toStringTree(parser));
          return (RuleTagToken)c.getSymbol();
        }
      }
    }
    return null;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

  public Collection<ParseTree> evaluate(ParseTree t) {
    // return all children of t that match nodeName
    List<ParseTree> nodes = new ArrayList<ParseTree>();
    for (Tree c : Trees.getChildren(t)) {
      if ( c instanceof TerminalNode ) {
        TerminalNode tnode = (TerminalNode)c;
        if ( (tnode.getSymbol().getType() == tokenType && !invert) ||
           (tnode.getSymbol().getType() != tokenType && invert) )
        {
          nodes.add(tnode);
        }
      }
    }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

    return visitChildren(ctx);
  }

  @Override
  public BinaryOperator visitComparison_predicate(SQLParser.Comparison_predicateContext ctx) {
    TerminalNode operator = (TerminalNode) ctx.comp_op().getChild(0);
    return new BinaryOperator(tokenToExprType(operator.getSymbol().getType()),
        visitNumeric_value_expression(ctx.left),
        visitNumeric_value_expression(ctx.right));
  }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

    Expr left;
    Expr right;
    for (int i = 1; i < ctx.getChildCount(); i++) {
      left = current;
      TerminalNode operator = (TerminalNode) ctx.getChild(i++);
      right = visitTerm((TermContext) ctx.getChild(i));

      if (operator.getSymbol().getType() == PLUS) {
        current = new BinaryOperator(OpType.Plus, left, right);
      } else {
        current = new BinaryOperator(OpType.Minus, left, right);
      }
    }
View Full Code Here

Examples of org.antlr.v4.runtime.tree.TerminalNode

    Expr left;
    Expr right;
    for (int i = 1; i < ctx.getChildCount(); i++) {
      left = current;
      TerminalNode operator = (TerminalNode) ctx.getChild(i++);
      right = visitNumeric_primary((Numeric_primaryContext) ctx.getChild(i));

      if (operator.getSymbol().getType() == MULTIPLY) {
        current = new BinaryOperator(OpType.Multiply, left, right);
      } else if (operator.getSymbol().getType() == DIVIDE) {
        current = new BinaryOperator(OpType.Divide, left, right);
      } else {
        current = new BinaryOperator(OpType.Modular, left, right);
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.