SlideShare a Scribd company logo
COMPILER DESIGN
YACC:Yet Another Compiler -Compiler
YACC: Yet Another Compiler-Compiler
• Yacc generates C code for syntax analyzer, of parser.
• Yacc uses grammar rules that allow it to analyze tokens from LEX
and create a syntax tree.
• Yacc provides a general tool for describing the input to a
computer program.
• The Yacc user specifies the structures of his input, together with
code to be invoked as each such structure is recognized.
• Yacc is written in portable C.
• The class of specifications accepted is a very general one: LALR
grammars with disambiguating rules.
• In addition to compilers for C, APL, Pascal, RATFOR, etc., Yacc
has also been used for less conventional languages, including a
phototypesetter language, several desk calculator languages, a
document retrieval system, and a Fortran debugging system.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
2
Yacc contd…….
• Yacc is a computer program for the Unix operating system.
• It is a Look Ahead Left-to-Right (LALR) parser generator,
generating a parser.
• The part of a compiler that tries to make syntactic sense of
the source code, specifically a LALR parser, based on an analytic
grammar written in a notation similar to Backus–Naur Form
(BNF).
• Yacc was originally developed in the early 1970s by Stephen C.
Johnson at AT&T Corporation and written in the B programming
language, but soon rewritten in C.
• Yacc has also been rewritten for other languages, including
OCaml, Ratfor, ML, Ada, Pascal, Java, Python, Ruby, Go and Com
mon Lisp.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
3
4
yacc
Generate a new parser code from grammar
YACC source (*.y)
y.tab.h
y.tab.c
C compiler/linker
Compile a new parser
y.tab.c a.out
a.out
Parse source code
Token stream
Abstract
Syntax
Tree
y.output
How Does YACC Work?
PLLab, NTHU,Cs2403 Programming
Languages
5
Lex with Yacc
Lex Yacc
yylex() yyparse()
Lex source
(Lexical Rules)
Yacc source
(Grammar Rules)
Input
Parsed
Input
Lex Source
(Lexical Rules)
Yacc Source
(Grammar Rules)
y.tab.clex.yy.c call
Parsed
Input
Input
Return token
LALR PARSER GENERATOR-yacc
• The tool yacc can be used to generate automatically
an LALR parser.
• Input of yacc is divided into three sections:
………..definitions………..
%%
…..rules…..
%%
…….subroutines………..
The def section consists of token declarations & C code
bracketed by % { and % }.
The grammar is placed in the rules section, &
User subroutines are added in subroutines section.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
6
Example- small calculator
• The def section for the yacc input file:
%token INTEGER
This def declares an INTEGER token. When we
run yacc, it generates a parser file y.tab.c & also
creates an include file y.tab.h:
#ifndef YYSTYPE
#define YYSTYPE int
#endif
#define INTEGER 258
extern YYSTYPE yylval;
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
7
Contd……
• Lex includes this file & utilizes the definitions for token values.
• To obtain tokens, yacc calls yylex.
• Function yylex has a return type of int & returns the token value.
• Attributes associated with the token are returned by lex in variable
yylval.
File Content
calc.lex Specifies the lex command specification file that defines the
lexical analysis rules.
calc.yacc Specifies the yacc command grammar file that defines the
parsing rules, and calls the yylex subroutine created by
the lex command to provide input.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
8
Free APL Compilers and Interpreters
• ELI
ELI is an array programming language that has most of the
features of APL with additional ones not present in the language.
• NGN APL
This is an APL written in JavaScript. (Actually, it is written in
Coffee Script, which compiles to JavaScript.)
• NARS2000
NARS2000 (where NARS stands for Nested Arrays Research
System) is an experimental APL interpreter used as a test bed for
new ideas in the language.
• J
J is a programming language in the APL language family. Unlike
APL, it uses ASCII characters.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
9
Contd…….
• A+
According to its website, "A+ is a descendent of the language 'A'". Unlike
APL, A+ is "geared" to business, supporting large capacity and high
performance, with the "+" referring to the "electric graphical user
interface". It is released under the GNU General Public License.
Supported platforms include Linux, FreeBSD, AIX, IRIX, Mac OS X,
NetBSD, Solaris, and Tru64.
• OpenAPL
This package, for Linux, FreeBSD, OpenBSD, Mac OS X, and POSIX/Unix-
like systems, includes the APL font as well as the interpreter for APL11.
We will have to compile it from the sources provided.
• APL Special Edition
APLSE is a freeware version of APL*Plus PC, a compiler for the APL
programming language, a highly symbolic language (ie, it uses pictorial
symbols rather than the traditional English words) and compact
language.
1/31/2017
ANKUR SRIVASTAVA ASSISTANT PROFESSOR
JIT
10
THANKS

