Skip to content

margdoc/mrjp-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latte Compiler

This code was written as a university project. The task description, written in Polish, can be found here. The specification of the Latte language for this task is available here. I chose Haskell for this project because I enjoy working with it, and it was recommended by the lecturer. This version (uploaded to GitHub) does not meet the technical requirements for code structure.

Compiler compiles Latte language program to x86_64.

Requirements

  • gcc - for compiling C code
  • ghc - for compiling Haskell code
  • bnfc,alex,happy - for creating Latte parser

Score

This code scored 30.5/34 points, the highest score among students in my year.

Compilation

make

Code Structure

  • Makefile
  • src/ - source files
  • build/latc_x86_64 - compiled BNFC files for the grammar described in src/Grammar.cf
  • build/Grammar/ - compiled BNFC files for the grammar described in src/Grammar.cf
  • lib/runtime.o - compiled built-in functions from src/runtime.c
  • tests/ - test cases for the compiler

Grammar

The current conflict is a well-known issue with if (...) if (...) ... else .... The parser resolves this conflict by applying the shift operation, ensuring that else is associated with the nearest preceding if, which aligns with our intuition.

Language Extensions

  • Arrays
  • Structures
  • Objects
  • Virtual methods
  • Garbage collection (instead of a la Rust's memory management)
  • LCSE/GCSE (Local/Common Subexpression Elimination)
  • Constant propagation (enabled under the -O2 compilation flag)

Built-in Functions

Library and helper functions are included in lib/runtime.o (source code in src/runtime.c).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages