This repository contains solutions to a set of lexical analyzer assignments using Flex (Fast Lexical Analyzer Generator).
The project is organized into three separate questions/solutions:
- Q1: Word Count Analyzer
- Q2: Text Capitalizer
- Q3: Verb Recognizer
A lexical analyzer that counts the total number of words in a text file and calculates their combined size in characters.
Files:
verb_recognizer.1: The Flex source filelex.yy.c: The C code generated by Flexverb_recognizer: The compiled executableinput.txt: Sample input text for testing
Usage:
cd Q1
flex word_counter.1
gcc lex.yy.c -o word_counter -lfl
./verb_recognizer < input.txtA lexical analyzer that capitalizes text from the input.
Files:
capitalize.1: The Flex source file (binary)lex.yy.c: The C code generated by Flexinput.txt: Sample input text for testing
Usage:
cd Q2
flex capitalize.1
gcc lex.yy.c -o capitalize -lfl
./capitalize < input.txtA lexical analyzer that identifies and extracts common English verbs from text.
Files:
verb_recognizer.1: The Flex source filelex.yy.c: The C code generated by Flexinput.txt: Sample input text containing verbs for testing
Usage:
cd Q3
flex verb_recognizer.1
gcc lex.yy.c -o verb_recognizer -lfl
./verb_recognizer < input.txtEach solution can be compiled using the following general steps:
-
Generate C code from the Flex source file:
flex filename.l
-
Compile the generated C code:
gcc lex.yy.c -o output_name -lfl
-
Run the program with input:
./output_name < input.txt
- Flex (Fast Lexical Analyzer Generator)
- GCC (GNU Compiler Collection)
This project is provided for educational purposes.