More Related Content

What's hot

Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
Radhakrishnan Chinnusamy
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
Dattatray Gandhmal
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
SRS(software requirement specification)
SRS(software requirement specification)SRS(software requirement specification)
SRS(software requirement specification)
Akash Kumar Dhameja
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
sanchi29
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
josemachoco
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
FellowBuddy.com
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
SOMNATHMORE2
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Assemblers
AssemblersAssemblers
Assemblers
Dattatray Gandhmal
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
Satyamevjayte Haxor
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 

What's hot (20)

Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
SRS(software requirement specification)
SRS(software requirement specification)SRS(software requirement specification)
SRS(software requirement specification)
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Assemblers
AssemblersAssemblers
Assemblers
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 

Viewers also liked

Yacc lex
Yacc lexYacc lex
Yacc lex
915086731
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
pssraikar
 
Passescd
PassescdPassescd
Passescd
BBDITM LUCKNOW
 
Lex
LexLex
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
BBDITM LUCKNOW
 
Yacc
YaccYacc
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabus
JK Knowledge
 
Flex y Bison
Flex y BisonFlex y Bison
Flex y Bison
Bryant Arellano
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
Sarmad Ali
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)bolovv
 
Meta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student VersionMeta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student Version
Kelly Bauer
 
Minimization of dfa
Minimization of dfaMinimization of dfa
Minimization of dfa
BBDITM LUCKNOW
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IVManoj Patil
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
patchamounika7
 
Parsing example
Parsing exampleParsing example
Parsing example
Shraddha Patel
 

Viewers also liked (20)

Yacc lex
Yacc lexYacc lex
Yacc lex
 
Lex and Yacc ppt
Lex and Yacc pptLex and Yacc ppt
Lex and Yacc ppt
 
Passescd
PassescdPassescd
Passescd
 
Lex
LexLex
Lex
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Yacc
YaccYacc
Yacc
 
Yacc topic beyond syllabus
Yacc   topic beyond syllabusYacc   topic beyond syllabus
Yacc topic beyond syllabus
 
Cimplementation
CimplementationCimplementation
Cimplementation
 
Ch4c
Ch4cCh4c
Ch4c
 
Flex y Bison
Flex y BisonFlex y Bison
Flex y Bison
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Lexyacc
LexyaccLexyacc
Lexyacc
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Meta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student VersionMeta Languages Bnf Ebnf Student Version
Meta Languages Bnf Ebnf Student Version
 
Minimization of dfa
Minimization of dfaMinimization of dfa
Minimization of dfa
 
System Programming Unit IV
System Programming Unit IVSystem Programming Unit IV
System Programming Unit IV
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Parsing example
Parsing exampleParsing example
Parsing example
 

Similar to Yacc

Structure-Compiler-phases information about basics of compiler. Pdfpdf
Structure-Compiler-phases information  about basics of compiler. PdfpdfStructure-Compiler-phases information  about basics of compiler. Pdfpdf
Structure-Compiler-phases information about basics of compiler. Pdfpdf
ovidlivi91
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
MashaelQ
 
Oracle sun studio
Oracle sun studioOracle sun studio
Oracle sun studio
Kamesh Waran
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan
 
Ch1 (1).ppt
Ch1 (1).pptCh1 (1).ppt
Ch1 (1).ppt
MDSayem35
 
Viva
VivaViva
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
Apoorv Diwan
 
