Hassan220022 / Compiler-Project

A compiler is a crucial tool in software development, it is like a translator for computer programs, converting high-level source code written by developers into machine code that computers can understand and execute. The process of compilation is divided into several phases, and the first three are particularly significant.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Compiler Project

A compiler is an essential tool in software development, acting as a translator for high-level source code into machine-readable instructions. This project focuses on implementing a compiler for a For-loop statement, covering crucial phases of compilation.

General Phases

Phase 1 (Lexical Analyzer)

In this phase, the source code is transformed into a set of tokens, including reserved words, special symbols, numbers, identifiers, and comments.

Context-Free Grammar (CFG)

To progress to subsequent phases, a well-designed CFG is crucial. The CFG must be tailored to the specific structure of the given statement.

Phase 2 (Syntax Analyzer)

This phase emphasizes the code's structure, constructing an abstract syntax tree.

Phase 3 (Semantic Analyzer)

Checking the code's meaning and context to ensure alignment with the language's semantics. These initial phases enable the compiler to comprehend the code's structure and meaning.

Example: IF (X < Y) {X++}

  • High-level language
    • Lexical Analyzer (Tokenizer)
    • Syntax Analyzer (CFG, Parser)
    • Semantic Analyzer -> Semantic Tree

The Parser

This project requires a Parse Tree parser, providing a geometrical representation of the derived string.

The Statement

The specific statement implemented in this project is the For-loop statement.

For (int X = 0; X <= 100; X++) 
{
    Sum += X;
}

SIC Machine

The Simplified Instructional Computer (SIC) machine is a hypothetical computer architecture introduced by Leland Beck. It's a simplified model used for educational purposes. The SIC machine includes various instructions and features to demonstrate fundamental concepts of computer organization and programming.

Requirements

  • Display inputs and outputs for each phase.
  • Print the designed CFG used by the parser.
  • Provide a brief project report, including:
    • Simple pseudo-code or flowchart of the design.
    • Screenshots of mentioned inputs and outputs.

About

A compiler is a crucial tool in software development, it is like a translator for computer programs, converting high-level source code written by developers into machine code that computers can understand and execute. The process of compilation is divided into several phases, and the first three are particularly significant.


Languages

Language:C++ 75.8%Language:C 23.9%Language:Makefile 0.3%