Monday 5 June 2017

What are three parts of Yacc program?


                YACC program consists of three sections: 
1. "Definitions", 
2. "Context Free Grammar and action for each production", 
3. "Subroutines/Functions"

               In first section, we can mention C language code which may consist of header files inclusion, global variables/ Constants definition/declaration. C language code can be mentioned in between the symbols %{ and %}.  Also we can define tokens in the first section. We can define the associativity of the operations (i.e. left associativity or right associativity). Priorities among the operators can also be specified.  

              In second section, we mention the grammar productions and the action for each production. 

             Third section consists of the subroutines. We have to call yyparse() to initiate the parsing process. yyerror() function is called when all productions in the grammar in second section do not match to the input statement.

No comments:

Post a Comment