This repository contains Lex programs Compiler Design Lab using **Lex** and **Bison**.
This program identifies tokens in C language source code, including:
- Keywords
- Identifiers
- Operators
- Constants (Int, Float, Character)
- Special Symbols
- Strings
The Lex program reads a text as input and categorizes the tokens accordingly.
This Lex program processes a question paper text and provides the following analysis:
1. Count the number of questions.
2. Identify how many questions have sub-parts and how many do not.
3. Count the total marks mentioned for each question.
4. Extract the date of the examination.
5. Extract the semester information.
6. Count different types of questions (e.g., What, Discuss, etc.).
7. Count various statistics like the number of words, lines, small letters, capital letters, digits, and special characters.
Sample Question Paper Input:
Shri Ramdeobaba College of Engineering and Management
Sem: VI
12/12/2024
Solve as per questions.
Q1(a): What is a compiler? [5Marks]
Q1(b): What is a software? [5Marks]
Q2(a): Explain the need for an assembler. [3Marks]
Q2(b): Discuss phases of compiler. [2Marks]
Q3: What is a parser? [5Marks]
Q4(a): What is error correction? [2Marks]
Q4(b): Explain SDTS. [3Marks]
This Lex program removes comments (both single-line and multi-line) from a C program.
The input is a C program, and the output is the same C program with comments removed.
This Lex program processes the contents of a file and performs the following tasks:
- Add 3 to numbers divisible by 7.
- Add 4 to numbers divisible by 2.
- Convert an alphabetical list to a numbered list.
Sample Input:
14
16
a) Bread
b) Butter
c) Magnets
d) Paint Brush
- Lex (Flex) must be installed on your system.
- Yacc (Bison) must be installed on your system.
-
Download setup files:
- Flex: Download here
- Bison:Download here
Install both inC:\GnuWin32(not the default path).
-
Download C Setup (Dev-C++): Download Dev-C++
Install inC:\Dev-Cpp. -
Add to PATH variable: Add these paths to the PATH environment variable:
C:\GnuWin32\binC:\Dev-Cpp\MinGW64\binC:\Dev-Cpp\MinGW64\libexec\gcc\x86_64-w64-mingw32\4.9.2C:\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin
-
Check installation:
- Open Control Panel → System → Advanced System Settings → Environment Variables → Edit.
- Open Notepad and paste the given code, then save as
filename.l(select "All Files" as the type).
-
Run and check:
- Open Command Prompt and type
cmd. - Change directory to where
filename.lis saved. - Run:
flex filename.l. - Then compile:
gcc lex.yy.c. - Run the output executable:
a.exeand type any word to check.
- Open Command Prompt and type
- Open Terminal.
- Update:
sudo apt-get update - Install flex and bison:
sudo apt-get install flex
sudo apt-get install bison - Check installation:
- Open a text editor:
gedit filename.l - Write and save the code
- Compile with LEX:
flex filename.l - Run C:
gcc lex.yy.c –lfl - Run final output:
./a.out - Type input and if it gives output, installation is successful.
- Exit with
Ctrl + Z.
- Open a text editor:
- Clone this repository to your local machine:
git clone https://github.com/vaishnavipaswan/Compiler-Design-Lab-CSP327.git cd Compiler-Design-Lab-CSP327