Package weasel.compiler.v2.tokentree

Examples of weasel.compiler.v2.tokentree.WeaselTreeCondition


              if(token.param==WeaselKeyWord.THIS){
                superCaller = false;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
                if(token.tokenType!=WeaselTokenType.SEMICOLON)
                  throw new WeaselCompilerException(token.line, "Expect ; but got %s", token);
              }else if(token.param==WeaselKeyWord.SUPER){
                superCaller = true;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericSuperClass().getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
                if(token.tokenType!=WeaselTokenType.SEMICOLON)
                  throw new WeaselCompilerException(token.line, "Expect ; but got %s", token);
View Full Code Here


  @Override
  public WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    expect(iterator.next(), WeaselTokenType.OPENBRACKET);
    compilerHelpher.openBlock(true);
    WeaselInstructionList instructions = WeaselTree.parseAndCompileWhithVarDec(compiler, compilerHelpher, iterator);
    WeaselTree tree2 = WeaselTree.parse(iterator, WeaselTokenType.SEMICOLON);
    if(tree2==null){
      throw new WeaselCompilerException(token.line, "Expect boolean value in secound part of for");
    }
    WeaselTree tree3 = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
   
    WeaselToken t = iterator.next();
    WeaselCompilerReturn wcr;
    if(instructions == null){
      instructions = new WeaselInstructionList();
      instructions.add(token.line, new WeaselInstructionJumperDummy());
    }
    WeaselInstruction startJump = instructions.getLast();
    wcr = tree2.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionIf ifI;
    instructions.add(token.line, ifI = new WeaselInstructionIf());
    if(t.tokenType==WeaselTokenType.OPENBLOCK){
      t = iterator.next();
      while(t.tokenType!=WeaselTokenType.CLOSEBLOCK){
        iterator.previous();
        instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
        t = iterator.next();
      }
    }else{
      iterator.previous();
      instructions.addAll(WeaselTree.parseAndCompile(compiler, compilerHelpher, iterator));
    }
    WeaselInstruction continueJump = instructions.getLast();
    if(tree3!=null){
      wcr = tree3.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.voidClass), null, false);
      instructions = wcr.getInstructions();
      if(wcr.getReturnType().getBaseClass()!=compiler.baseTypes.voidClass)
        instructions.add(t.line, new WeaselInstructionPop());
    }
    WeaselInstruction ifJump = new WeaselInstructionJump(startJump);
View Full Code Here

    if(retClass.getBaseClass()==compiler.baseTypes.voidClass){
      expect(iterator.next(), WeaselTokenType.SEMICOLON);
      instructions = new WeaselInstructionList();
      instructions.add(token.line, new WeaselInstructionReturnNull(compilerHelpher.getVarCount()));
    }else{
      WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.SEMICOLON);
      if(tree==null){
        throw new WeaselCompilerException(token.line, "return need to return %s", retClass);
      }
      WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelpher, null, retClass, null, false);
      instructions = wcr.getInstructions();
      WeaselTree.autoCast(compiler, wcr.getReturnType(), retClass, token.line, instructions, true);
      instructions.add(token.line, new WeaselInstructionReturn(compilerHelpher.getVarCount()));
    }
    return new WeaselCompilerReturnInstructionList(instructions, new WeaselGenericClass(compiler.baseTypes.voidClass));
