SlideShare a Scribd company logo
1 of 27
LEX & YACC
Ms.Ashwini Jarali
Department of Computer Science
International Institute of Information Technology, I²IT
www.isquareit.edu.in
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
LEX & YACC
•What is Lex?
•Lex is officially known as a "Lexical Analyser".
•It's main job is to break up an input stream into more usable
elements.
• in, other words, to identify the "interesting bits" in a text file.
•For example, if you are writing a compiler for the C
programming language, the symbols { } ( ) ; all have
significance on their own. The letter a usually appears as part
of a keyword or variable name, and is not interesting on it's
own. Instead, we are interested in the whole word. Spaces and
newlines are completely uninteresting, and we want to ignore
them completely, unless they appear within quotes "like this“
•All of these things are handled by the Lexical Analyser.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
What is Yacc?
•Yacc is officially known as a "parser".
•YACC stands for "Yet Another Compiler Compiler". This is
because this kind of analysis of text files is normally
associated with writing compilers.
For example, a C program may contain something like:
{
int int; int = 33;
printf("int: %dn",int);
}
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
In this case, the lexical analyser would have broken the input stream into a
series of "tokens", like this:
{ int
int
;
int
=
33 ;
Printf ( "int: %dn" , int )
;
}
•Note that the lexical analyser has already determined that where the
keyword int appears within quotes, it is really just part of a litteral string.
•It is up to the parser to decide if the token int is being used as a keyword
or variable. Or it may choose to reject the use of the name int as a variable
name. The parser also ensures that each statement ends with a ; and that
the brackets balance.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Compilation Sequence
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•The patterns in the above diagram is a file you create with a text
editor. Lex will read your patterns and generate C code for a lexical
analyzer or scanner.
• The lexical analyzer matches strings in the input, based on your
patterns, and converts the strings to tokens.
•Tokens are numerical representations of strings, and simplify
processing.
•When the lexical analyzer finds identifiers in the input stream it
enters them in a symbol table.
•The grammar in the above diagram is a text file you create with a
text editor. Yacc will read your grammar and generate C code for a
syntax analyzer or parser.
•The syntax analyzer uses grammar rules that allow it to analyze
tokens from the lexical analyzer and create a syntax tree.
•The syntax tree imposes a hierarchical structure to the tokens.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Lex specifications:
A Lex program (the .l file) consists of three parts:
declarations
%%
translation rules
%%
Definition(User Subroutines)
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•auxiliary procedures
•The declarations section includes declarations of variables,
manifest constants and regular definitions.
•The translation rules of a Lex program are statements of the form :
p1 {action 1}
p2 {action 2}
…
•Where each p is a regular expression and each action is a program
fragment describing what action the lexical analyzer should take
when a pattern p matches a lexeme. In Lex the actions are written
in C.
•The third section holds whatever auxiliary procedures are needed
by the actions. Alternatively these procedures can be compiled
separately and loaded with the lexical analyzer.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Sample Lex program implementation to count the number of words.
/*lex program to count number of words*/
%{ /*Declaration section*/
#include<stdio.h>
#include<string.h>
int i = 0;
%}
/* Rules Section*/
%%
([a-zA-Z0-9])* {i++;} /* Rule for counting number of words*/
"n" {printf("%dn", i); i = 0;}
%%
int yywrap(void){}
int main()
{ // The function that starts the analysis
yylex(); return 0; }
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
/*lex program to count number of words, lines and characters */
%{ //declaration
int nchar, nword, nline;
%}
//rules
%%
n { nline++; nchar++; }
[^ tn]+ { nword++, nchar += yyleng; }
. { nchar++; }
%%
//defination
int main(void) {
yylex();
printf("%dt%dt%dn", nchar, nword, nline);
return 0;
}
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Lex Predefined Variables
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Pattern Matching Primitives
Pattern Matching Primitives
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Pattern Matching Examples
Pattern Matching Primitives
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
YACC
Pattern Matching Primitives
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Building a Compiler with Lex/Yacc
assume our goal is to write a BASIC compiler. First, we need to
specify all pattern matching rules for lex (bas.l) and
grammar rules for yacc (bas.y).
Commands to create our compiler, bas.exe, are listed below:
yacc –d bas.y # create y.tab.h, y.tab.c
lex bas.l # create lex.yy.c
cc lex.yy.c y.tab.c –o bas.exe # compile/link
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•Yacc reads the grammar descriptions in bas.y and generates a
syntax analyzer (parser), that includes function yyparse, in file
y.tab.c. Included in file bas.y are token declarations.
•The –d option causes yacc to generate definitions for tokens
and place them in file y.tab.h.
•Lex reads the pattern descriptions in bas.l, includes file
y.tab.h, and generates a lexical analyzer, that includes function
yylex, in file lex.yy.c.
•Finally, the lexer and parser are compiled and linked together
to create executable bas.exe.
•From main we call yyparse to run the compiler.
•Function yyparse automatically calls yylex to obtain each
token.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•YACC full specification file looks like:
declarations
%%
rules
%%
programs
•The declaration section may be empty
•The rules section is made up of one or more grammar rules. A
grammar rule has the BNF form:
A : BODY ;
Where A represents a nonterminal name, and BODY
represents a sequence of zero or more names and literals.
• The colon and the semicolon are Yacc punctuation.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•If there are several grammar rules with the same left hand
side, the vertical bar ``|'' can be used to avoid rewriting the left
hand side. Thus the grammar rules
A : B C D ;
A : E F ;
A : G ;
•can be given to Yacc as
A : B C D
| E F
| G ;
•If a nonterminal symbol matches the empty string, this can be
indicated in the obvious way:
empty : ;
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•Names representing tokens must be declared ;
this is most simply done by writing in the declarations section.
%token name1 name2 . . .
•Every name not defined in the declarations section is assumed
to represent a nonterminal symbol.
•Every nonterminal symbol must appear on the left side of at
least one rule.
•For recursive execution ,the grammar rule is :
A : Z|A Z;
Z:B C D
| E F
| G ;
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Sample YACC program which accept strings that starts and ends with 0
or 1
Lexical Analyzer Source Code (abc.l)
%{ /* Definition section */
extern int yylval;
%}
/* Rule Section */
%%
0 {yylval = 0; return ZERO;}
1 {yylval = 1; return ONE;}
.|n {yylval = 2; return 0;}
%%
/*Definition Section*/
#no need of Definition section here as it is input to Yacc program
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Parser Source Code : (abc.y)
%{ /* Definition section */
#include<stdio.h>
#include <stdlib.h>
void yyerror(const char *str)
{ printf("nSequence Rejectedn");
}
%}
%token ZERO ONE
/* Rule Section */
%%
r : s {printf("nSequence Acceptednn");}
;
s : n
| ZERO a
| ONE b
;
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Parser Source Code :(abc.y)
a : n a //Recursive
| ZERO
;
b : n b //Recursive
| ONE
;
n : ZERO
| ONE
;
%%
#include"lex.yy.c“ //driver code
int main()
{ printf("nEnter Sequence of Zeros and Ones : ");
yyparse(); printf("n");
return 0; }
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
Steps to execute Yacc Program
yacc –d abc.y # create y.tab.h, y.tab.c
lex abc.l # create lex.yy.c
cc lex.yy.c y.tab.c –o abc.exe # compile/link
./abc.exe #Execute
Output
01110 //Accepted
10001//Accepted
10000 //Rejected
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•Difference between LEX and YACC
•Lex is used to split the text into a list of tokens, what text become
token can be specified using regular expression in lex file.
•Yacc is used to give some structure to those tokens. For example
in Programming languages, we have assignment statements like
int a = 1 + 2; and i want to make sure that the left hand side of '='
be an identifier and the right side be an expression [it could be
more complex than this]. This can be coded using a CFG rule and
this is what you specify in yacc file and this you cannot do using
lex (lex cannot handle recursive languages).
•A typical application of lex and yacc is for implementing
programming languages.
•Lex tokenizes the input, breaking it up into keywords, constants,
punctuation, etc.
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
•Yacc then implements the actual computer language;
recognizing a for statement, for instance, or a function
definition.
•Lex and yacc are normally used together. This is how you
usually construct an application using both:
•Input Stream (characters) -> Lex (tokens) -> Yacc (Abstract
Syntax Tree) -> Your Application
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
References:
1. https://luv.asn.au/overheads/lex_yacc/index.ht
ml
2. https://www.ques10.com/p/9881/lex-and-
yacc-1/
3. https://www.cs.utexas.edu/users/novak/yaccp
aper.htm
4. https://www.geeksforgeeks.org/yacc-program-
which-accept-strings-that-starts-and-ends-
with-0-or-1/
5. LEX & YACC TUTORIAL by Tom Niemann
International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057
Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in
THANK-YOU
International Institute of Information Technology (I²IT)
P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1,
Hinjawadi, Pune – 411057, India
Email - info@isquareit.edu.in
Website - http://www.isquareit.edu.in/

