Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (v - z) yacc(1)
• Defines the operators and their precedence.
Rules Section
The rules section defines the rules that parse the input stream.
Programs Section
The programs section contains the following routines. Because these routines are included in
this file, you do not need to use the yacc library when processing this file.
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 file calc.lex. This file contains include statements for standard
intput and output, as well as for the y.tab.h file. The yacc program generates that file from the
yacc grammar file information, if you use the -d flag with the yacc command. The file y.tab.h
contains definitions 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 conflicts gen-
erated by grammar ambiguities.
y.tab.c Output file.
y.tab.h Definitions for token names.
527188-007 Hewlett-Packard Company 10−43