Skip to content

khalil-hamidani/Compiler

Repository files navigation

Mini Compiler Project Description

This project is a mini compiler built using Flex and Bison to perform lexical, syntax, and semantic analysis. The compiler is written with the help of flex , bison and the C programming language.

♾️ Overview

The mini compiler reads input source code, performs lexical analysis to identify tokens, parses the tokens to check for syntax errors, and performs semantic analysis to check for semantic errors.

The input source code is written in a simplified programming language that includes basic data types, arithmetic and logical operators, conditional statements, loops, and functions. The output of the compiler is a symbol table in the terminal.

♾️ Lexical Analysis

Lexical analysis is the process of breaking down the input source code into a sequence of tokens. Each token represents a meaningful sequence of characters in the source code, such as keywords, identifiers, constants, and operators.

The Flex tool is used to generate a lexer, which reads the input source code and identifies the tokens based on regular expressions. The lexer generates a stream of tokens, which is passed to the parser for syntax analysis.

♾️ Syntax Analysis

Syntax analysis is the process of checking the sequence of tokens generated by the lexer against a grammar that defines the syntax rules of the programming language using bison. The grammar is defined using Bison, which generates a parser that reads the stream of tokens and builds a parse tree.

♾️ Semantic Analysis

Semantic analysis is the process of checking the meaning of the input source code based on the context in which it is used. The semantic analyzer checks for semantic errors, such as type mismatches, undeclared variables, and invalid function calls with the help of C programming language.

♾️ Conclusion

This mini compiler project demonstrates the use of Flex and Bison to perform lexical, syntax, and semantic analysis of input source code written in a simplified programming language. The project also shows how C programming language can be used to implement a compiler.