Class exercise.txt Using the JavaCC parser generator tool, implement the following language, including code generation: -> BEGIN END -> { }* -> COMPUTE -> { (+ | -) }* -> integer-value | ( )...


JavaCC Exercise

Using the JavaCC parser generator tool, implement the following language, including code generation: -> BEGIN END -> {}* -> COMPUTE -> { (+ | -) }* -> integer-value | ( )As a reference, you have an example (A_HOLE_EXAMPLE.zip)


Class exercise.txt Using the JavaCC parser generator tool, implement the following language, including code generation: -> BEGIN END -> {}* -> COMPUTE -> { (+ | -) }* -> integer-value | ( ) InClass1.jj /* JavaCC implementation of a subset of the Anderson Holistic Learning Environment Programming Language (A-HOLE) BEGIN ( |( ( +|- |)* ) )+ END */ PARSER_BEGIN(A_HOLE_EXAMPLE) public class A_HOLE_EXAMPLE { public static void main(String args[]) throws ParseException { A_HOLE_EXAMPLE parser; if (args.length == 0) { parser = new A_HOLE_EXAMPLE(System.in); } else { try { parser = new A_HOLE_EXAMPLE(new java.io.FileInputStream(args[0])); } catch (java.io.FileNotFoundException e) { System.out.println("Input File Not Found"); return; } } java.io.FileOutputStream out; java.io.DataOutputStream dataOut; try { out = new java.io.FileOutputStream("Evaluate.java"); dataOut = new java.io.DataOutputStream(out); dataOut.write(parser.PROGRAM().getBytes()); dataOut.close(); } catch (java.io.IOException e) { System.out.println("Cannot Open or Use Output File"); } } } PARSER_END(A_HOLE_EXAMPLE) SKIP : { " " | "\t" | "\n" | "\r" } TOKEN : { < begin:="" "begin"=""> | < end:="" "end"=""> | < compute:="" "compute"=""> | < id:="" ["a"-"z","a"-"z","_"]="" (="" ["a"-"z","a"-"z","_","0"-"9"]="" )*=""> | < num:="" (="" ["0"-"9"]="" )+=""> } String PROGRAM() : { String s=""; String s1=""; } { s1=BODY() { s="public class Evaluate\n"+"{\n"+" public static void main(String args[])\n"+" {\n"+s1+" }\n"+"}\n"; return s; } } String BODY() : { String s=""; String s1=""; } { ( s1=STMT() { s=s+s1; } )* { return s; } } String STMT() : { String s=""; } { s=EXPR() { return " System.out.println("+s+");\n"; } } String EXPR() : { String s=""; String s1=""; String s2=""; String op=""; } { s=TERM() ( ( "+" { op="+"; } | "-" { op="-"; } ) s2=TERM() { s=s+op+s2; } )* { return s; } } String TERM() : { Token t; String s=""; } { "(" s=EXPR() ")" { return "("+s+")"; } | t= { return t.image; } } A_HOLE_EXAMPLE.jj /* JavaCC implementation of a subset of the Anderson Holistic Learning Environment Programming Language (A-HOLE) BEGIN ( |( ( +|- |)* ) )+ END */ PARSER_BEGIN(A_HOLE_EXAMPLE) public class A_HOLE_EXAMPLE { public static void main(String args[]) throws ParseException { A_HOLE_EXAMPLE parser; if (args.length == 0) { parser = new A_HOLE_EXAMPLE(System.in); } else { try { parser = new A_HOLE_EXAMPLE(new java.io.FileInputStream(args[0])); } catch (java.io.FileNotFoundException e) { System.out.println("Input File Not Found"); return; } } java.io.FileOutputStream out; java.io.DataOutputStream dataOut; try { out = new java.io.FileOutputStream("Evaluate.java"); dataOut = new java.io.DataOutputStream(out); dataOut.write(parser.PROGRAM().getBytes()); dataOut.close(); } catch (java.io.IOException e) { System.out.println("Cannot Open or Use Output File"); } } } PARSER_END(A_HOLE_EXAMPLE) SKIP : { " " | "\t" | "\n" | "\r" } TOKEN : { < begin:="" "begin"=""> | < end:="" "end"=""> | < id:="" ["a"-"z","a"-"z","_"]="" (="" ["a"-"z","a"-"z","_","0"-"9"]="" )*=""> | < num:="" (="" ["0"-"9"]="" )+=""> } String PROGRAM() : { String s=""; String s1=""; } { s1=BODY() { s="public class Evaluate\n"+"{\n"+" public static void main(String args[])\n"+" {\n"+s1+" }\n"+"}\n"; return s; } } String BODY() : { String s=""; String s1=""; } { ( s1=EXPR() { s=s+s1; } )+ { return " System.out.println("+s+");\n"; } } String EXPR() : { String s=""; String s1=""; String s2=""; String op=""; } { s=FACTOR() ( ( "+" { op="+"; } | "-" { op="-"; } ) s2=FACTOR() { s=s+op+s2; } )* { return s; } } String FACTOR() : { Token t; String s=""; } { t= { return t.image; } | t= { return t.image; } } javacc.PNG A Simple Machine Language A Simple Machine Language Project Simple Machine Architecture The machine has 16 general‑purpose registers numbered 0 through F (in hexadecimal). Each register is one byte (eight bits) long. For identifying registers within instructions, each register is assigned the unique four‑bit pattern that represents its register number. Thus register 0 is identified by 0000 (hexadecimal 0), and register 4 is identified by 0100 (hexadecimal 4). There are 256 cells in the machine's main memory. Each cell is assigned a unique address consisting of an integer in the range of 0 to 255. An address can therefore be represented by a pattern of eight bits ranging from 00000000 to 11111111 (or a hexadecimal value in the range of 00 to FF). Storing a value to address FF will print the ASCII representation of that byte on the machine’s printer. Floating‑point values are assumed to be stored in an eight‑bit format where the first bit is the sign bit (0 – positive, 1 – negative), the next three bits represent the exponent in an excess-3 format (111 represents 3, 000 represents -4), and the final four bits are the mantissa. Machine Language Each machine instruction is two bytes long. The first 4 bits provide the op‑code; the last 12 bits make up the operand field. The table that follows lists the instructions in hexadecimal notation together with a short description of each. The letters R, S, and T are used in place of hexadecimal digits in those fields representing a register identifier that varies depending on the particular application of the instruction. The letters X and Y are used in lieu of hexadecimal digits in variable fields not representing a register. Op‑code Operand Description 1 RXY LOAD the register R with the bit pattern found in the memory cell whose address is XY. Example: 14A3 would cause the contents of the memory cell located at address A3 to be placed in register 4. 2 RXY LOAD the register R with the bit pattern XY Example: 20A3 would cause the value A3 to be placed in register 0. 3 RXY STORE the bit pattern found in register R in the memory cell whose address is XY. Example: 35B1 would cause the contents of register 5 to be placed in the memory cell whose address is BI. 4 0RS MOVE the bit pattern found in register R to register S. Example: 40A4 would cause the contents of register A to be copied into register 4. 5 RST ADD the bit patterns in registers S and T as though they were two's complement representations and leave the result in register R. Example: 5726 would cause the binary values in registers 2 and 6 to be added and the sum placed in register 7. 6 RST ADD the bit patterns in registers S and T as though they represented values in floating-point notation and leave the floating‑point result in register R. Example: 634E would cause the values in registers 4 and E to be added as floating‑point values and the result to be placed in register 3. 7 RST OR the bit patterns in registers S and T and place the result in register R. Example: 7CB4 would cause the result of ORing the contents of registers B and 4 to be placed in register C. 8 RST
Aug 27, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here