Compiler

Description

  • Michal Ondrejka, Dominik Trúchly, Jakub Brňák, Maťo Hrachovec

  • GitHub

  • december, 2021

This project involves designing and developing a compiler for IFJ22. The compiler takes code written in IFJ22 (Language similar to PHP) and translates it into IFJcode22 (Similar to Assembly language), a low-level programming language.
The compiler consits of four parts. Lexical analyzer generates tokens based on finite state machine I designed (2nd picture). Tokens are sequence of characters (for, int, if, 5, ;, ...). These tokens are generated by Syntax analyzer which uses LL grammar (3rd picture) to verify the syntax of translated code. While generating tokens symbol table is filled up with variable names and types, function names and return types and more. This is used in Semantic analysis to make sure the semantic correctness of the code. This was a approach top-down. For expressions (5 + 5 * 2) the bottom-up approach has to be applied. For this I designed precedent analysis table which systematicly applies the rules when possible to expression. Code is being generated when equivalent instructions from input code have been processed and are able to be generated in the target language.

Technology