Group 19 CD project
Group 19 CD projectGroup 19 CD project
Group 19 CD project
DushyantSharma146
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Mohammad Hossein Rimaz
 
11700220036.pdf
11700220036.pdf11700220036.pdf
11700220036.pdf
SouvikRoy149
 
CD U1-5.pptx
CD U1-5.pptxCD U1-5.pptx
CD U1-5.pptx
Himajanaidu2
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 

Similar to Yacc (20)

Structure-Compiler-phases information about basics of compiler. Pdfpdf
Structure-Compiler-phases information  about basics of compiler. PdfpdfStructure-Compiler-phases information  about basics of compiler. Pdfpdf
Structure-Compiler-phases information about basics of compiler. Pdfpdf
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
Oracle sun studio
Oracle sun studioOracle sun studio
Oracle sun studio
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...Using ANTLR on real example - convert "string combined" queries into paramete...
Using ANTLR on real example - convert "string combined" queries into paramete...
 
Ch1 (1).ppt
Ch1 (1).pptCh1 (1).ppt
Ch1 (1).ppt
 
Compiler1
Compiler1Compiler1
Compiler1
 
Viva
VivaViva
Viva
 
Viva
VivaViva
Viva
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Group 19 CD project
Group 19 CD projectGroup 19 CD project
Group 19 CD project
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
11700220036.pdf
11700220036.pdf11700220036.pdf
11700220036.pdf
 
CD U1-5.pptx
CD U1-5.pptxCD U1-5.pptx
CD U1-5.pptx
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 
Introduction
IntroductionIntroduction
Introduction
 

More from BBDITM LUCKNOW

Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
BBDITM LUCKNOW
 
Unit 4 cspc
Unit 4 cspcUnit 4 cspc
Unit 4 cspc
BBDITM LUCKNOW
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
BBDITM LUCKNOW
 
Cse ppt 2018
Cse ppt 2018Cse ppt 2018
Cse ppt 2018
BBDITM LUCKNOW
 
Binary system ppt
Binary system pptBinary system ppt
Binary system ppt
BBDITM LUCKNOW
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
BBDITM LUCKNOW
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
BBDITM LUCKNOW
 
Unit 2 ca- control unit
Unit 2 ca- control unitUnit 2 ca- control unit
Unit 2 ca- control unit
BBDITM LUCKNOW
 
Unit 1 ca-introduction
Unit 1 ca-introductionUnit 1 ca-introduction
Unit 1 ca-introduction
BBDITM LUCKNOW
 
Bnf and ambiquity
Bnf and ambiquityBnf and ambiquity
Bnf and ambiquity
BBDITM LUCKNOW
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
BBDITM LUCKNOW
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
BBDITM LUCKNOW
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
BBDITM LUCKNOW
 
Cspc final
Cspc finalCspc final
Cspc final
BBDITM LUCKNOW
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
BBDITM LUCKNOW
 

More from BBDITM LUCKNOW (15)

Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
 
Unit 4 cspc
Unit 4 cspcUnit 4 cspc
Unit 4 cspc
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
Cse ppt 2018
Cse ppt 2018Cse ppt 2018
Cse ppt 2018
 
Binary system ppt
Binary system pptBinary system ppt
Binary system ppt
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
 
Unit 2 ca- control unit
Unit 2 ca- control unitUnit 2 ca- control unit
Unit 2 ca- control unit
 
Unit 1 ca-introduction
Unit 1 ca-introductionUnit 1 ca-introduction
Unit 1 ca-introduction
 
