NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package view;

import controller.Controller;
import model.*;
import repository.IRepo;
import repository.Repository;

public class MyInterpreter{

public static void main(String[] args){

//Example 1
IStmt ex1 = new CompStmt(new AssignStmt("v", new ConstExp(2)), new PrintStmt(new VarExp("v")));
PrgState prg1 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex1);
IRepo repo1 = new Repository(prg1, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log1.txt");
Controller ctrl1 = new Controller(repo1);

//Example 2
IStmt ex2 = new CompStmt(new AssignStmt("a", new ArithExp("+", new ConstExp(2),
new ArithExp("*", new ConstExp(3), new ConstExp(5) ))), new CompStmt(
new AssignStmt("b", new ArithExp("+", new VarExp("a"), new ConstExp(1))),
new PrintStmt(new VarExp("b"))));
PrgState prg2 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex2);
IRepo repo2 = new Repository(prg2, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log2.txt");
Controller ctrl2 = new Controller(repo2);

//Example 3
IStmt ex3 = new CompStmt(new AssignStmt("a", new ArithExp("-", new ConstExp(2), new ConstExp(2))),
new CompStmt(new IfStmt(new VarExp("a"), new AssignStmt("v", new ConstExp(2)),new AssignStmt
("v", new ConstExp(3))), new PrintStmt(new VarExp("v"))));
PrgState prg3 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex3);
IRepo repo3 = new Repository(prg3, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log3.txt");
Controller ctrl3 = new Controller(repo3);

// Example 4
// openRFile(var_f,"test.in");
// readFile(var_f,var_c);print(var_c);
// (if var_c then readFile(var_f,var_c);print(var_c)
// else print(0));
// closeRFile(var_f)
OpenRFile openFile = new OpenRFile("file", "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\data.txt");
ReadFile readFile = new ReadFile(new VarExp("file"), "variable");
CloseRFile closeFile = new CloseRFile(new VarExp("file"));
PrintStmt printStmt = new PrintStmt(new VarExp("variable"));
IfStmt ifStmt = new IfStmt(new VarExp("variable"), new CompStmt(readFile, printStmt), new PrintStmt(new ConstExp(0)));
IStmt ex4 = new CompStmt(new CompStmt(openFile, new CompStmt(readFile, printStmt)), new CompStmt(ifStmt, closeFile));
PrgState prg4 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex4);
IRepo repo4 = new Repository(prg4, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log4.txt");
Controller ctrl4 = new Controller(repo4);

// Example 5
// openRFile(var_f,"test.in");
// readFile(var_f+2,var_c);print(var_c);
// (if var_c then readFile(var_f,var_c);print(var_c)
// else print(0));
// closeRFile(var_f)
OpenRFile openFile2 = new OpenRFile("file", "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\data.txt");
ReadFile readFile2 = new ReadFile(new ArithExp("+", new VarExp("file"), new ConstExp(2)), "variable");
CloseRFile closeFile2 = new CloseRFile(new VarExp("file"));
PrintStmt printStmt2 = new PrintStmt(new VarExp("variable"));
IfStmt ifStmt2 = new IfStmt(new VarExp("variable"), new CompStmt(readFile2, printStmt2), new PrintStmt(new ConstExp(0)));
IStmt ex5 = new CompStmt(new CompStmt(openFile2, new CompStmt(readFile2, printStmt2)), new CompStmt(ifStmt2, closeFile2));
PrgState prg5 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(),ex5);
IRepo repo5 = new Repository(prg5, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log5.txt");
Controller ctrl5 = new Controller(repo5);


// Example 6
// v = 10;
// new(v,20);
// new(a,22);
// print(v)
IStmt ex6 = new CompStmt(new AssignStmt("v", new ConstExp(10)),new CompStmt(new New("v",new ConstExp(20)),new CompStmt(
new New("a", new ConstExp(22)), new PrintStmt(new VarExp("v")))));
PrgState prg6 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex6);
IRepo repo6 = new Repository(prg6, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log6.txt");
Controller ctrl6 = new Controller(repo6);

// Example 7
// v=10;new(v,20);
// new(a,22);print(100+rH(v));
// print(100+rH(a))
IStmt ex7 = new CompStmt(new AssignStmt("v", new ConstExp(10)),new CompStmt(new New("v",new ConstExp(20)),new CompStmt(
new New("a", new ConstExp(22)),new CompStmt(new PrintStmt(new ArithExp("+", new ConstExp(100),new ReadHeap("v"))),
new PrintStmt(new ArithExp("+", new ConstExp(100),new ReadHeap("a")))))));
PrgState prg7 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex7);
IRepo repo7 = new Repository(prg7, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log7.txt");
Controller ctrl7 = new Controller(repo7);

// Example 8
// v=10;new(v,20);
// new(a,22);wH(a,30);
// print(a);print(rH(a))
IStmt ex8 = new CompStmt(new AssignStmt("v", new ConstExp(10)),new CompStmt(new New("v",new ConstExp(20)),new CompStmt(
new New("a", new ConstExp(22)),new CompStmt(new WriteHeap("a",new ConstExp(30)), new CompStmt(new PrintStmt(
new VarExp("a")), new PrintStmt(new ReadHeap("a")))))));
PrgState prg8 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex8);
IRepo repo8 = new Repository(prg8, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log8.txt");
Controller ctrl8 = new Controller(repo8);

// Example 9
// v=6; (while (v-4) print(v);v=v-1);
// print(v)
IStmt ex9 = new CompStmt(new AssignStmt("v",new ConstExp(6)), new CompStmt(new WhileStmt(new ArithExp("-",new VarExp("v"), new ConstExp(4)),
new CompStmt(new PrintStmt(new VarExp("v")), new AssignStmt("v", new ArithExp("-", new VarExp("v"), new ConstExp(1))))),
new PrintStmt(new VarExp("v"))));
PrgState prg9 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex9);
IRepo repo9 = new Repository(prg9, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log9.txt");
Controller ctrl9 = new Controller(repo9);

// Example 10
// openRFile(var_f,"test.in");
// readFile(var_f,var_c);print(var_c);
// (if var_c then readFile(var_f,var_c);print(var_c)
// else print(0));
OpenRFile openFilee = new OpenRFile("file", "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\data.txt");
ReadFile readFilee = new ReadFile(new VarExp("file"), "variable");
//CloseRFile closeFilee = new CloseRFile(new VarExp("file"));
PrintStmt printStmtt = new PrintStmt(new VarExp("variable"));
IfStmt ifStmtt = new IfStmt(new VarExp("variable"), new CompStmt(readFile, printStmt), new PrintStmt(new ConstExp(0)));
IStmt ex10 = new CompStmt(new CompStmt(openFile, new CompStmt(readFile, printStmt)), ifStmt);
PrgState prg10 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex10);
IRepo repo10 = new Repository(prg10, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log10.txt");
Controller ctrl10 = new Controller(repo10);

// Example 11
// 10 + (2<6) evaluates to 11
Exp ex11 = new ArithExp("+", new ConstExp(10), new BoolExp(new ConstExp(2), new ConstExp(6), "<"));
System.out.println(ex11.eval(new MyDictionary<String, Integer>(), new Heap()));

// Example 12
// (10+2)<6 evaluates to 0
Exp ex12 = new BoolExp(new ArithExp("+", new ConstExp(10), new ConstExp(2)), new ConstExp(6), "<");
System.out.println(ex12.eval(new MyDictionary<String, Integer>(), new Heap()));

// Example 13
//v=10; new(a,22);
//fork(wH(a,30); v=32;print(v); print(rH(a)));
//print(v); print(rH(a))
IStmt ex13 = new CompStmt(new AssignStmt("v", new ConstExp(10)),new CompStmt(new New("a",new ConstExp(22)),
new CompStmt(new ForkStmt(new CompStmt(new WriteHeap("a",new ConstExp(30)), new CompStmt(new AssignStmt("v",
new ConstExp(32)), new CompStmt(new PrintStmt(new VarExp("v")), new PrintStmt(new ReadHeap("a")))))),
new CompStmt(new PrintStmt(new VarExp("v")), new PrintStmt(new ReadHeap("a"))))));
PrgState prg13 = new PrgState(new MyStack<IStmt>(), new MyDictionary<String, Integer>(), new MyList<Integer>(), new MyFileTable(), new Heap(), ex13);
IRepo repo13 = new Repository(prg13, "C:\Users\Darian Soporan\Desktop\MAP\untitled\src\repository\log13.txt");
Controller ctrl13 = new Controller(repo13);

TextMenu menu = new TextMenu();
menu.addCommand(new ExitCommand("0", "Exit"));
menu.addCommand(new RunExample("1", ex1.toString(), ctrl1));
menu.addCommand(new RunExample("2",ex2.toString(), ctrl2));
menu.addCommand(new RunExample("3", ex3.toString(), ctrl3));
menu.addCommand(new RunExample("4", ex4.toString(), ctrl4));
menu.addCommand(new RunExample("5", ex5.toString(), ctrl5));
menu.addCommand(new RunExample("6", ex6.toString(), ctrl6));
menu.addCommand(new RunExample("7", ex7.toString(), ctrl7));
menu.addCommand(new RunExample("8", ex8.toString(), ctrl8));
menu.addCommand(new RunExample("9", ex9.toString(), ctrl9));
menu.addCommand(new RunExample("10", ex10.toString(), ctrl10));
menu.addCommand(new RunExample("11", ex13.toString(), ctrl13));

menu.show();
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.