Package sicel.compiler.parser

Examples of sicel.compiler.parser.ASTNode


 
  public static void main( String[] args ) throws IOException
  {
    Parser parser = new ParserImpl();
    parser.setLexer( new LexerImpl() );
    ASTNode rootNode;
    try
    {
      rootNode = parser.parse( new File( "input.txt" ) );
    }
    catch ( SyntaxError e )
    {
      e.printStackTrace();
      return;
    }
   
    rootNode.printTree();
  }
View Full Code Here


 
  @Override
  public final ASTNode parse( File file )
  {
    lexer.initialize( file );
    ASTNode n = new Program();
    while( true )
    {   
      while( consumeIf( T_EOL.class ) );
      if( lexer.peek() == null )
      {
        // 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

 
  private final boolean binding()
  {
    if( ! consumeIf( T_BINDING.class ) ) return false;
    T_BINDING t = (T_BINDING)consumedToken;
    ASTNode n = new Binding( t.text );
    expression();
    n.putChild( consumedNode );
    if( lexer.peek() != null )
    {
      expect( T_EOL.class );
      if( consumeIf( T_BRACE_OPEN.class) )
      {
        while( consumeIf( T_EOL.class ) );
        while( binding() )
        {
          n.putChild( consumedNode );
          while( consumeIf( T_EOL.class ) );
        }
        expect( T_BRACE_CLOSE.class );
      }
    }
View Full Code Here

 
  private final boolean lambda()
  {
    if( ! lookAhead( 1, T_ARROW.class ) ) return false;
    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

 
  private final boolean functionCall()
  {
    if( ! consumeIf( T_WORD.class ) ) return false;
    T_WORD word = (T_WORD)consumedToken;
    ASTNode fc = new FunctionCall( word.text );
   
    if( consumeIf( T_PAREN_OPEN.class ) )
    {
      if( expression() )
      {
        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();
View Full Code Here

 
  private final boolean literalList()
  {
    if( ! consumeIf( T_SQUARE_OPEN.class ) ) return false;

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

TOP

Related Classes of sicel.compiler.parser.ASTNode

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.