Package sicel.compiler.parser

Examples of sicel.compiler.parser.Token


 
  public abstract ASTNode parse( File file );
 
  protected final Token expect( Class<? extends Token> tokenType )
  {
    Token t = lexer.take();
    if( t == null )
    {
      throw new SyntaxError("Unexpected EOF", "", 0, 0);
    }
    if( ! t.getClass().equals( tokenType ) )
    {
      throw new UnexpectedTokenError( t, tokenType );
    }
    return t;
  }
View Full Code Here


    return t;
  }
 
  protected final boolean consumeIf( Class<? extends Token> tokenType )
  {
    Token t = lexer.peek();
    if( t == null ) return false;
    if( t.getClass().equals( tokenType ) )
    {
      consumedToken = lexer.take();
      return true;
    }
    return false;
View Full Code Here

    return false;
  }
 
  protected final boolean lookAhead( int depth, Class<? extends Token> tokenType )
  {
    Token t = lexer.lookAhead( depth );
    if( t == null ) return false;
    return ( t.getClass().equals( tokenType ) );
  }
View Full Code Here

        // no more tokens. EOF
        break;
      }
      if( ! binding() )
      {
        Token t = lexer.take();
        throw new UnexpectedTokenError( t, "binding" );
      }
      n.putChild( consumedNode );
    }
    return n;
View Full Code Here

      Operator op = new Operator( op_token.text );
      op.putChild( lhn ); //left-hand node
     
      if( ! unit() )
      {
        Token t = lexer.take();
        throw new UnexpectedTokenError( t );
      }
     
      op.putChild( consumedNode ); //right-hand node
     
      if( ! binOp( op ) )
      {
        consumedNode = op;
      }
     
      return true;
    }
   
    if( lookAhead( 0, T_INFIX_WORD.class ) )
    {
      T_INFIX_WORD op_token = (T_INFIX_WORD)lexer.take();
      FunctionCall op = new FunctionCall( op_token.text );
      op.putChild( lhn ); //left-hand node
     
      if( ! unit() )
      {
        Token t = lexer.take();
        throw new UnexpectedTokenError( t );
      }
     
      op.putChild( consumedNode ); //right-hand node
     
View Full Code Here

  private final boolean dotCall( ASTNode lhs )
  {
    if( ! consumeIf( T_DOT.class ) ) return false;
    if( ! functionCall() )
    {
      Token t = lexer.take();
      throw new UnexpectedTokenError( t, "function call" );
    }
    consumedNode.putChild( 0, lhs );
    dotCall( consumedNode );
    return true;
View Full Code Here

    T_WORD word = (T_WORD)expect( T_WORD.class );
    ASTNode lambda = new Lambda( word.text );
    lexer.take(); // arrow
    if( ! expression() )
    {
      Token t = lexer.take();
      throw new UnexpectedTokenError( t, "expression" );
    }
    lambda.putChild( consumedNode );
    consumedNode = lambda;
    return true;
View Full Code Here

        fc.putChild( consumedNode );
        while( consumeIf( T_COMMA.class ) )
        {
          if( ! expression() )
          {
            Token t = lexer.take();
            throw new SyntaxError( "Expected expression", "", t.getLine(), t.getColumn() );
          }
          fc.putChild( consumedNode );
        }
      }
      if( ! consumeIf( T_PAREN_CLOSE.class ) )
      {
        Token t = lexer.take();
        throw new UnexpectedTokenError( t, T_PAREN_CLOSE.class );
      }
    }
    consumedNode = fc;
    return true;
View Full Code Here

      n.putChild( consumedNode );
      while( consumeIf( T_COMMA.class ) )
      {
        if( ! expression() )
        {
          Token t = lexer.take();
          throw new UnexpectedTokenError( t, "expression" );
        }
        n.putChild( consumedNode );
      }
    }
View Full Code Here

  {
    Lexer lexer = new LexerImpl();
    lexer.initialize( new File( "input.txt" ) );
    //System.out.println( lexer.lookAhead( 30 ) );
   
    Token t;
    while( ( t = lexer.take() ) != null )
    {
      System.out.println( t );
    }
   
View Full Code Here

TOP

Related Classes of sicel.compiler.parser.Token

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.