Skip to Content
lex & yacc, 2nd Edition
book

lex & yacc, 2nd Edition

by John Levine, Doug Brown, Tony Mason
October 1992
Intermediate to advanced
384 pages
7h 8m
English
O'Reilly Media, Inc.
Content preview from lex & yacc, 2nd Edition

Appendix I. MGL Compiler Code

Chapter 4, A Menu Generation Language , presented the lex and yacc grammars for the MGL. Here we present the entire code of the MGL, including runtime support code not shown in the chapter. Many improvements to the runtime code are possible, such as:

  • Screen clearing after improper input.

  • Better handling of the system() call, particularly saving and restoring terminal modes and screen contents.

  • Automatic generation of a main routine. Currently, it must be defined outside the calling program. Furthermore, it must call the routine menu_cleanup before exiting.

  • More flexible command handling, e.g., allowing unique prefixes of commands rather than requiring the whole command.

  • Taking keyboard input a character at a time in cbreak mode rather than the current line at a time.

  • More flexible nesting of menus.

See the Preface for information on obtaining an online copy of this code.

MGL Yacc Source

This is file mglyac.c.

 %{ #include <stdio.h> #include <string.h> #include <stdlib.h> int screen_done = 1; /* 1 if done, 0 otherwise */ char *act_str; /* extra argument for an action */ char *cmd_str; /* extra argument for command */ char *item_str; /* extra argument for * item description */ %} %union { char *string; /* string buffer */ int cmd; /* command value */ } %token <string> QSTRING ID COMMENT %token <cmd> SCREEN TITLE ITEM COMMAND ACTION EXECUTE EMPTY %token <cmd> MENU QUIT IGNORE ATTRIBUTE VISIBLE INVISIBLE END %type <cmd> action line attribute command %type <string> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

The GNU Make Book

The GNU Make Book

John Graham-Cumming
Learn LLVM 12

Learn LLVM 12

Kai Nacke
flex & bison

flex & bison

John Levine

Publisher Resources

ISBN: 9781565920002Errata Page