0% found this document useful (0 votes)
93 views13 pages

YACC - Compiler Design

The document discusses YACC, which is a tool that generates parsers. YACC takes a grammar specification as input and generates code for a parser. It has declarations, translation rules, and supporting C rules sections. YACC works with Lex to generate a lexical analyzer and parser from specifications. The document provides details on the working, syntax, and functions used in YACC and Lex/YACC programs.

Uploaded by

Aarthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views13 pages

YACC - Compiler Design

The document discusses YACC, which is a tool that generates parsers. YACC takes a grammar specification as input and generates code for a parser. It has declarations, translation rules, and supporting C rules sections. YACC works with Lex to generate a lexical analyzer and parser from specifications. The document provides details on the working, syntax, and functions used in YACC and Lex/YACC programs.

Uploaded by

Aarthi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPILER DESIGN

YACC

Harishkumar J

Sathyapriya R
TOPICS

Working of
Definition
YACC

Lex with YACC Execution


DEFINITION:

YACC is a tool which generates parser generator (LALR).

It is an automated tool for syntax analyzer.

YACC takes grammar as specification.


WORKING OF YACC:
SYNTAX:

Declarations
%%
Translation rules
%%
Supporting C rules
Declarations Part
• This part of YACC has two sections; both are optional. The first section has ordinary C
declarations, which is delimited by %{ and %}. Any temporary variable used by the
second and third sections will be kept in this part.
Translation Rule Part
• After the first %% pair in the YACC specification part, we place the translation rules.
Every rule has a grammar production and the associated semantic action.
Supporting C–Rules
• It is the last part of the YACC specification and should provide a lexical analyzer
named yylex(). These produced tokens have the token's name and are associated with
its attribute value. Whenever any token like DIGIT is returned, the returned token name
should have been declared in the first part of the YACC specification.
LEX WITH YACC :

output
ALGORITHM:
• Flex (lexical analyzer) recognizes the input tokens based on the regular
expressions defined in calc.l. It recognizes numbers and whitespace
characters.
• Bison (parser generator) defines the grammar rules and actions for
parsing and evaluating arithmetic expressions. It generates a parser
(yyparse()) based on the rules defined in calc.y.
• In Bison file (calc.y), we define the precedence and associativity of
operators using %left and %token directives.
• In the main() function, you prompt the user to enter an arithmetic
expression, then call yyparse() to parse and evaluate it.
FUNCTIONS USED:
yywrap() – Indicate the end of the input
yyparse()
 calls the yylex(), whenever the parser needs the next token in input.
 Read the token, matches against grammar rules and execute actions.
yylex() – read input, match against patterns (RE) and returns tokens or perform
actions.
yyerror() – Report syntax errors during process.
atoi() – convert a string representing an integer into an integer value.

yytext - holds the corresponding substring when a pattern is matched in the input
PROGRAM:
Lex program : YACC program :
DOWNLOAD :
https://gnuwin32.sourceforge.net/packages.html
HTTP://MARIN.JB.FREE.FR/BISON/
EXECUTION:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy