Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.64 KB | None | 0 0
  1. class IfStatement
  2. {
  3.    String condition;
  4.    String gotoLabel;
  5. }
  6.  
  7. public void parseLine(String line)
  8. {
  9.    line = line.trim();
  10.  
  11.    String[] parts = line.split("\\s+");
  12.  
  13.    String command = parts[0];
  14.  
  15.    if(command.equals("IF"))
  16.    {
  17.       String condition = parts[1];
  18.       boolean result = evaluate(conditon);
  19.  
  20.       if(parts[2].equals("GOTO"))
  21.       {
  22.          String gotoLabel = parts[3];
  23.          if(!gotoLabel.startsWith("#"))
  24.             throw new CompileError();
  25.          instructions.add(new IfStatement(condition, gotoLabel));
  26.       }
  27.    }
  28.    else if(command.equals("GOTO"))
  29.    {
  30.       line = line.substring(5);
  31.    }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement