Skip to content

This project is aimed at implementing a compiler for a subset of a programming language. It consists of two main phases: lexical analysis (Phase 1) and parsing (Phase 2).

Notifications You must be signed in to change notification settings

AbdullatifHabiba/Compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Project

Description

This project is aimed at implementing a compiler for a subset of a programming language. It consists of two main phases: lexical analysis (Phase 1) and parsing (Phase 2).

Phase 1 - Lexical Analysis

In Phase 1, the lexical analyzer is generated using a tool that constructs a lexical analyzer from a regular expression description of a set of tokens. Here's an overview of the process:

  1. Scanner: The Scanner class is responsible for scanning the input file and generating the NFA (Nondeterministic Finite Automaton) for the given regular expressions.
  2. NFA Conversion: The NFA is then converted to a DFA (Deterministic Finite Automaton) using the DFA class.
  3. Minimization: The DFA is minimized to optimize the lexical analyzer using the Minimize class.
  4. Matching: The generated DFA is used for matching tokens in the input file with the Matcher class.
  5. Token Extraction: The Matcher class extracts tokens and outputs them to a file.

Phase 2 - Parsing

In Phase 2, the generated lexical analyzer is integrated with the parser. Here's how it works:

  1. CFG (Context-Free Grammar) Reader: The CFGReader class reads the production rules from a file.
  2. Left Factoring and Left Recursion Elimination: The LL(1) grammar is generated by eliminating left factoring and left recursion using the LL1_Generator.
  3. Parsing Table Generation: The LL(1) parsing table is generated using the ParsingTable class.
  4. Parsing: The LL(1) parsing is performed using the Combiner class, which integrates the lexical analyzer with the parsing table.

Usage

  1. Compile the project.
  2. Run the executable, providing the input file path (input.txt) and the test file path (test.txt).

About

This project is aimed at implementing a compiler for a subset of a programming language. It consists of two main phases: lexical analysis (Phase 1) and parsing (Phase 2).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •