Package sicel.compiler.parser.exceptions

Examples of sicel.compiler.parser.exceptions.SyntaxError


  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 );
    }
View Full Code Here


        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 ) )
View Full Code Here

          buffer.append( c );
          return true;
        }
        else
        {
          throw new SyntaxError(
              "Unexpected input: Expected '`', got '" + c + "'",
              fileName, linePos, charPos )
        }
       
      case NUMBER:
       

        if( c == 'L' || c == 'l' || c == 'd' || c == 'D' || c == 'f' || c == 'F' )
        {
          buffer.append( c );
          return true;
        }
        else if( ( ! ( Character.isDigit( c ) || c == '.' || c == 'E' ) ) || eof )
        {
          String res = buffer.toString();
          if( res.matches( "-?[1-9][0-9]*" ) )
          {
            int value = Integer.parseInt( res );
            tokenBuffer.offer( new T_INT_LITERAL( value, linePos, stateStartCharPos ) );
          }
          else if( res.matches( "-?[1-9][0-9]*L" ) )
          {
            long value = Long.parseLong( res );
            tokenBuffer.offer( new T_LONG_LITERAL( value, linePos, stateStartCharPos ) );
          }
          else if( res.matches( "-?([1-9][0-9]*|0)\\.[0-9]*[dD]?" ) ||
               res.matches( "-?[0-9]\\.[0-9]+E[1-9][0-9]*" ) )
          {
            double value = Double.parseDouble( res );
            tokenBuffer.offer( new T_DOUBLE_LITERAL( value, linePos, stateStartCharPos ) );
          }
          else if( res.matches( "-?([1-9][0-9]*|0)\\.[0-9]*[fF]" ) )
          {
            float value = Float.parseFloat( res );
            tokenBuffer.offer( new T_FLOAT_LITERAL( value, linePos, stateStartCharPos ) );
          }
          else
          {
            throw new SyntaxError( "Unrecognized number format: '" + res + "'",
                fileName, linePos, stateStartCharPos );
          }
          buffer.setLength( 0 );
          lexerState = LexerState.INIT;
          charPos--;
          return false;
        }
        else
        {
          buffer.append( c );
          return true;
        }
     
      case OPERATOR:
       
        if( Arrays.binarySearch( opChars, c ) >= 0 )
        {
          buffer.append( c );
          return true;
        }
        else
        {
          tokenBuffer.offer( new T_OPERATOR( buffer.toString(), linePos, stateStartCharPos ) );
          buffer.setLength( 0 );
          lexerState = LexerState.INIT;
          charPos--;
          return false;
        }
       
      case STRING:
       
        if( c == '"' )
        {
          tokenBuffer.offer( new T_STRING_LITERAL( buffer.toString(), linePos, stateStartCharPos ) );
          buffer.setLength( 0 );
          lexerState = LexerState.INIT;
          return true;
        }
        else if( c == '\\' )
        {
          buffer.append( '\\' );
          lexerState = LexerState.STRING_ESCAPE;
          return true;
        }
        else
        {
          buffer.append( c );
          return true;
        }
       
      case STRING_ESCAPE:
       
        buffer.append( c );
        lexerState = LexerState.STRING;
        return true;
       
      case INIT:
       
        if( c == '\n' )
        {
          tokenBuffer.offer( new T_EOL( linePos, charPos ) );
          charPos = 0;
          linePos++;
          return true;
        }
        if( c == '\t' )
        {
          charPos += 3;
          return true;
        }
        if( Character.isWhitespace( c ) ) { lexerState = LexerState.INIT;    return true; }
        if( Arrays.binarySearch( opChars, c ) >= 0 )
        {
          buffer.append( c );
          stateStartCharPos = charPos;
          lexerState = LexerState.OPERATOR;
          return true;
        }
        if( c == '"' ) { stateStartCharPos = charPos; lexerState = LexerState.STRING;            return true; }
        if( c == '`' ) { stateStartCharPos = charPos; lexerState = LexerState.INFIX_WORD;          return true; }
        if( c == '-' ) { stateStartCharPos = charPos; lexerState = LexerState.DASH;              return true; }
        if( c == ',' ) { tokenBuffer.offer( new T_COMMA(     linePos, charPos ) )return true; }
        if( c == '{' ) { tokenBuffer.offer( new T_BRACE_OPENlinePos, charPos ) )return true; }
        if( c == '}' ) { tokenBuffer.offer( new T_BRACE_CLOSElinePos, charPos ) )return true; }
        if( c == '(' ) { tokenBuffer.offer( new T_PAREN_OPENlinePos, charPos ) )return true; }
        if( c == ')' ) { tokenBuffer.offer( new T_PAREN_CLOSElinePos, charPos ) )return true; }
        if( c == '[' ) { tokenBuffer.offer( new T_SQUARE_OPENlinePos, charPos ) )return true; }
        if( c == ']' ) { tokenBuffer.offer( new T_SQUARE_CLOSElinePos, charPos ) )return true; }
        if( c == '.' ) { tokenBuffer.offer( new T_DOT(      linePos, charPos ) )return true; }
        if( Character.isLetter( c ) )
        {
          buffer.append( c );
          stateStartCharPos = charPos;
          lexerState = LexerState.WORD;
          return true;
        }
        if( Character.isDigit( c ) && c != '0' )
        {
          buffer.append( c );
          stateStartCharPos = charPos;
          lexerState = LexerState.NUMBER;
          return true;
        }
       
        throw new SyntaxError( "Unrecognized input '" + c + "'",
            fileName, linePos, charPos );
       
      default:
       
        throw new SyntaxError( "Invalid parser state",
            fileName, linePos, charPos );
       
    }
  }
View Full Code Here

TOP

Related Classes of sicel.compiler.parser.exceptions.SyntaxError

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.