PBYACC(1)

🌸 NAME 🌸

pbyacc β€” an LALR(1) parser generator. Yes bestie, this is the pbyacc manual page (section 1 of the manual, iykyk) and she is that girl when it comes to turning grammars into parsers. πŸ’–


✨ SYNOPSIS ✨

pbyacc [ -CPcdlrtv ] [ -b file_prefix ] [ -p symbol_prefix ] filename

πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea: pbyacc reads the grammar specification sitting in the file filename and generates an LR(1) parser for it. Periodt. Those parsers are made up of a set of LALR(1) parsing tables plus a driver routine, and that driver gets written in the C or Perl programming languages. By default, pbyacc writes the parse tables and the driver routine to the file y.tab.c, using the C programming language. Default behavior, main character energy, no notes. ✨

The following options are available:

πŸ‘‘ OPTIONS πŸ‘‘

  • -b file_prefix β€” this one changes the prefix that gets prepended to the output file names, and it sets it to the string you hand over as file_prefix. The default prefix is the character y. Cute, right? πŸŽ€
  • -C or -c β€” use the C programming language. This is the default, so like, you're already here. πŸ’…
  • -d β€” causes the header file y.tab.h to be written (or y.tab.ph, for Perl). Headers? We love to see it. 🫢
  • -l β€” listen up, this one's a whole vibe check. If the -l option is not specified, pbyacc will insert #line directives in the generated code. Those #line directives let the C compiler relate errors in the generated code back to the user's original code. If the -l option is specified, pbyacc will not insert the #line directives. But heads up: #line directives specified by the user will be retained. πŸ’œ
  • -p symbol_prefix β€” this changes the prefix in symbols in the generated code to the string denoted by symbol_prefix, rather than the default of "yy". Only symbols generated by pbyacc are affected β€” symbols in the definition and user subroutine sections are not changed. πŸ™ˆ

The symbol_prefix can contain upper or lower case letters, digits, or _ (underline or underscore). It must start with either an underline or a letter, and it must contain at least one lower case letter.

All lower case letters in the symbol prefix will be converted to upper case letters when defined values or typedefs are generated.

For example, if -p ftp_ is specifed on the pbyacc command line:

  • old symbol YYABORT β†’ new symbol FTP_ABORT
  • old symbol YYACCEPT β†’ new symbol FTP_ACCEPT
  • old symbol YYBYACC β†’ new symbol FTP_BYACC
  • old symbol YYDEBUG β†’ new symbol FTP_DEBUG
  • old symbol YYSTYPE β†’ new symbol FTP_STYPE
  • old symbol yyabort β†’ new symbol ftp_abort
  • old symbol yyerrok β†’ new symbol ftp_errok
  • old symbol yylex β†’ new symbol ftp_lex
  • old symbol yylval β†’ new symbol ftp_lval
  • old symbol yyparse β†’ new symbol ftp_parse
Note: The above list is not complete.
  • -P β€” use the Perl programming language. The output files have extensions .tab.pl and .tab.ph. Slay. πŸͺ
  • -r β€” causes pbyacc to produce separate files for code and tables. The code file is named y.code.c, and the tables file is named y.tab.c. In Perl mode, the file name extension is .pl, but the use of this option is not recommended. You've been warned, bestie. 😭
  • -t β€” changes the preprocessor directives generated by pbyacc so that debugging statements will be incorporated in the compiled code. Debugging era. πŸ”₯
  • -v β€” causes a human-readable description of the generated parser to be written to the file y.output. Reading is fundamental. πŸ“–

If the environment variable TMPDIR is set, the string denoted by TMPDIR will be used as the name of the directory where the temporary files are created.

In C mode, the user's code at the end of the PBYACC file is inserted before the yyparse subroutine, but in Perl mode, it is appended to yyparse so it can contain the main program. In Perl mode, there is no library, so the user must supply the yyerror and yylex subroutines and a main program that calls yyparse. For example:

%%
...grammar...
%%
sub yyerror { print STDERR "$.: $@\n"; }
sub yylex { ... }
exit &yyparse;

πŸŽ€ FILES πŸŽ€

  • y.code.c β€” output parser code in C
  • y.tab.c β€” output parser code and tables in C or, if -r switch specified, output parser tables in C
  • y.tab.h β€” defines for token names and, if %union used in grammar, the union definition for C parsers
  • y.code.pl β€” output parser code in PERL
  • y.tab.pl β€” output parser code and tables in PERL or, if -r switch specified, output parser tables in PERL
  • y.tab.ph β€” PERL assignment statements for token names
  • y.output β€” description of parser states, state transitions, and conflicts
  • /tmp/pbyacc.aXXXXXX, /tmp/byacc.tXXXXXX, /tmp/byacc.uXXXXXX β€” temporary files
  • /usr/lib/libby.a β€” library containing simple versions of main() (calls yyparse() then exits) and yyerror() (prints message to stderr then returns)

πŸ¦‹ SEE ALSO πŸ¦‹

  • flex(1), lex(1)
  • Yacc: Yet Another Compiler-Compiler β€” Stephen C. Johnson. Originally (?) published as Comp. Sci. Tech. Rep. No. 32. Bell Laboratories, July 1975. Reprinted in many different places. πŸ“š
  • Introduction to Compiler Construction with UNIX β€” Axel T. Schreiner and H. George Friedman, Jr. Prentice Hall, 1985.
  • lex & yacc, Second Edition β€” John R. Levine, Tony Mason, and Doug Brown. O'Reilly & Associates, Inc., 1992.
    • Possibly the best book yet on lex and yacc. (My opinion only. Others may disagree. - Rick Ohnemus)
  • comp.compilers monthly message and Frequently Asked Questions β€” Posted monthly in comp.compilers and news.answers USENET newsgroups. Old-school internet lore, honestly iconic. 🌈

πŸ’… DIAGNOSTICS πŸ’…

  • If there are rules that are never reduced, the number of such rules is reported on standard error. 🫒
  • If there are any LALR(1) conflicts, the number of conflicts is reported on standard error.

🌈 RESTRICTIONS 🌈

A symbol prefix specified using the -p switch must contain at least one lower case character. This is to allow a distinction between variables, defined values, and typedefs. It's giving "strict but fair". πŸ’œ


πŸ’€ BUGS πŸ’€

Not a single bug listed on this page, bestie. The section is just… there. Empty. Silently thriving. 🧚


And that's the whole page!! Before you go: this manual page comes from the 4.3 Berkeley Distribution, dated January 18, 1993, and it lives in the General Commands Manual as PBYACC(1). Thank you for coming to my TED talk, go generate a parser, ily. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from