Exemplo n.º 1
0
 static ArrayList<String> popArray(Variable v, String fileName, long line, boolean sizeKnown)
     throws CompilerException {
   ArrayList<String> res = new ArrayList<>();
   Tokenizer t = new Tokenizer();
   String code1 = "#pop array\n";
   if (!sizeKnown) {
     code1 += "asm:\n" + "\tpop " + v.sizeVarName() + " ;\n" + "end\n";
   }
   code1 +=
       "for var __ALZ_I=sub("
           + v.sizeVarName()
           + " 1); moreeq(__ALZ_I 0); __ALZ_I=sub(__ALZ_I 1);\n";
   String code2 = "endfor\n";
   ArrayList<Token> tokens1 = t.tokenize(code1);
   ArrayList<Token> tokens2 = t.tokenize(code2);
   Compiler c = new Compiler();
   try {
     res.addAll(c.compile(tokens1, false));
     res.addAll(v.type.pop(v.nameWithoutIndex() + "[__ALZ_I]"));
     res.addAll(c.compile(tokens2, false));
   } catch (Exception e) {
     CompilerException ex =
         new CompilerException("failed to pop array " + v.nameWithoutIndex(), fileName, line);
     ex.initCause(e);
     throw ex;
   }
   exec("delv __ALZ_I ;", res);
   return res;
 }
Exemplo n.º 2
0
 static ArrayList<String> pushArray(Variable v, String fileName, long line)
     throws CompilerException {
   ArrayList<String> res = new ArrayList<>();
   Tokenizer t = new Tokenizer();
   String code1 =
       ""
           + "#push array\n"
           + "for var __ALZ_I=0; less(__ALZ_I "
           + v.sizeVarName()
           + "); __ALZ_I=add(__ALZ_I 1);\n";
   String code2 =
       "" + "endfor\n" + "asm:\n" + "\tpush " + v.nameWithoutIndex() + ".size ;\n" + "end";
   ArrayList<Token> tokens1 = t.tokenize(code1);
   ArrayList<Token> tokens2 = t.tokenize(code2);
   Compiler c = new Compiler();
   try {
     res.addAll(c.compile(tokens1, false));
     res.addAll(v.type.push(v.nameWithoutIndex() + "[__ALZ_I]"));
     res.addAll(c.compile(tokens2, false));
   } catch (Exception e) {
     CompilerException ex =
         new CompilerException("failed to push array " + v.nameWithoutIndex(), fileName, line);
     ex.initCause(e);
     throw ex;
   }
   exec("delv __ALZ_I ;", res);
   return res;
 }
 /** The run() method. */
 public void run() {
   try {
     createInstaller(); // Execute the compiler - may send info to
     // System.out
   } catch (CompilerException ce) {
     System.out.println(ce.getMessage() + "\n");
   } catch (Exception e) {
     if (Debug.stackTracing()) {
       e.printStackTrace();
     } else {
       System.out.println("ERROR: " + e.getMessage());
     }
   }
 }
Exemplo n.º 4
0
  public void run() {
    try {

      Scanner s = new Scanner(this.reader);
      Parser p = new Parser(s);
      Symbol root = p.parse();

      Program prog = (Program) root.value;
      prog.accept(new PrettyPrintVisitor());

      System.out.print("Parser rodou com sucesso!");

    } catch (CompilerException e) {
      // erro de compilação do arquivo de entrada
      System.err.println(e.getMessage());
    } catch (Exception e) {
      // erro do compilador
      System.err.println("Erro inesperado no parser: " + e.toString());
      e.printStackTrace();
    }
  }
Exemplo n.º 5
0
  Macro(GlobalIndex globalIndex, AMacro declaration, Macro parent) {

    super(globalIndex);

    if (globalIndex == null) {
      throw new InternalException("globalIndex may not be null");
    }

    if (declaration == null) {
      throw new InternalException("declaration may not be null");
    }

    this.declaration = declaration;
    this.parent = parent;

    if (!declaration.getRepeatName().getText().equals(declaration.getName().getText())) {
      throw CompilerException.endMismatch(declaration.getRepeatName(), declaration.getName());
    }
  }