Compiler Lab
Compiler Lab
LEX is a tool used to generate lexical analyzers (scanners or tokenizers). These analyzers are programs
that process input text and convert it into a sequence of tokens, which are the building blocks for parsing
in compilers and interpreters.
Purpose: To automate the creation of a lexical analyzer based on predefined patterns of tokens.
Input: A specification file (typically .l extension) that defines:
Tokens: Regular expressions that represent patterns in the text.
Actions: Code snippets to execute when a token is recognized.
Output: A C program (usually lex.yy.c) that can be compiled and used as a tokenizer.
Flex is an improved, faster, and more modern version of LEX. It retains compatibility with LEX while
offering better performance and additional features.
Advantages over LEX:
Faster token recognition.
Generates more efficient C code.
Can interface seamlessly with tools like Bison (a parser generator).
Advantages of Flex
Applications
Bash ::::
b) Write a Lex program to count number of vowels and consonants in a given input string.
Bash :::::::::::::
Experiment 7
Bash::::::
b) Write a Lex program to printout all HTML tags in file.
Bash::::::::::::
c) Write a Lex program which adds line numbers to the given file and display the same onto the standard output.
Bash ::::::::::::::::::::
Experiment 8
Write a Lex program to count the number of comment lines in a given C program. Also eliminate them
and copy that program into separate file.
Experiment 9
Write a C program for implementing the functionalities of predictive parser for the mini language.
Experiment 10