Package weasel.compiler

Examples of weasel.compiler.WeaselToken


  private List<WeaselTreeGenericElement> list = new ArrayList<WeaselTreeGenericElement>();
  public boolean close;
 
  public WeaselTreeGeneric(ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    WeaselToken token = iterator.next();
    if(!(token.tokenType==WeaselTokenType.OPERATOR && (token.param==WeaselOperator.GREATER || token.param==WeaselOperator.RSHIFT))){
      iterator.previous();
      do{
        WeaselTreeGenericElement tge = new WeaselTreeGenericElement(iterator);
        list.add(tge);
View Full Code Here


  public abstract String toString();
 
  public static WeaselInstructionList parseAndCompile(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
   
    WeaselToken token = iterator.next();
    if(token.tokenType==WeaselTokenType.KEYWORD && ((WeaselKeyWord)token.param).compiler!=null){
      WeaselCompilerReturn wcr = ((WeaselKeyWord)token.param).compiler.compile(token, compiler, compilerHelper, iterator);
      return wcr.getInstructions(compiler, compiler.baseTypes.voidClass);
    }
    if(token.tokenType==WeaselTokenType.MODIFIER){
View Full Code Here

    return null;
  }

  public static WeaselInstructionList parseAndCompileWhithVarDec(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
   
    WeaselToken token = iterator.next();
    if(token.tokenType==WeaselTokenType.KEYWORD && ((WeaselKeyWord)token.param).compiler!=null){
      throw new WeaselCompilerException(token.line, "Unexpect keyword %s", token);
    }
    if(token.tokenType==WeaselTokenType.MODIFIER){
      return compileVarDec(token, compiler, compilerHelper, iterator);
View Full Code Here

    WeaselCompiler.expect(iterator.next(), WeaselTokenType.SEMICOLON);
    return instructions;
  }
 
  private static WeaselInstructionList compileVar(int modifier, WeaselGenericClass wgc, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, ListIterator<WeaselToken> iterator) throws WeaselCompilerException{
    WeaselToken token = iterator.next();
    WeaselCompiler.expect(token, WeaselTokenType.IDENT);
    String varName = (String)token.param;
    token = iterator.next();
    String className = wgc.getBaseClass().getByteName();
    while(token.tokenType==WeaselTokenType.OPENINDEX){
View Full Code Here

   
    WeaselTreeGeneric generic = null;
   
    while(iterator.hasNext()){
     
      WeaselToken token = iterator.next();
     
      if(Arrays.asList(end).contains(token.tokenType)){
       
        if(generic!=null)
          throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
       
        while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
          tokenSuffix.add(tokenCache.remove(0));
        }
       
        if(tokenCache.size()!=0){
          throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
        }
       
        if(!tokenSuffix.isEmpty()){
          WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
          bottom = wtar.newTree;
        }
       
        tokenPrefix.clear();
        tokenSuffix.clear();
        tokenCache.clear();
       
        break;
       
      }else{
     
        if(token.tokenType==WeaselTokenType.KEYWORD && token.param==WeaselKeyWord.INSTANCEOF){
          WeaselToken t = iterator.next();
          WeaselCompiler.expect(t, WeaselTokenType.IDENT);
          String className = (String)t.param;
          t = iterator.next();
          while(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.ELEMENT){
            t = iterator.next();
            WeaselCompiler.expect(t, WeaselTokenType.IDENT);
            className += "."+(String)t.param;
            t = iterator.next();
          }
          if(t.tokenType==WeaselTokenType.OPERATOR && t.param==WeaselOperator.LESS){
            generic = new WeaselTreeGeneric(iterator);
            if(generic.close)
              throw new WeaselCompilerException(t.line, "To many >");
          }else{
            iterator.previous();
          }
          token = new WeaselInstanceofToken(token.line, className, generic);
          generic = null;
        }
       
        if(token.tokenType==WeaselTokenType.COMMA){
          token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.COMMA);
        }
       
        if(token.tokenType==WeaselTokenType.QUESTIONMARK){
         
          if(generic!=null)
            throw new WeaselCompilerException(token.line, "Expect Ident but got ?:");
         
          while(!tokenCache.isEmpty() && ((Properties)tokenCache.get(0).param).suffix!=null){
            tokenSuffix.add(tokenCache.remove(0));
          }
         
          if(tokenCache.size()!=0){
            throw new WeaselCompilerException(token.line, "Expect suffix but got %s", tokenCache.get(0));
          }
         
          if(!tokenSuffix.isEmpty()){
            WeaselTreeAddResult wtar = bottom.add(tokenSuffix, null, null, null, iterator);
            bottom = wtar.newTree;
          }
         
          WeaselTree tree = parse(iterator, WeaselTokenType.COLON);
         
          WeaselTreeCondition wtc = new WeaselTreeCondition(tree, token);
         
          WeaselTreeAddResult wtar = wtc.setLeft(bottom);
         
          bottom = wtar.newTree;
         
          start = true;
         
        }else if(token.tokenType == WeaselTokenType.OPERATOR){
         
          if(generic!=null)
            throw new WeaselCompilerException(token.line, "Expect Ident but got %s", token);
         
          tokenCache.add(token);
       
          if(token.param == WeaselOperator.ELEMENT){
            WeaselToken wtoken = iterator.next();
            if(wtoken.tokenType == WeaselTokenType.OPERATOR && wtoken.param ==WeaselOperator.LESS) {
              generic = new WeaselTreeGeneric(iterator);
              token = iterator.previous();
              if(generic.close){
                throw new WeaselCompilerException(token.line, "Expect Ident but got >");
              }
            }else{
              iterator.previous();
            }
          }
         
        }else{
         
          if(generic!=null && token.tokenType != WeaselTokenType.IDENT)
            throw new WeaselCompilerException(token.line, "Expect ident after generic but got %s", token);
         
          boolean isCast = false;
         
          if(token.tokenType==WeaselTokenType.OPENBRACKET){
            WeaselToken token2 = iterator.next();
            String className = "";
            if(token2.tokenType==WeaselTokenType.IDENT){
              isCast = true;
              className = (String)token2.param;
              token2 = iterator.next();
View Full Code Here

public abstract class WeaselKeyWordCompiler {
 
  public abstract List<WeaselInstruction> compile(WeaselToken token, WeaselCompiler compiler, boolean isFirst) throws WeaselCompilerException;

  protected WeaselToken expect(WeaselCompiler compiler, WeaselTokenType tt) throws WeaselCompilerException{
    WeaselToken token = null;//compiler.getNextToken();
    if(token.tokenType!=tt){
      throw new WeaselSyntaxError(token.line, "Expect %s but got %s", tt, token);
    }
    return token;
  }
View Full Code Here

TOP

Related Classes of weasel.compiler.WeaselToken

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.