More Related Content

What's hot (20)

Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Pass Structure of Assembler
Pass Structure of AssemblerPass Structure of Assembler
Pass Structure of Assembler
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Minimization of DFA.pptx
Minimization of DFA.pptxMinimization of DFA.pptx
Minimization of DFA.pptx
 
Assemblers
AssemblersAssemblers
Assemblers
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 

Similar to What Is LEX and YACC?

IRJET - Query Processing using NLP
IRJET - Query Processing using NLPIRJET - Query Processing using NLP
IRJET - Query Processing using NLPIRJET Journal
 
IRJET- Intelligent Laboratory Management System based on Internet of Thin...
IRJET-  	  Intelligent Laboratory Management System based on Internet of Thin...IRJET-  	  Intelligent Laboratory Management System based on Internet of Thin...
IRJET- Intelligent Laboratory Management System based on Internet of Thin...IRJET Journal
 

Similar to What Is LEX and YACC? (20)

Programming with LEX & YACC
Programming with LEX & YACCProgramming with LEX & YACC
Programming with LEX & YACC
 
Systems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACCSystems Programming & Operating Systems - Overview of LEX-and-YACC
Systems Programming & Operating Systems - Overview of LEX-and-YACC
 
Introduction To Assembly Language Programming
Introduction To Assembly Language ProgrammingIntroduction To Assembly Language Programming
Introduction To Assembly Language Programming
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
DAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & ApplicationDAA Introduction to Algorithms & Application
DAA Introduction to Algorithms & Application
 
Database Query Optimization
Database Query OptimizationDatabase Query Optimization
Database Query Optimization
 
Fundamentals of Computer Networks
Fundamentals of Computer NetworksFundamentals of Computer Networks
Fundamentals of Computer Networks
 
Introduction To Design Pattern
Introduction To Design PatternIntroduction To Design Pattern
Introduction To Design Pattern
 
DESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy PatternsDESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy Patterns
 
Understanding Natural Language Processing
Understanding Natural Language ProcessingUnderstanding Natural Language Processing
Understanding Natural Language Processing
 
Supervised Learning in Cybersecurity
Supervised Learning in CybersecuritySupervised Learning in Cybersecurity
Supervised Learning in Cybersecurity
 
IRJET - Query Processing using NLP
IRJET - Query Processing using NLPIRJET - Query Processing using NLP
IRJET - Query Processing using NLP
 
State Pattern: Introduction & Implementation
State Pattern: Introduction  & Implementation State Pattern: Introduction  & Implementation
State Pattern: Introduction & Implementation
 
What is DevOps?
What is DevOps?What is DevOps?
What is DevOps?
 
Register Organization of 80386
Register Organization of 80386Register Organization of 80386
Register Organization of 80386
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
Data Structure - Linked List
Data Structure - Linked ListData Structure - Linked List
Data Structure - Linked List
 
Big Data Technologies
Big Data TechnologiesBig Data Technologies
Big Data Technologies
 
Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)Adapter Pattern: Introduction & Implementation (with examples)
Adapter Pattern: Introduction & Implementation (with examples)
 
IRJET- Intelligent Laboratory Management System based on Internet of Thin...
IRJET-  	  Intelligent Laboratory Management System based on Internet of Thin...IRJET-  	  Intelligent Laboratory Management System based on Internet of Thin...
IRJET- Intelligent Laboratory Management System based on Internet of Thin...
 

