[go: up one dir, main page]

0% found this document useful (0 votes)
131 views3 pages

Experiment No:-2 AIM:-Study of YACC Tools. Yacc

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

EXPERIMENT NO:-2

AIM:-Study of YACC tools.

YACC
 YACC stands for Yet Another Compiler Compiler.
 YACC provides a tool to produce a parser for a given grammar.
 YACC is a program designed to compile a LALR (1) grammar.
 It is used to produce the source code of the syntactic analyzer of the language
produced by LALR (1) grammar.
 The input of YACC is the rule or grammar and the output is a C program.

These are some points about YACC:


Input: A CFG- file.y
Output: A parser y.tab.c (yacc)
 The output file "file.output" contains the parsing tables.
 The file "file.tab.h" contains declarations.
 The parser called the yyparse ().
 Parser expects to use a function called yylex () to get tokens.

The basic operational sequence is as follows:

This file contains the desired grammar in YACC format.


It shows the YACC program.

It is the c source program created by YACC.

C Compiler

Executable file that will parse grammar given in gram.Y


How does this yacc works?

 yacc is designed for use with C code and generates a parser written in C.
 The parser is configured for use in conjunction with a lex-generated scanner and relies
on standard shared features (token types, yylval, etc.) and calls the function yylex as a
scanner coroutine.
 You provide a grammar specification file, which is traditionally named using a .y
extension.
 You invoke yacc on the .y file and it creates the y.tab.h and y.tab.c files containing a
thousand or so lines of intense C code that implements an efficient LALR (1) parser
for your grammar, including the code for the actions you specified.
 The file provides an extern function yyparse.y that will attempt to successfully parse a
valid sentence.
 You compile that C file normally, link with the rest of your code, and you have a
parser! By default, the parser reads from stdin and writes to stdout, just like a lex-
generated scanner does.

You might also like