Skip to content
Snippets Groups Projects

2024 Compilation Project Report - COREC Compiler

The project

The main goal of this project is to build a COREC compiler, from high-level syntax to low-level syntax (assembly language). See the project subject here.

You may also be interested in the architecture of the project and the test report.

Parameters

  • -o output.asm -> write the result in the output.asm.
  • -version -> show the credits.
  • -tos -> show the symbole table.

Prerequisites

  • Install flex :
sudo apt install flex
  • Install bison :
sudo apt install bison

Implemented Features

Branch gencode_1

  • Definition of local variable in the loc section of functions. (TO DO :TRANSLATE IN MIPS but do not do here the float value)
  • Affectation of integer value. (TO DO :TRANSLATE IN MIPS but do not do here the float value)
  • Print and printstr functions. (TO DO :TRANSLATE IN MIPS)

Branch gencode_2

  • Operation on variable (except arrays) -> (+,-,*,/). (TO DO :TRANSLATE IN MIPS)
  • Assignement operation on variable (except arrays) -> (+=,-=,*=,/=). (TO DO :TRANSLATE IN MIPS)

Branch gencode_3-4

  • Affectation and definition of local 1D array. (TO DO :TRANSLATE IN MIPS)

  • Operation with and on local 1D array. (TO DO :TRANSLATE IN MIPS)

  • print function works on array. (TO DO :TRANSLATE IN MIPS)

  • float value as singleton array. (TO DO :TRANSLATE IN MIPS)

  • Cast integer in float if integer affectation to arrays or multiplication of a float and an integer. (Implicit)

  • Multi dimensional array. (TO DO :TRANSLATE IN MIPS)

To Do

  1. Translate intermediate code of the gencode_1 branch in mips.
  2. Translate intermediate code of the gencode_2 branch in mips.
  3. Translate intermediate code of the gencode_3 branch in mips.
  4. Add to the symtable in the beginning of the programm COREC key words (def, prog, Loc, Rec, ...) to recognize without the lex. Not sure
  5. Possibility to add an attribut to the symbol struc for temporary variable and variable to know what, the affectation value type is (Maybe with an enum). This would provide a better

Makefile commands

  • make -> compile the source files
  • compil -> run project executable on the input.txt file, create and write the result on output/output.asm file.
  • run -> test with Mars (Mars4_5.jar) the output/output.asm file.
  • version -> same as run but shows credits.
  • tos -> same as run but shows the table of symbole.
  • clean -> clean the directory.

For developpment (add tokens display in the lex file):

  • test num=N -> run project executable and test it on Codes_en_COREC/tests/testN.corec file. By default, num is equal to 1.
  • testErr num=N -> run project executable and test it on Codes_en_COREC/testsErrors/testNErr.corec file. By default, num is equal to 1. The test should return an error by the compiler.
  • check num=N -> run project executable and check valgrind error on Codes_en_COREC/tests/testN.corec file. By default, num is equal to 1.
  • checkErr num=N -> run project executable and check valgrind error on Codes_en_COREC/testsErrors/testNErr.corec file. By default, num is equal to 1. The test should return an error by the compiler.
  • test_corec -> run project executable and test it on 7 COREC files examples in Codes_en_COREC/ directory.

Need more on commands for the project ? Go here.

Members

The four members are :