Package org.antlr.runtime.tree

Examples of org.antlr.runtime.tree.Tree


    // assert tree.getType() == Bst.COMMANDS;

    // Go
    for (int i = 0; i < tree.getChildCount(); i++) {
      Tree child = tree.getChild(i);
      switch (child.getType()) {
      case BstParser.STRINGS:
        strings(child);
        break;
      case BstParser.INTEGERS:
        integers(child);
View Full Code Here


   * these variables has a value for each entry on the list.
   */
  private void entry(Tree child) {

    { // Fields first
      Tree t = child.getChild(0);
      // assert t.getType() == Bst.IDLIST;

      for (int i = 0; i < t.getChildCount(); i++) {
        String name = t.getChild(i).getText();

        for (BstEntry entry : entries){
          entry.fields.put(name, null);
        }
      }
    }
    { // Integers
      Tree t = child.getChild(1);
      // assert t.getType() == Bst.IDLIST;

      for (int i = 0; i < t.getChildCount(); i++) {
        String name = t.getChild(i).getText();
       
        for (BstEntry entry : entries){
          entry.integers.put(name, new Integer(0));
        }
      }
    }
    { // Strings
      Tree t = child.getChild(2);
      // assert t.getType() == Bst.IDLIST;

      for (int i = 0; i < t.getChildCount(); i++) {
        String name = t.getChild(i).getText();
        for (BstEntry entry : entries){
          entry.strings.put(name, null);
        }
      }
      for (BstEntry entry : entries){
View Full Code Here

    });
  }

  public void executeInContext(Object o, BstEntry context) {
    if (o instanceof Tree) {
      Tree t = (Tree) o;
      new StackFunction(t).execute(context);
    } else if (o instanceof Identifier) {
      execute(((Identifier) o).getName(), context);
    }
  }
View Full Code Here

    throw new VMException("No matching identifier found: " + name);
  }

  private void function(Tree child) {
    String name = child.getChild(0).getText();
    Tree stack = child.getChild(1);
    functions.put(name, new StackFunction(stack));

  }
View Full Code Here

   * declaration must precede its use.
   *
   * @param child
   */
  private void integers(Tree child) {
    Tree t = child.getChild(0);
    // assert t.getType() == Bst.IDLIST;

    for (int i = 0; i < t.getChildCount(); i++) {
      String name = t.getChild(i).getText();
      integers.put(name, new Integer(0));
    }
  }
View Full Code Here

   * declaration must precede its use.
   *
   * @param child
   */
  private void strings(Tree child) {
    Tree t = child.getChild(0);
    // assert t.getType() == Bst.IDLIST;

    for (int i = 0; i < t.getChildCount(); i++) {
      String name = t.getChild(i).getText();
      strings.put(name, null);
    }
  }
View Full Code Here

    public void execute(BstEntry context) {

      for (int i = 0; i < tree.getChildCount(); i++) {

        Tree c = tree.getChild(i);
        try {

          switch (c.getType()) {
          case BstParser.STRING: {
            String s = c.getText();
            push(s.substring(1, s.length() - 1));
          }
            break;
          case BstParser.INTEGER:
            push(new Integer(Integer.parseInt(c.getText().substring(1))));
            break;
          case BstParser.QUOTED:
            push(new Identifier(c.getText().substring(1)));
            break;
          case BstParser.STACK:
            push(c);
            break;
          default:
            VM.this.execute(c.getText(), context);
          }
        } catch (VMException e) {
          if (file != null) {
            System.err.println("ERROR " + e.getMessage() + " (" + file.getPath() + ":"
              + c.getLine() + ")");
          } else {
            System.err.println("ERROR " + e.getMessage() + " (" + c.getLine() + ")");
          }
          throw e;
        }
      }
View Full Code Here

            navBuilder.begin();

            String previousReference = "$1";
            Class activeType = rootType;

            Tree node = tree;

            while (!isLeaf(node))
            {
                GeneratedTerm term = processDerefNode(navBuilder, activeType, node, previousReference, "$1");

                activeType = term.type;

                previousReference = term.termReference;

                // Second term is the continuation, possibly another chained
                // DEREF, etc.
                node = node.getChild(1);
            }

            navBuilder.addln("return %s;", previousReference);

            navBuilder.end();
View Full Code Here

        private GeneratedTerm processDerefNode(BodyBuilder builder, Class activeType, Tree node,
                String previousVariableName, String rootName)
        {
            // The first child is the term.

            Tree term = node.getChild(0);

            boolean allowNull = node.getType() == SAFEDEREF;

            // Returns the type of the method/property ... this is the wrapped
            // (i.e. java.lang.Integer) type if
View Full Code Here

     *            expression to be evaluated
     * @return the conduit
     */
    private PropertyConduit build(final Class rootClass, String expression)
    {
        Tree tree = parse(expression);

        try
        {
            switch (tree.getType())
            {
                case TRUE:

                    return literalTrue;

                case FALSE:

                    return literalFalse;

                case NULL:

                    return literalNull;

                case INTEGER:

                    // Leading '+' may screw this up.
                    // TODO: Singleton instance for "0", maybe "1"?

                    return createLiteralConduit(Long.class, new Long(tree.getText()));

                case DECIMAL:

                    // Leading '+' may screw this up.
                    // TODO: Singleton instance for "0.0"?

                    return createLiteralConduit(Double.class, new Double(tree.getText()));

                case STRING:

                    return createLiteralConduit(String.class, tree.getText());

                case RANGEOP:

                    Tree fromNode = tree.getChild(0);
                    Tree toNode = tree.getChild(1);

                    // If the range is defined as integers (not properties, etc.)
                    // then it is possible to calculate the value here, once, and not
                    // build a new class.

                    if (fromNode.getType() != INTEGER || toNode.getType() != INTEGER)
                        break;

                    int from = Integer.parseInt(fromNode.getText());
                    int to = Integer.parseInt(toNode.getText());

                    IntegerRange ir = new IntegerRange(from, to);

                    return createLiteralConduit(IntegerRange.class, ir);

View Full Code Here

TOP

Related Classes of org.antlr.runtime.tree.Tree

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.