View Full Code Here

          if(iterator.next().tokenType==WeaselTokenType.OPENBRACKET){
            try{
              if(token.param==WeaselKeyWord.THIS){
                superCaller = false;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
                if(token.tokenType!=WeaselTokenType.SEMICOLON)
                  throw new WeaselCompilerException(token.line, "Expect ; but got %s", token);
              }else if(token.param==WeaselKeyWord.SUPER){
                superCaller = true;
                auto = false;
                WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
                List<WeaselGenericMethod2> methods = classCompiler.genericClass.getGenericSuperClass().getGenericMethodsOfThis("<init>", true);
                WeaselParameterCompileReturn wpcr = WeaselTree.compileParamList(token.line, "<init>", compiler, this, tree, methods);
                instructions.addAll(wpcr.instructions);
                instructions.add(token.line, new WeaselInstructionInvoke(wpcr.method.getMethod().getMethod().getClassNameAndDesk()));
                token = iterator.next();
View Full Code Here

  @Override
  public WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    expect(iterator.next(), WeaselTokenType.OPENBRACKET);
    compilerHelpher.openBlock(true);
    WeaselTree tree1 = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
    if(tree1==null){
      throw new WeaselCompilerException(token.line, "Expect boolean value in while");
    }
    WeaselToken t = iterator.next();
    WeaselCompilerReturn wcr;
    WeaselInstructionList instructions = new WeaselInstructionList();
    WeaselInstruction continueJump = new WeaselInstructionJumperDummy();
    instructions.add(token.line, continueJump);
    wcr = tree1.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionIf ifI;
    instructions.add(token.line, ifI = new WeaselInstructionIf());
    if(t.tokenType==WeaselTokenType.OPENBLOCK){
View Full Code Here

    if(t.tokenType!=WeaselTokenType.KEYWORD || t.param!=WeaselKeyWord.WHILE){
      throw new WeaselCompilerException(t.line, "expect while but got %s", t);
    }
    WeaselInstruction continueJump = instructions.getLast();
    expect(t = iterator.next(), WeaselTokenType.OPENBRACKET);
    WeaselTree tree1 = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
    if(tree1==null){
      throw new WeaselCompilerException(t.line, "Expect boolean value in while");
    }
    WeaselCompilerReturn wcr;
    wcr = tree1.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    instructions.addAll(wcr.getInstructions());
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), t.line, instructions, true);
    WeaselInstruction ifJump = new WeaselInstructionJump(startJump);
    instructions.add(t.line, new WeaselInstructionIf(ifJump));
    instructions.add(t.line, ifJump);
View Full Code Here

public class WeaselKeyWordCompilerIf extends WeaselKeyWordCompiler {

  @Override
  public WeaselCompilerReturn compile(WeaselToken token, WeaselCompiler compiler, WeaselKeyWordCompilerHelper compilerHelpher, ListIterator<WeaselToken> iterator) throws WeaselCompilerException {
    expect(iterator.next(), WeaselTokenType.OPENBRACKET);
    WeaselTree tree = WeaselTree.parse(iterator, WeaselTokenType.CLOSEBRACKET);
    if(tree==null)
      throw new WeaselCompilerException(token.line, "Condition need to be a boolean value");
    WeaselCompilerReturn wcr = tree.compile(compiler, compilerHelpher, null, new WeaselGenericClass(compiler.baseTypes.booleanClass), null, false);
    WeaselInstructionList instructions = wcr.getInstructions();
    WeaselTree.autoCast(compiler, wcr.getReturnType(), new WeaselGenericClass(compiler.baseTypes.booleanClass), token.line, instructions, true);
    WeaselInstructionJump j1;
    instructions.add(token.line, j1 = new WeaselInstructionIf());
    instructions.addAll(compileBlock(compiler, compilerHelpher, iterator));
View Full Code Here

  }
 
  private WeaselGenericInformation[] makeGenericInformations(WeaselToken token) throws WeaselCompilerException{
    List<WeaselGenericInformation> genericList = new ArrayList<WeaselGenericInformation>();
    List<WeaselTreeGenericElement> genericListClass = new ArrayList<WeaselTreeGenericElement>();
    WeaselTreeGenericElement lwtge = null;
    if(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.LESS){
      do{
        token = getNextToken();
        WeaselCompiler.expect(token, WeaselTokenType.IDENT);
        String generic = (String)token.param;
        token = getNextToken();
        WeaselClass genericClass;
        if(token.tokenType == WeaselTokenType.KEYWORD && token.param == WeaselKeyWord.EXTENDS){
          ListIterator<WeaselToken> li;
          genericListClass.add(lwtge = new WeaselTreeGenericElement(li = tokenParser.listIterator()));
          if(lwtge.close){
            genericList.add(new WeaselGenericInformation(generic, lwtge.getWeaselClass(interpreter), -1));
            break;
          }
          token = li.next();
          genericClass = lwtge.getWeaselClass(interpreter);
        }else{
          genericClass = interpreter.baseTypes.getObjectClass();
          genericListClass.add(null);
          lwtge = null;
        }
        genericList.add(new WeaselGenericInformation(generic, genericClass, -1));
      }while(token.tokenType == WeaselTokenType.COMMA);
      if(!(lwtge!=null && lwtge.close) && !(token.tokenType==WeaselTokenType.OPERATOR && token.param == WeaselOperator.GREATER)){
        throw new WeaselCompilerException(token.line, "WeaselCompiler.expect > at end of generic declaration but got %s", token);
      }
    }else{
      setNextToken(token);
    }
    genericInformation = genericList.toArray(new WeaselGenericInformation[0]);
    for(int i=0; i<genericInformation.length; i++){
     
      WeaselTreeGenericElement wtge = genericListClass.get(i);
      if(wtge!=null){
        genericInformation[i].genericInfo = wtge.getGenericClassInfo(this);
      }
    }
    return genericInformation;
  }
View Full Code Here

TOP

Related Classes of weasel.compiler.v2.tokentree.WeaselTreeCondition

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.