Examples of WeaselTree


Examples of weasel.compiler.v2.tokentree.WeaselTree

  @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

Examples of weasel.compiler.v2.tokentree.WeaselTree

    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

Examples of weasel.compiler.v2.tokentree.WeaselTree

          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

Examples of weasel.compiler.v2.tokentree.WeaselTree

  @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

Examples of weasel.compiler.v2.tokentree.WeaselTree

    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

Examples of weasel.compiler.v2.tokentree.WeaselTree

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
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.