GuilhermeMLS / pascal-flex-compiler

A Simplified Pascal compiler made with Flex and Bison.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pascal Flex Compiler

A Simplified Pascal compiler that uses Flex and Bison to compile code to MEPA (abbreviation for Pascal Execution Machine in Portuguese), which is a virtual machine to execute Simplified Pascal programs. Simplified Pascal is a subset of the Pascal programming language.

This project was mas made by using a base-project made by professor Bruno Muller from UFPR. The base-project contains no logic and was made to help students to get started with Flex and Bison.

Example:

Pascal Code (input):

program type2 (input, output);
type banana = integer;
var b : banana;
   x  : integer;
begin
   x := 1;
   b:=1; 
	while b <=10 do
      begin
         if (x <= b) 
            then
            x:=x+1;
         write (x);
         b:=b+1;
      end
end.

MEPA code (output):

     INPP
     AMEM 1
     AMEM 1
     DSVS R00
R00: NADA 
     CRCT 1
     ARMZ 0, 1
     CRCT 1
     ARMZ 0, 0
R01: NADA 
     CRVL 0, 0
     CRCT 10
     CMEG
     DSVF R02
     CRVL 0, 1
     CRVL 0, 0
     CMEG
     DSVF R04
     CRVL 0, 1
     CRCT 1
     SOMA
     ARMZ 0, 1
     DSVS R03
R04: NADA 
R03: NADA 
     CRVL 0, 1
     IMPR
     CRVL 0, 0
     CRCT 1
     SOMA
     ARMZ 0, 0
     DSVS R01
R02: NADA 
     DMEM 2
     PARA

Running the program

$ make clean
$ make
./compilador {simplified_pascal_file}

Notice: there are some Simplified Pascal files in the root directory:

  • testebool.pas;
  • type1.pas;
  • type2.pas;
  • type3.pas.

About

A Simplified Pascal compiler made with Flex and Bison.


Languages

Language:C 69.7%Language:Makefile 11.2%Language:Assembly 5.4%Language:CMake 5.0%Language:Yacc 4.1%Language:Lex 2.6%Language:C++ 1.6%Language:Pascal 0.2%Language:Shell 0.2%