sudhamsh@iitbhu: ~/CSE425_Compiler_Design_Lab
****************************************************************************************************************************************

Compiler Design Lab

CSE425 · IIT (BHU) · seven labs, from gcc's intermediate files to an LR parser $ ls $ ./clp "(id+id)*id+id" Accepted ****************************************************************************************************************************************
Cover of Principles of Compiler Design by Aho and Ullman: a knight fighting the complexity-of-compiler-design dragon
This repository contains my workings for the lab assignments of the compiler design course at IIT (BHU).

Every lab is a small program written in C++, LEX or YACC. Each one comes with its input, the exact commands to build and run it, and a screenshot of what the terminal printed.

  1. The whole pipeline Preprocess, compile, assemble and link a C program with gcc.
  2. Lexical analysis Turn a stream of characters into keywords, identifiers, numbers and operators.
  3. Syntax analysis Check the tokens against a grammar, top-down and bottom-up.
  4. Translation Attach actions to grammar rules with LEX and YACC.

1 A compiler is a pipeline: source → preprocessed file → assembly → object code → executable

2 The lexer reads characters and groups them into lexemes, each one tagged as a token

3 Top-down parsers grow the parse tree from the start symbol towards the input

4 Bottom-up parsers shift input onto a stack and reduce it back to the start symbol

5 LEX hands tokens to YACC, and YACC runs an action whenever a grammar rule matches

Straight from the terminal

Canonical LR parser trace: state stack, symbols, remaining input and shift/reduce actions, ending in Accepted
Lab 6 · canonical LR parse of (id+id)*id+id
Predictive parser trace with matched, stack, input and action columns
Lab 5 · predictive parse of id*(id+id)
Parse tree drawn in the terminal by the recursive descent parser
Lab 4 · parse tree from recursive descent
LEX rules for keywords, integers, identifiers, strings, comments and operators
Lab 3 · the LEX rules behind the lexer

The color_*.cpp builds of Labs 4–6 print in 256 colours. The colours mean:


Run any lab

git clone https://github.com/repsick3r/CSE425_Compiler_Design_Lab.git
cd CSE425_Compiler_Design_Lab/Lab6
g++ canonicalLRParser.cpp -o clp
./clp input.txt

Labs 3 and 7 also need flex and bison (sudo apt-get install bison flex). Each lab page has its exact commands.