Skip to content

A curated list of my implementations for offlines in the course 'CSE-310: Compilers'

Notifications You must be signed in to change notification settings

Tahmeed156/Compiler-Sessional

Repository files navigation

Offline 1: Symbol Table Manager

Instructions: [PDF]

Implementation: cpp [Code]

Offline 2: Lexical Analysis

Instructions: [PDF]

Implementation: flex [Code]

Offline 3: Syntax & Semantic Analysis

Instructions: [PDF]

Implementation: bison [Code]

Offline 4: Intermediate Code Generation

Implementation: [PDF]

Implementation: bison + emu8086 [Code]


Install

  • flex
  • bison
  • emu8086 (with wine on linux)

Script

  • script.sh file
#!/bin/bash

# file names (without extensions)
SCANNER_FILE=1705039
PARSER_FILE=1705039

# compiling yacc file
bison -d -y -o $PARSER_FILE.cpp $PARSER_FILE.y
g++ -w -c -o y.o $PARSER_FILE.cpp

# compiling lex file
flex -o $SCANNER_FILE.cpp $SCANNER_FILE.l
g++ -w -c -o l.o $SCANNER_FILE.cpp

# linking object files
g++ -o a.out y.o l.o -lfl

# run executable on input file
./a.out $1

# open with emu8086 (with wine)
cp ./optimized_code.asm ~/.wine/drive_c/code.asm
wine ~/.wine/drive_c/emu8086/emu8086.exe "C:\\code.asm"
  • then run $ ./script.sh input.c

Input

  • input.c - contains the c code to be compiled

Output:

  • a.o - final object file
  • log.txt - log grammar rules with code segments
  • error.txt - log errors with line numbers
  • code.asm - assembly (MASM) code
  • optimized_code.asm - optimized assembly code

About

A curated list of my implementations for offlines in the course 'CSE-310: Compilers'

Resources

Stars

Watchers

Forks