PPT Slide
// Parse slash-delimited book data.
LineTerminator = \r|\n|\r\n
private void initialize_buffer(String s) {
int adjusted_line_no = yyline + 1;
line = new StringBuffer("[" + adjusted_line_no + "] " + s);
private void add_identifier_to_buffer(String s) {
private void add_delimiter_to_buffer(String s) {
private void display_line() {
System.out.println(line.toString());
System.out.println("Lines Processed: " + yyline);
System.out.println("Total Number of Characters: " + yychar);
{Title} { initialize_buffer(yytext()); }
{Field} { add_identifier_to_buffer(yytext()); }
{Slash} { add_delimiter_to_buffer("/"); }
{LineTerminator} { display_line(); }
<<EOF>> { wrap_up(); return 0; }
When the lexer hits the end of file
we call this wrap_up method to
print the number of lines and the
total number of characters in the