0% found this document useful (0 votes)
83 views5 pages

Yacc

Uploaded by

bhushankawadar
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)
83 views5 pages

Yacc

Uploaded by

bhushankawadar
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/ 5

Chameli Devi Group of Institutions, Indore

Department of Computer Science & Engineering

Subject Presentation on
YACC

SUBMITTED TO : PRESENTED BY:


Mr. SUMEET KOTHARI Alfaiz Shaikh 0832CS211015
Alina khan 0832CS211016
Aman vishwakarma 0832CS211018
Amit Baghel 0832CS211019
2
of 10

YACC (Yet Another Compiler Compiler) is a powerful tool used in compiler design. Let’s delve into what YACC is
and how it fits into the world of language processing:

1.What is YACC?
• YACC is an LALR (1) (LookAhead, Left-to-right, Rightmost derivation producer with 1 lookahead
token) parser generator.
• It generates a bottom-up parser for a grammar-based language.
• Essentially, YACC helps create the syntactic analyzer (parser) for a language based on a given grammar.

2.How Does YACC Work?


• YACC takes as input a specification of a syntax (usually in the form of a set of production rules) and produces
as output a procedure for recognizing that language.
• Historically, YACC (as well as similar tools) was also called a “compiler compiler” because it generates code
that can be used to build a compiler for a specific language.

3.YACC Input File Structure:


• The YACC input file is divided into three parts:
• Definitions: This section includes information about the tokens used in the syntax definition. Tokens can be
user-defined or predefined.
• Rules: The rules part contains grammar definitions in a modified BNF (Backus-Naur Form) format. Each
rule specifies how to recognize a particular construct in the language.
• Auxiliary Routines: This section contains C code for auxiliary functions needed by the parser. It can also
include the main() function if the parser is intended to be run as a standalone program.
Example of YACC Usage:
•Suppose we want to create a parser for a simple arithmetic expression language with rules like:
expression : expression '+' term | expression '-' term | term term : term '*' factor | term '/' factor | factor factor :
NUMBER | '(' expression ')'
%{
%}

%%
Lines : Lines S '\n' { printf("OK \n"); }
| S '\n’
| error '\n' {yyerror("Error: reenter last line:");
yyerrok; };
S : '(' S ')’
| '[' S ']’
| /* empty */ ;
%%

#include "lex.yy.c"

void yyerror(char * s)
/* yacc error handler */
{
fprintf (stderr, "%s\n", s);
}

int main(void)
{
return yyparse();
}
This command converts the file translate.y into a C file
y.tab.c.
THANK YOU…….

You might also like