8000 GitHub - compiler-experts/miniJava at f45ac9bab5a0e55137b8ebcc6c68b2e2408db65d
[go: up one dir, main page]

Skip to content

compiler-experts/miniJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The minijavac compiler

A compilation project for Thrid year students of IMT Atlantique (the former Telecom Bretagne)

The specification of the project can be found here (Authorization Required)

How to clone the project

Using git clone

git clone https://redmine-df.telecom-bretagne.eu/git/f2b304_compiler_cn

then input your Username and Password in the command prompt

The project structure

The project is divided by 2 parts

  • phase1: the first delivery which contains the lexical and syntax analyzer for the language minijava
  • phase2: the second delivery which contains the semantic analyzer for the language minijava based on the lexical and syntax analyzer that offered by professors

to build or execute the compiler, you should entre one of these folder, cd ./phase1 or cd ./phase2

How to build the compiler

Using the shell script build

./build

or using ocamlbuild to build the compiler

ocamlbuild Main.byte

Notes

The main file is Main/Main.ml, it should not be modified. It opens the given file,creates a lexing buffer, initializes the location and call the compile function of the module Main/compile.ml. It is this function that you should modify to call your parser.

How to execute the compiler

Using the shell script minijavac

./minijavac <filename>

or using the following command to build and then execute the compiler on the given file named <filename>

ocamlbuild Main.byte -- <filename>

By default, the program searches for file with the extension .java and append it to the given filename if it does not end with it.

How to test the Compiler

Using the shell script test

./test

it will execute Main.byte on all files in the directory Evaluator

How to contribute to the Project

If you are a team member of the project, please follow the Working Standard to make appropriate contributions

To do list

First part: Lexical and syntactic analyzers

Deadline 15/01/2018

Expression

  • Line Terminators
  • Input Elements and Tokens
  • White Space
  • Comments
  • Identifiers
  • Keywords
    • for
    • while
    • else
    • if
  • Literals
    • Int
    • String
  • Separators
    • brace
    • parenthese
    • dot
    • comma
    • semicolon
  • Operators
    • = Simple Assignment Operator
    • + - * / % Arithmetic Operators
    • + - ++ -- ! Unary Operators
    • == != > < <= >= Equality and Relational Operators
    • && || Conditional Operators

Classes

  • Keywords
    • class
    • static
    • extends
    • return
    • new
  • Classes
    • Class Declaration
      • simple class declaration
      • simple class declaration with extends
    • Field Declarations
      • static Fields
      • non-static Fields
    • Method Declarations
      • static Methods
      • non-static Methods

Second part: The Type-checking and the Execution

Deadline 25/02/2018

Type-checking

  • The construction of the class definition environment. This environment contains the type of methods for each class. This phase ignores the attributes (which are not visible outside the class) and the method bodies.
    • create a class definition environment type called class_env, it contains 4 fields as follows
      • methods: a Hashtbl that maps from methode name to methode return type and argument type
      • constructors: a Hashtbl that maps from constructor name to class reference type and argument type
      • attributes: a Hashtbl that maps from attribute name to attribute type (declared type)
      • parent: a class reference type that refers to its class
    • create a Hashtbl that maps from class
  • [] The second phase is concerned with verifying that the inside of classes is correct (mainly the body of methods). She will also make sure of the correction of the higher level expression.
    • create 3 verification methode that verifies the following aspects of the program
      • verify_methods that checks the type of methods
        • create a local definition environment type called current_env it contains 3 fields as follows
          • returntype: the declared return type of the methode
          • variables: a Hashtbl that maps from local variable name to local variable declared type
          • this_class: the id of the class
          • env_type: a string that identifies the type of the local definition environment, it could be constructor, methode or attribute, in this case, the env_type is methode
        • write a verification methode (verify_declared_args) that checks the declared type of variables in the methode arguments
          • check if there exists Duplicate Local Variable
        • [] write a verification methode (verify_statement) that checks the body of the methode
          • check declared variables
          • check block of statement
          • check expression
          • check return statement when it's none, ex: return;
          • [] check return statement when it's not none, ex: return x;
          • [] check throw statement
          • [] check while statement
          • [] check if statement when it doesn't have else
          • [] check if statement when it has else
          • [] check for statement
          • [] check try statement
      • verify_constructors that checks the type of constructors
      • verify_attributes that checks the type of attributes
Errors that can be found during Type-checking
  • ArgumentAlreadyExists
  • AttributeAlreadyExists
  • ClassAlreadyExists
  • ConstructorAlreadyExists
  • DuplicateLocalVariable
  • IncompatibleTypes
    • when constructor try to return a variable -> IncompatibleTypes("unexpected return value")
    • when methode return does not contain variable -> IncompatibleTypes("missing return value")
    • when methode return type does not corresponds with the declared one -> IncompatibleTypes("missing return value")
  • MethodAlreadyExists
  • UnknowVariable
  • WrongTypesAssignOperation
  • WrongTypesOperation
Errors that can not yet be found during Type-checking
  • errors related to overloading
  • errors related to overriding

Execution

Evaluation and execute by certain means

1. Complilation

Construction of descriptors and tables

Construction of descriptors

  • [] object descriptor ? object descriptor space
  • [] class descriptor ? class descriptor space
  • [] methode descriptor ? methode descriptor space

Allocations

working from specail cases:

  • object -> null, true, false

  • class -> Object, Int, Boolean, String

  • [] allocation of special classes

  • [] allocation of special objects

  • [] allocation of class if it is not allocated

2. Execution

Problems

Problems of Type

Problems of Execution

About

A compilation project for Thrid year students of IMT Atlantique (the former Telecom Bretagne)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  
0