Assignment in Automata Theory and Compiler Design
Assignment in Automata Theory and Compiler Design
Submitted by:
Sampada Sitaphale BE06F06F018
Contents:
Definition of Parsing
Definition of Parser
Overview of Parsing Process
Types of Parsers
Definition of Compiler-Compiler
Parser Generators
Definition of YACC
YACC Specification
YACC Grammar Rules
Advantages of YACC
Parsing:
%{
/* C declarations and includes */
%}
/* Yacc token and type declarations */
YACC Specification:
%%
/* Yacc Specification in the form of grammar rules */
symbol : symbols tokens
{ $$ = my_c_code($1); }
;
%%
/* C language program (the rest) */
| menu_item menu_items
but, due to the internals of yacc, this builds a less
memory-efficient parser.
Empty Rule
In case of a single menu_item, we can also accomodate
the optional DEFAULT keyword; by defining an empty
rule, like this:
Ex. menu_item : LABEL default EXEC '\n'
;
default : /* empty */
| DEFAULT
;
The comment /* empty */ is ignored by yacc, and can be
omitted.
Advantages of YACC:
A parser created using Lex quickly
becomes unmaintainable, as the number
of user-defined states tends to explode.
YACC can handle greater number of
user-defined states.
For inputs containing elements which are
context-sensitive, YACC has to be used.
◦ Ex. The '*' character in C
THANK YOU!