Examples of WeaselToken


Examples of weasel.compiler.WeaselToken

    return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(compiler.baseTypes.voidClass));
  }

  private WeaselInstructionList compileBlock(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException{
    compilerHelpher.openBlock(false);
    WeaselToken token = iterator.next();
    WeaselInstructionList instructions;
    if(token.tokenType==WeaselTokenType.OPENBLOCK){
      instructions = new WeaselInstructionList();
      token = iterator.next();
      while(token.tokenType!=WeaselTokenType.CLOSEBLOCK){
View Full Code Here

Examples of weasel.compiler.WeaselToken

    }
  }
 
  private List<WeaselToken> readModifier(){
    List<WeaselToken> modifiers = new ArrayList<WeaselToken>();
    WeaselToken token = getNextToken();
    while(token.tokenType==WeaselTokenType.MODIFIER){
      modifiers.add(token);
      token = getNextToken();
    }
    setNextToken(token);
View Full Code Here

Examples of weasel.compiler.WeaselToken

      for(int i=0; i<fields.length; i++){
        newFields[i] = fields[i];
      }
      newFields[fields.length] = field;
      fields = newFields;
      WeaselToken nameToken = token;
      classStaticInit.add(nameToken);
      classStaticInit.add(new WeaselToken(WeaselTokenType.OPERATOR, nameToken.line, WeaselOperator.ASSIGN));
      classStaticInit.add(new WeaselToken(WeaselTokenType.KEYWORD, nameToken.line, WeaselKeyWord.NEW));
      classStaticInit.add(new WeaselToken(WeaselTokenType.IDENT, nameToken.line, name));
      token = getNextToken();
      if(token.tokenType==WeaselTokenType.OPENBRACKET){
        int count = 0;
        classStaticInit.add(token);
        token = getNextToken();
        while(token.tokenType!=WeaselTokenType.NONE){
          classStaticInit.add(token);
          if(token.tokenType==WeaselTokenType.OPENBRACKET)
            count++;
          else if(token.tokenType==WeaselTokenType.CLOSEBRACKET){
            if(count<=0)
              break;
            count--;
          }
          token = getNextToken();
        }
        token = getNextToken();
        classStaticInit.add(new WeaselToken(WeaselTokenType.SEMICOLON, token.line));
      }else{
        classStaticInit.add(new WeaselToken(WeaselTokenType.OPENBRACKET, nameToken.line));
        classStaticInit.add(new WeaselToken(WeaselTokenType.CLOSEBRACKET, nameToken.line));
        classStaticInit.add(new WeaselToken(WeaselTokenType.SEMICOLON, nameToken.line));
      }
      if(token.tokenType!=WeaselTokenType.COMMA)
        break;
      token = getNextToken();
    }
    WeaselField field = createField("values", WeaselModifier.FINAL | WeaselModifier.STATIC | WeaselModifier.PRIVATE, this, new WeaselGenericClassInfo(interpreter.getWeaselClass("["+getByteName()), -1, new WeaselGenericClassInfo[0]), ids.staticObjectRef++);
    WeaselField[] newFields = new WeaselField[fields.length+1];
    for(int i=0; i<fields.length; i++){
      newFields[i] = fields[i];
    }
    newFields[fields.length] = field;
    fields = newFields;
    classStaticInit.add(new WeaselToken(WeaselTokenType.IDENT, 0, "values"));
    classStaticInit.add(new WeaselToken(WeaselTokenType.OPERATOR, 0, WeaselOperator.ASSIGN));
    classStaticInit.add(new WeaselToken(WeaselTokenType.KEYWORD, 0, WeaselKeyWord.NEW));
    classStaticInit.add(new WeaselToken(WeaselTokenType.IDENT, 0, name));
    classStaticInit.add(new WeaselToken(WeaselTokenType.OPENINDEX, 0));
    classStaticInit.add(new WeaselToken(WeaselTokenType.CLOSEINDEX, 0));
    classStaticInit.add(new WeaselToken(WeaselTokenType.OPENBLOCK, 0));
    classStaticInit.add(new WeaselToken(WeaselTokenType.IDENT, 0, constants.get(0)));
    for(int i=1; i<constants.size(); i++){
      classStaticInit.add(new WeaselToken(WeaselTokenType.COMMA, 0));
      classStaticInit.add(new WeaselToken(WeaselTokenType.IDENT, 0, constants.get(i)));
    }
    classStaticInit.add(new WeaselToken(WeaselTokenType.CLOSEBLOCK, 0));
    classStaticInit.add(new WeaselToken(WeaselTokenType.SEMICOLON, 0));
    WeaselCompiler.expect(token, WeaselTokenType.SEMICOLON, WeaselTokenType.CLOSEBLOCK);
    token = getNextToken();
    return token;
  }
View Full Code Here

Examples of weasel.compiler.WeaselToken

 
  @Override
  public void compileEasy() {
    compiler.addWeaselCompilerMessage(new WeaselCompilerMessage(MessageType.INFO, 0, getFileName(), "Compiling Class"));
    List<WeaselToken> modifiers = readModifier();
    WeaselToken token = getNextToken();
    try{
      WeaselCompiler.expectKeyWord(token, WeaselKeyWord.CLASS, WeaselKeyWord.INTERFACE, WeaselKeyWord.ENUM);
    }catch(WeaselCompilerException e){
      onException(e);
    }
    boolean isEnum = token.param == WeaselKeyWord.ENUM;
    isInterface = token.param == WeaselKeyWord.INTERFACE;
    boolean isClass = !(isEnum||isInterface);
    modifier = getModifier(modifiers, isEnum?enumModifier:isInterface?interfaceModifier:classModifier);
    modifiers = null;
    if(isInterface)
      modifier |= WeaselModifier.ABSTRACT;
    if(isEnum)
      modifier |= WeaselModifier.FINAL;
    token = getNextToken();
    try{
      WeaselCompiler.expect(token, WeaselTokenType.IDENT);
      if(!name.equals(token.param)){
        onException(token.line, "ClassFile name %s and classname %s is not epual", name, token.param);
      }
    }catch(WeaselCompilerException e){
      onException(e);
    }
    token = getNextToken();
    if(isEnum){
      genericInformation = new WeaselGenericInformation[0];
    }else{
      try{
        genericInformation = makeGenericInformations(token);
      }catch(WeaselCompilerException e){
        onException(e);
      }
      token = getNextToken();
    }
    genericInterfaces = new WeaselGenericClassInfo[0];
    try{
      if(isClass){
        token = readClassHead(token);
      }
      if(isInterface){
        token = readInterfaceHead(token);
      }
      if(isEnum){
        token = readEnumHead(token);
      }
      WeaselCompiler.expect(token, WeaselTokenType.OPENBLOCK);
    }catch(WeaselCompilerException e){
      onException(e);
      while(getNextToken().tokenType!=WeaselTokenType.OPENBLOCK);
    }
   
    token = getNextToken();
   
    ids.staticMethod++;
   
    methods = new WeaselMethod[isInterface()?1:2];
    staticMethodBodys = new WeaselMethodBody[ids.staticMethod];
    if(!isInterface())
      methodBodys = new WeaselMethodBody[ids.method];
    fields = new WeaselField[0];
   
    methods[0] = createMethod("<staticInit>", WeaselModifier.STATIC, this, new WeaselGenericClassInfo(interpreter.baseTypes.voidClass, -1, new WeaselGenericClassInfo[0]), new WeaselGenericClassInfo[0], new WeaselGenericInformation[0], ids.staticMethod-1);
    staticMethodBodys[ids.staticMethod-1] = new WeaselMethodBodyCompilerV2(methods[0], this, classStaticInit, new ArrayList<String>(), new ArrayList<Integer>(), compiler);
    if(!isInterface()){
      methods[1] = createMethod("<preInit>", 0, this, new WeaselGenericClassInfo(interpreter.baseTypes.voidClass, -1, new WeaselGenericClassInfo[0]), new WeaselGenericClassInfo[0], new WeaselGenericInformation[0], 0);
      methodBodys[0] = new WeaselMethodBodyCompilerV2(methods[1], this, classPreInit, new ArrayList<String>(), new ArrayList<Integer>(), compiler);
    }
   
    if(isEnum){
      try {
        token = readEnumConstants(token);
      } catch (WeaselCompilerException e) {
        onException(e);
        while(getNextToken().tokenType!=WeaselTokenType.SEMICOLON);
      }
    }
   
    while(token.tokenType!=WeaselTokenType.CLOSEBLOCK&&token.tokenType!=WeaselTokenType.NONE){
      try{
        setNextToken(token);
        modifiers = readModifier();
        token = getNextToken();
       
        //WeaselGenericInformation[] genericInformations = makeGenericInformations(token);
        //token = getNextToken();
        String name;
        boolean isConstructor=token.tokenType == WeaselTokenType.IDENT && token.param.equals(this.name);
        if(isConstructor){
          WeaselToken token2 = getNextToken();
          if(token2.tokenType!=WeaselTokenType.OPENBRACKET){
            isConstructor = false;
          }
          setNextToken(token2);
        }
View Full Code Here

Examples of weasel.compiler.WeaselToken

  }
 
  private void arrayMaker(List<WeaselToken> tl, WeaselClass typeC, int line){
    if(typeC.isArray()){
      arrayMaker(tl, typeC.getArrayClass(), line);
      tl.add(new WeaselToken(WeaselTokenType.OPENINDEX, line));
      tl.add(new WeaselToken(WeaselTokenType.CLOSEINDEX, line));
    }else{
      tl.add(new WeaselToken(WeaselTokenType.IDENT, line, typeC.getRealName()));
    }
  }
View Full Code Here

Examples of weasel.compiler.WeaselToken

      tl.add(new WeaselToken(WeaselTokenType.IDENT, line, typeC.getRealName()));
    }
  }
 
  private WeaselToken compileField2(int modifier, WeaselGenericClassInfo typeInfo, String name, WeaselToken token) throws WeaselCompilerException{
    WeaselToken nameToken = token;
    if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.ASSIGN){
      List<WeaselToken> init;
      if(WeaselModifier.isStatic(modifier)){
        init = classStaticInit;
      }else{
        init = classPreInit;
        if(isInterface()){
          onException(token.line, "Interface field %s cant be set here", name);
        }
      }
      init.add(new WeaselToken(WeaselTokenType.IDENT, token.line, name));
      init.add(token);
      token = getNextToken();
      if(token.tokenType==WeaselTokenType.OPENBLOCK){
        init.add(new WeaselToken(WeaselTokenType.KEYWORD, token.line, WeaselKeyWord.NEW));
        arrayMaker(init, typeInfo.genericClass, token.line);
      }
      int h=0;
      while(token.tokenType!=WeaselTokenType.SEMICOLON&&(h>0 || token.tokenType!=WeaselTokenType.COMMA)){
        if(token.tokenType==WeaselTokenType.OPENBLOCK||token.tokenType==WeaselTokenType.OPENINDEX||token.tokenType==WeaselTokenType.OPENBRACKET)
          h++;
        if(token.tokenType==WeaselTokenType.CLOSEBLOCK||token.tokenType==WeaselTokenType.CLOSEINDEX||token.tokenType==WeaselTokenType.CLOSEBRACKET)
          if(h>0)
            h--;
        init.add(token);
        token = getNextToken();
        if(token.tokenType==WeaselTokenType.NONE){
          WeaselCompiler.expect(token, WeaselTokenType.SEMICOLON);
          break;
        }
      }
      init.add(new WeaselToken(WeaselTokenType.SEMICOLON, token.line));
    }
    WeaselField field = null;
    try{
      field = getField(name);
    }catch(WeaselNativeException e){}
View Full Code Here

Examples of weasel.compiler.WeaselToken

    fields = newFields;
    return token;
  }
 
  private void compileMethod(List<WeaselToken> modifiers, WeaselGenericClassInfo typeInfo, String name, WeaselToken token, WeaselGenericInformation[] genericInformations) throws WeaselCompilerException{
    WeaselToken tokenName = token;
    boolean isConstructor = name.equals("<init>");
    boolean isPreConstructor = name.equals("<preInit>");
    boolean isStaticConstructor = name.equals("<staticInit>");
    int modifier = getModifier(modifiers, isStaticConstructor||isPreConstructor?0:isConstructor?isEnum()?0:
      WeaselMethod.constructorModifier:WeaselModifier.isAbstract(getModifier())?WeaselMethod.abstractModifier:WeaselMethod.normalModifier);
View Full Code Here

Examples of weasel.compiler.WeaselToken

      }while(token.tokenType == WeaselTokenType.COMMA);
      if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.GREATER)){
        if(!(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.RSHIFT)){
          onException(token.line, "WeaselCompiler.expect > at end of generic");
        }else{
          token = new WeaselToken(WeaselTokenType.OPERATOR, token.line, WeaselOperator.GREATER);
        }
      }else{
        token = iterator.next();
      }
    }
View Full Code Here

Examples of weasel.compiler.WeaselToken

  private WeaselCompilerReturn compileOperator(WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelper, WeaselGenericClass write, WeaselGenericClass expect,
    WeaselGenericClass elementParent, boolean isVariable, int i) throws WeaselCompilerException {
    if(i==-1 || i==operators.size())
      return level.get(0).compile(compiler, compilerHelper, null, expect, elementParent, isVariable);
    WeaselToken operator = operators.get(i);
    Properties oper = (Properties)operator.param;
    WeaselInstructionList instructions;
    WeaselCompilerReturn wcr;
    WeaselGenericClass ret;
    if(oper==WeaselOperator.INSTANCEOF){
View Full Code Here

Examples of weasel.compiler.WeaselToken

      WeaselGenericClass elementParent, boolean isVariable, int i) throws WeaselCompilerException {
    if(i==-1)
      return level.get(0).compile(compiler, compilerHelper, write, expect, elementParent, isVariable);
    if(i==operators.size())
      return level.get(operators.size()).compile(compiler, compilerHelper, write, expect, elementParent, isVariable);
    WeaselToken operator = operators.get(i);
    Properties oper = (Properties)operator.param;
    WeaselInstructionList instructions = new WeaselInstructionList();
    WeaselCompilerReturn wcr;
    WeaselGenericClass ret;
    WeaselGenericClass wgc;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.