Giter VIP home page Giter VIP logo

jmptrader / tinyjava-parsetree-compiler-execute_vmcode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harry1357931/tinyjava-parsetree-compiler-execute_vmcode

0.0 0.0 1.0 636 KB

The TinyJ language is an extremely small subset of Java. Every valid TinyJ program is a valid Java program, and has the same semantics whether it is regarded as a TinyJ or a Java program. This repository contain programs that generates the Parse Tree of TinyJ program, compile that program to generate Virtual Machine Code and then execute that Machine Code.

Java 100.00%

tinyjava-parsetree-compiler-execute_vmcode's Introduction

TinyJava-Compiler-VMcodeGenerator

The TinyJ language is an extremely small subset of Java. Every valid TinyJ program is a valid Java program, and has the same semantics whether it is regarded as a TinyJ or a Java program. This repository contain programs that generates the Parse Tree of TinyJ program, compile that program to generate Virtual Machine Code and then execute that VM Code.

About Tiny Java or Tiny J

The TinyJ language is an extremely small subset of Java. Every valid TinyJ program is a valid Java program, and has the same semantics whether it is regarded as a TinyJ or a Java program. The syntax of TinyJ is given by the EBNF rules given in file 'TinyJ-Assignment-1.pdf'. A Java program is a TinyJ program if and only if it can be generated by these EBNF rules, except that TinyJ doesn’t support method name overloading, program arguments, “return;” statements within the main() method, and ints that are ³ 231!216 = 2,147,418,112. Reserved words of TinyJ are shown in boldface. Some names used by Java library packages, classes, and predefined methods (e.g., java, Scanner, main, and nextInt) are reserved words of TinyJ. Otherwise, IDENTIFIER here means any Java identifier consisting of ASCII characters.

My Contribution to this program:

There were total of 3 TinyJ assignments, Check the bottom of this file to get hint of what each assignment does.
Contribution:
About 30% of Code in Tiny J(Tiny Java) assignment is written by me -- Gurpreet Singh, and 70% is done by Professor Kong (Phd.-Oxford University)
I wrote code for:
1) ParserAndTranslator.java at location TJasn\ParserAndTranslator.java
2) execute() method of approx. 30 Instructions at folder Location: TJasn\virtualmachine</b>
3) Parser.java at location \TJ1asn\Parser.java

To know more about Tiny J:

Read files: 'TinyJ-Assignment-1.pdf', 'TinyJ-Assignment-3.pdf', 'TinyJ-Assignment-3.pdf'

Examples:

In folder 'Examples', CS316ex0, CS316ex1,.... CS316ex15 are input files to a TinyJ Program, and .out files like 0.out, 1.out, ...15.out are output files. Each such output file contains a Parse Tree of java program, and virtual machine code of the program. TinyJ Assignment 1

It will not deal with compilation of TinyJ programs, nor with execution of virtual machine code, but only with syntax analysis of TinyJ programs. The goal of TinyJ Assignment 1 is to complete a program that will:
(a) determine whether its input file is a according to the above EBNF rules, and
(b) output a parse tree of the input file, if the input file is a .

TinyJ Assignment 2

Your assignment is to complete a compiler which does all of the following whenever its input is a syntactically valid TinyJ source file:

  1. It checks that declarations and uses of identifiers in the source file are consistent with Java's scope rules.
  2. As long as no errors are detected in the source file, it translates the source file into a sequence of instructions for a stack-based virtual machine whose instruction set is given below. At the same time, it writes to the output file an "enhanced parse tree" of the source file; this shows the static address or the stackframe offset that the compiler has allocated to each int or array reference variable, the start address of the code generated for each method, and the time at which each instruction is generated.
  3. If no errors are detected in the source file then a list of the instructions generated is also written to the output file.

TinyJ Assignment 3

The assignment is to further develop your TJasn program so it will correctly execute the TinyJ virtual machine (VM) instructions that it generates. For each VM instruction, there will be a corresponding file *instr.java in your TJasn/virtualMachine directory. Every such file has an execute() method. In ADDTOPTRinstr.java, HEAPALLOCinstr.java, NOPorDISCARDVALUEinstr.java, READINTinstr.java, and STOPinstr.java, that method is written for you. In the other 29 instr.java files, the body of the execute() method contains a comment of the form / ???????? */ which you need to replace with code that executes the corresponding VM instruction: Your code must make appropriate changes to the expression evaluation stack [CodeInterpreter.EXPRSTACK[]], data memory [TJ.data[]], and registers [CodeInterpreter.ESP, .PC, .FP, .ASP, etc.], and must produce correct output (if any). See the example at the beginning of the "How to Do the Assignment" section below.

tinyjava-parsetree-compiler-execute_vmcode's People

Contributors

harry1357931 avatar

Forkers

orb1t

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.