SHARE
TWEET

Untitled

a guest Dec 14th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.antlr.v4.runtime.misc.NotNull;
  2.  
  3. import java.sql.SQLOutput;
  4. import java.util.ArrayList;
  5.  
  6. public class Operations extends gBaseVisitor<Integer> {
  7.  
  8.     OperationData operationData = new OperationData();
  9.  
  10.     @Override
  11.     public Integer visitInterrupt(gParser.InterruptContext ctx) {
  12.         operationData.getRegisters();
  13.         return super.visitInterrupt(ctx);
  14.  
  15.     }
  16.  
  17.  
  18.     @Override
  19.     public Integer visitStart(gParser.StartContext ctx) {
  20.         visitChildren(ctx);
  21.         return null;
  22.     }
  23.  
  24.     @Override
  25.     public Integer visitMov(gParser.MovContext ctx) {
  26.  
  27.         System.out.println(ctx.score.getText());
  28.         System.out.println(ctx.REGISTER());
  29.         //     System.out.println(Integer.valueOf(String.valueOf(ctx.right)));
  30.         //   operationData.setRegister(ctx.left.toString(),Integer.valueOf(String.valueOf(ctx.right)));
  31.         visitChildren(ctx);
  32.         return null;
  33.     }
  34.  
  35.     @Override
  36.     public Integer visitNumber(gParser.NumberContext ctx) {
  37.         return Integer.valueOf(ctx.getText());
  38.     }
  39.  
  40.     @Override
  41.     public Integer visitRegister(gParser.RegisterContext ctx) {
  42.         return operationData.getRegisters().get(ctx.REGISTER());
  43.     }
  44.  
  45.     @Override
  46.     public Integer visitAdd(gParser.AddContext ctx) {
  47.  
  48.         return visit(ctx.left) + visit(ctx.right);
  49.  
  50.     }
  51.  
  52.     @Override
  53.     public Integer visitMul(gParser.MulContext ctx) {
  54.         return visit(ctx.left) * visit(ctx.right);
  55.     }
  56.  
  57.     @Override
  58.     public Integer visitSub(gParser.SubContext ctx) {
  59.  
  60.         return visit(ctx.left) - visit(ctx.right);
  61.     }
  62.  
  63.  
  64.     @Override
  65.     public Integer visitXor(gParser.XorContext ctx) {
  66.         String left = String.valueOf(ctx.left.getText());
  67.         String right = String.valueOf(ctx.right.getText());
  68.         if (operationData.getRegisters().get(left) == null && operationData.getRegisters().get(right) == null) {
  69.             operationData.setRegister(right, 0);
  70.  
  71.         } else {
  72.  
  73.         }
  74.  
  75.         return null;
  76.  
  77.     }
  78.  
  79.     @Override
  80.     public Integer visitPush(gParser.PushContext ctx) {
  81.  
  82.         return null;
  83.     }
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top