Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)

User Commands (v - z) yacc(1)
Denes the operators and their precedence.
Rules Section
The rules section denes the rules that parse the input stream.
Programs Section
The programs section contains the following routines. Because these routines are included in
this le, you do not need to use the yacc library when processing this le.
main() The required main program that calls yyparse() to start the program.
yyerror(s) This error handling routine only prints a syntax error message.
yywrap() The wrap-up routine that returns a value of 1 when the end of input
occurs.
The Lexical Analyzer Source Code
This shows the contents of the le calc.lex. This le contains include statements for standard
intput and output, as well as for the y.tab.h le. The yacc program generates that le from the
yacc grammar le information, if you use the -d ag with the yacc command. The le y.tab.h
contains denitions for the tokens that the parser program uses. In addition, calc.lex contains the
rules used to generate the tokens from the input stream.
%{
#include <stdio.h>
#include "y.tab.h"
int c;
extern int yylval;
%}
%%
"" ;
[a-z] {
c = yytext[0];
yylval=c-a;
return(LETTER);
}
[0-9] {
c = yytext[0];
yylval=c-0;
return(DIGIT);
}
[ˆa-z 0-9] {
c = yytext[0];
return(c);
}
FILES
y.output A readable description of parsing tables and a report on conicts gen-
erated by grammar ambiguities.
y.tab.c Output le.
y.tab.h Denitions for token names.
527188-007 Hewlett-Packard Company 1043