More from International Institute of Information Technology (I²IT)

More from International Institute of Information Technology (I²IT) (20)

Minimization of DFA
Minimization of DFAMinimization of DFA
Minimization of DFA
 
What Is Smart Computing?
What Is Smart Computing?What Is Smart Computing?
What Is Smart Computing?
 
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
 
Writing Skills: Importance of Writing Skills
Writing Skills: Importance of Writing SkillsWriting Skills: Importance of Writing Skills
Writing Skills: Importance of Writing Skills
 
Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself Professional Communication | Introducing Oneself
Professional Communication | Introducing Oneself
 
Servlet: A Server-side Technology
Servlet: A Server-side TechnologyServlet: A Server-side Technology
Servlet: A Server-side Technology
 
What Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It WorksWhat Is Jenkins? Features and How It Works
What Is Jenkins? Features and How It Works
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Hypothesis-Testing
Hypothesis-TestingHypothesis-Testing
Hypothesis-Testing
 
Data Science, Big Data, Data Analytics
Data Science, Big Data, Data AnalyticsData Science, Big Data, Data Analytics
Data Science, Big Data, Data Analytics
 
Types of Artificial Intelligence
Types of Artificial Intelligence Types of Artificial Intelligence
Types of Artificial Intelligence
 
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
 
Sentiment Analysis in Machine Learning
Sentiment Analysis in  Machine LearningSentiment Analysis in  Machine Learning
Sentiment Analysis in Machine Learning
 
What Is Cloud Computing?
What Is Cloud Computing?What Is Cloud Computing?
What Is Cloud Computing?
 
Importance of Theory of Computations
Importance of Theory of ComputationsImportance of Theory of Computations
Importance of Theory of Computations
 
Java as Object Oriented Programming Language
Java as Object Oriented Programming LanguageJava as Object Oriented Programming Language
Java as Object Oriented Programming Language
 
What Is High Performance-Computing?
What Is High Performance-Computing?What Is High Performance-Computing?
What Is High Performance-Computing?
 
Data Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BIData Visualization - How to connect Microsoft Forms to Power BI
Data Visualization - How to connect Microsoft Forms to Power BI
 
AVL Tree Explained
AVL Tree ExplainedAVL Tree Explained
AVL Tree Explained
 
Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19Yoga To Fight & Win Against COVID-19
Yoga To Fight & Win Against COVID-19
 

Recently uploaded

COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxFarihaAbdulRasheed
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑Damini Dixit
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Servicemonikaservice1
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)Areesha Ahmad
 
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Joonhun Lee
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bSérgio Sacani
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxRizalinePalanog2
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencySheetal Arora
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxgindu3009
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPirithiRaju
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...ssuser79fe74
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsSérgio Sacani
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 

Recently uploaded (20)

COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
 
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts ServiceJustdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
Justdial Call Girls In Indirapuram, Ghaziabad, 8800357707 Escorts Service
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
Feature-aligned N-BEATS with Sinkhorn divergence (ICLR '24)
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Presentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptxPresentation Vikram Lander by Vedansh Gupta.pptx
Presentation Vikram Lander by Vedansh Gupta.pptx
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 

What Is LEX and YACC?

  • 1. LEX & YACC Ms.Ashwini Jarali Department of Computer Science International Institute of Information Technology, I²IT www.isquareit.edu.in
  • 2. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in LEX & YACC •What is Lex? •Lex is officially known as a "Lexical Analyser". •It's main job is to break up an input stream into more usable elements. • in, other words, to identify the "interesting bits" in a text file. •For example, if you are writing a compiler for the C programming language, the symbols { } ( ) ; all have significance on their own. The letter a usually appears as part of a keyword or variable name, and is not interesting on it's own. Instead, we are interested in the whole word. Spaces and newlines are completely uninteresting, and we want to ignore them completely, unless they appear within quotes "like this“ •All of these things are handled by the Lexical Analyser.
  • 3. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in What is Yacc? •Yacc is officially known as a "parser". •YACC stands for "Yet Another Compiler Compiler". This is because this kind of analysis of text files is normally associated with writing compilers. For example, a C program may contain something like: { int int; int = 33; printf("int: %dn",int); }
  • 4. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in In this case, the lexical analyser would have broken the input stream into a series of "tokens", like this: { int int ; int = 33 ; Printf ( "int: %dn" , int ) ; } •Note that the lexical analyser has already determined that where the keyword int appears within quotes, it is really just part of a litteral string. •It is up to the parser to decide if the token int is being used as a keyword or variable. Or it may choose to reject the use of the name int as a variable name. The parser also ensures that each statement ends with a ; and that the brackets balance.
  • 5. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Compilation Sequence
  • 6. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •The patterns in the above diagram is a file you create with a text editor. Lex will read your patterns and generate C code for a lexical analyzer or scanner. • The lexical analyzer matches strings in the input, based on your patterns, and converts the strings to tokens. •Tokens are numerical representations of strings, and simplify processing. •When the lexical analyzer finds identifiers in the input stream it enters them in a symbol table. •The grammar in the above diagram is a text file you create with a text editor. Yacc will read your grammar and generate C code for a syntax analyzer or parser. •The syntax analyzer uses grammar rules that allow it to analyze tokens from the lexical analyzer and create a syntax tree. •The syntax tree imposes a hierarchical structure to the tokens.
  • 7. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Lex specifications: A Lex program (the .l file) consists of three parts: declarations %% translation rules %% Definition(User Subroutines)
  • 8. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •auxiliary procedures •The declarations section includes declarations of variables, manifest constants and regular definitions. •The translation rules of a Lex program are statements of the form : p1 {action 1} p2 {action 2} … •Where each p is a regular expression and each action is a program fragment describing what action the lexical analyzer should take when a pattern p matches a lexeme. In Lex the actions are written in C. •The third section holds whatever auxiliary procedures are needed by the actions. Alternatively these procedures can be compiled separately and loaded with the lexical analyzer.
  • 9. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Sample Lex program implementation to count the number of words. /*lex program to count number of words*/ %{ /*Declaration section*/ #include<stdio.h> #include<string.h> int i = 0; %} /* Rules Section*/ %% ([a-zA-Z0-9])* {i++;} /* Rule for counting number of words*/ "n" {printf("%dn", i); i = 0;} %% int yywrap(void){} int main() { // The function that starts the analysis yylex(); return 0; }
  • 10. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in /*lex program to count number of words, lines and characters */ %{ //declaration int nchar, nword, nline; %} //rules %% n { nline++; nchar++; } [^ tn]+ { nword++, nchar += yyleng; } . { nchar++; } %% //defination int main(void) { yylex(); printf("%dt%dt%dn", nchar, nword, nline); return 0; }
  • 11. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Lex Predefined Variables
  • 12. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Pattern Matching Primitives Pattern Matching Primitives
  • 13. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Pattern Matching Examples Pattern Matching Primitives
  • 14. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in YACC Pattern Matching Primitives
  • 15. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Building a Compiler with Lex/Yacc assume our goal is to write a BASIC compiler. First, we need to specify all pattern matching rules for lex (bas.l) and grammar rules for yacc (bas.y). Commands to create our compiler, bas.exe, are listed below: yacc –d bas.y # create y.tab.h, y.tab.c lex bas.l # create lex.yy.c cc lex.yy.c y.tab.c –o bas.exe # compile/link
  • 16. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •Yacc reads the grammar descriptions in bas.y and generates a syntax analyzer (parser), that includes function yyparse, in file y.tab.c. Included in file bas.y are token declarations. •The –d option causes yacc to generate definitions for tokens and place them in file y.tab.h. •Lex reads the pattern descriptions in bas.l, includes file y.tab.h, and generates a lexical analyzer, that includes function yylex, in file lex.yy.c. •Finally, the lexer and parser are compiled and linked together to create executable bas.exe. •From main we call yyparse to run the compiler. •Function yyparse automatically calls yylex to obtain each token.
  • 17. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •YACC full specification file looks like: declarations %% rules %% programs •The declaration section may be empty •The rules section is made up of one or more grammar rules. A grammar rule has the BNF form: A : BODY ; Where A represents a nonterminal name, and BODY represents a sequence of zero or more names and literals. • The colon and the semicolon are Yacc punctuation.
  • 18. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •If there are several grammar rules with the same left hand side, the vertical bar ``|'' can be used to avoid rewriting the left hand side. Thus the grammar rules A : B C D ; A : E F ; A : G ; •can be given to Yacc as A : B C D | E F | G ; •If a nonterminal symbol matches the empty string, this can be indicated in the obvious way: empty : ;
  • 19. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •Names representing tokens must be declared ; this is most simply done by writing in the declarations section. %token name1 name2 . . . •Every name not defined in the declarations section is assumed to represent a nonterminal symbol. •Every nonterminal symbol must appear on the left side of at least one rule. •For recursive execution ,the grammar rule is : A : Z|A Z; Z:B C D | E F | G ;
  • 20. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Sample YACC program which accept strings that starts and ends with 0 or 1 Lexical Analyzer Source Code (abc.l) %{ /* Definition section */ extern int yylval; %} /* Rule Section */ %% 0 {yylval = 0; return ZERO;} 1 {yylval = 1; return ONE;} .|n {yylval = 2; return 0;} %% /*Definition Section*/ #no need of Definition section here as it is input to Yacc program
  • 21. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Parser Source Code : (abc.y) %{ /* Definition section */ #include<stdio.h> #include <stdlib.h> void yyerror(const char *str) { printf("nSequence Rejectedn"); } %} %token ZERO ONE /* Rule Section */ %% r : s {printf("nSequence Acceptednn");} ; s : n | ZERO a | ONE b ;
  • 22. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Parser Source Code :(abc.y) a : n a //Recursive | ZERO ; b : n b //Recursive | ONE ; n : ZERO | ONE ; %% #include"lex.yy.c“ //driver code int main() { printf("nEnter Sequence of Zeros and Ones : "); yyparse(); printf("n"); return 0; }
  • 23. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in Steps to execute Yacc Program yacc –d abc.y # create y.tab.h, y.tab.c lex abc.l # create lex.yy.c cc lex.yy.c y.tab.c –o abc.exe # compile/link ./abc.exe #Execute Output 01110 //Accepted 10001//Accepted 10000 //Rejected
  • 24. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •Difference between LEX and YACC •Lex is used to split the text into a list of tokens, what text become token can be specified using regular expression in lex file. •Yacc is used to give some structure to those tokens. For example in Programming languages, we have assignment statements like int a = 1 + 2; and i want to make sure that the left hand side of '=' be an identifier and the right side be an expression [it could be more complex than this]. This can be coded using a CFG rule and this is what you specify in yacc file and this you cannot do using lex (lex cannot handle recursive languages). •A typical application of lex and yacc is for implementing programming languages. •Lex tokenizes the input, breaking it up into keywords, constants, punctuation, etc.
  • 25. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in •Yacc then implements the actual computer language; recognizing a for statement, for instance, or a function definition. •Lex and yacc are normally used together. This is how you usually construct an application using both: •Input Stream (characters) -> Lex (tokens) -> Yacc (Abstract Syntax Tree) -> Your Application
  • 26. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in References: 1. https://luv.asn.au/overheads/lex_yacc/index.ht ml 2. https://www.ques10.com/p/9881/lex-and- yacc-1/ 3. https://www.cs.utexas.edu/users/novak/yaccp aper.htm 4. https://www.geeksforgeeks.org/yacc-program- which-accept-strings-that-starts-and-ends- with-0-or-1/ 5. LEX & YACC TUTORIAL by Tom Niemann
  • 27. International Institute of Information Technology, I²IT, P-14, Rajiv Gandhi Infotech Park, Hinjawadi Phase 1, Pune - 411 057 Phone - +91 20 22933441/2/3 | Website - www.isquareit.edu.in | Email - info@isquareit.edu.in THANK-YOU International Institute of Information Technology (I²IT) P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1, Hinjawadi, Pune – 411057, India Email - info@isquareit.edu.in Website - http://www.isquareit.edu.in/