Bnf and ambiquity
Bnf and ambiquityBnf and ambiquity
Bnf and ambiquity
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
Cspc final
Cspc finalCspc final
Cspc final
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Yacc

  • 1. COMPILER DESIGN YACC:Yet Another Compiler -Compiler
  • 2. YACC: Yet Another Compiler-Compiler • Yacc generates C code for syntax analyzer, of parser. • Yacc uses grammar rules that allow it to analyze tokens from LEX and create a syntax tree. • Yacc provides a general tool for describing the input to a computer program. • The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized. • Yacc is written in portable C. • The class of specifications accepted is a very general one: LALR grammars with disambiguating rules. • In addition to compilers for C, APL, Pascal, RATFOR, etc., Yacc has also been used for less conventional languages, including a phototypesetter language, several desk calculator languages, a document retrieval system, and a Fortran debugging system. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 2
  • 3. Yacc contd……. • Yacc is a computer program for the Unix operating system. • It is a Look Ahead Left-to-Right (LALR) parser generator, generating a parser. • The part of a compiler that tries to make syntactic sense of the source code, specifically a LALR parser, based on an analytic grammar written in a notation similar to Backus–Naur Form (BNF). • Yacc was originally developed in the early 1970s by Stephen C. Johnson at AT&T Corporation and written in the B programming language, but soon rewritten in C. • Yacc has also been rewritten for other languages, including OCaml, Ratfor, ML, Ada, Pascal, Java, Python, Ruby, Go and Com mon Lisp. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 3
  • 4. 4 yacc Generate a new parser code from grammar YACC source (*.y) y.tab.h y.tab.c C compiler/linker Compile a new parser y.tab.c a.out a.out Parse source code Token stream Abstract Syntax Tree y.output How Does YACC Work?
  • 5. PLLab, NTHU,Cs2403 Programming Languages 5 Lex with Yacc Lex Yacc yylex() yyparse() Lex source (Lexical Rules) Yacc source (Grammar Rules) Input Parsed Input Lex Source (Lexical Rules) Yacc Source (Grammar Rules) y.tab.clex.yy.c call Parsed Input Input Return token
  • 6. LALR PARSER GENERATOR-yacc • The tool yacc can be used to generate automatically an LALR parser. • Input of yacc is divided into three sections: ………..definitions……….. %% …..rules….. %% …….subroutines……….. The def section consists of token declarations & C code bracketed by % { and % }. The grammar is placed in the rules section, & User subroutines are added in subroutines section. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 6
  • 7. Example- small calculator • The def section for the yacc input file: %token INTEGER This def declares an INTEGER token. When we run yacc, it generates a parser file y.tab.c & also creates an include file y.tab.h: #ifndef YYSTYPE #define YYSTYPE int #endif #define INTEGER 258 extern YYSTYPE yylval; 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 7
  • 8. Contd…… • Lex includes this file & utilizes the definitions for token values. • To obtain tokens, yacc calls yylex. • Function yylex has a return type of int & returns the token value. • Attributes associated with the token are returned by lex in variable yylval. File Content calc.lex Specifies the lex command specification file that defines the lexical analysis rules. calc.yacc Specifies the yacc command grammar file that defines the parsing rules, and calls the yylex subroutine created by the lex command to provide input. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 8
  • 9. Free APL Compilers and Interpreters • ELI ELI is an array programming language that has most of the features of APL with additional ones not present in the language. • NGN APL This is an APL written in JavaScript. (Actually, it is written in Coffee Script, which compiles to JavaScript.) • NARS2000 NARS2000 (where NARS stands for Nested Arrays Research System) is an experimental APL interpreter used as a test bed for new ideas in the language. • J J is a programming language in the APL language family. Unlike APL, it uses ASCII characters. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 9
  • 10. Contd……. • A+ According to its website, "A+ is a descendent of the language 'A'". Unlike APL, A+ is "geared" to business, supporting large capacity and high performance, with the "+" referring to the "electric graphical user interface". It is released under the GNU General Public License. Supported platforms include Linux, FreeBSD, AIX, IRIX, Mac OS X, NetBSD, Solaris, and Tru64. • OpenAPL This package, for Linux, FreeBSD, OpenBSD, Mac OS X, and POSIX/Unix- like systems, includes the APL font as well as the interpreter for APL11. We will have to compile it from the sources provided. • APL Special Edition APLSE is a freeware version of APL*Plus PC, a compiler for the APL programming language, a highly symbolic language (ie, it uses pictorial symbols rather than the traditional English words) and compact language. 1/31/2017 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JIT 10