Overview-Lex and Yacc Program
Overview-Lex and Yacc Program
Overview-Lex and Yacc Program
• Definitions
• Rules
• Auxiliary functions
Definition Section
• C source code, include header files, etc.
• %token
• Yacc invokes yylex() when a token is required.
• All terminal symbols should be declared
through %token.
• Yacc produces y.tab.h by %token definitions.
Syntax-YACC Program
• Definitions | Declarations
%token
%%
• Rules
Head:body1 {action1} | body2 {action2}
%%
• Auxiliary functions
• C source code, include files, etc.
• %token
• Yacc invokes yylex() when a token is required.
• All terminal symbols should be declared
through %token.
• Yacc produces y.tab.h by %token definitions.
Variables and functions used in YACC program
1) yytext-pointer to the input character stream or matched input
string.
2) yylval: values associated with the tokens are returned by Lex in the
variable yylval.
Ex: yyval= a to i (yytext)
converts string to int and stores in variable yyval.
1) lex bas.l
2) yacc -d bas.y
3) gcc lex.yy.c y.tab.c -ll
4) ./a.out