YACC(1plan9)

✨ YACC πŸ’… (1plan9)

ok bestie so you wanna build a parser?? say less. this is the Plan 9 manual page for yacc, section 1 (general commands). let's get into it 🫢


🌸 NAME 🌸

yacc β€” yet another compiler-compiler. yes the name is literally a recursive joke, we love a self-aware king πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

yacc [ option ...  ] grammar

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so here's the tea β˜•: yacc takes a context-free grammar plus some translation code and turns it into a whole set of tables for an LR(1) parser and translator. Iconic. And here's the best part β€” your grammar is allowed to be ambiguous, no stress πŸ’–. The precedence rules you specify get used to break the ambiguities. slay.

The output file, y.tab.c, has to be compiled by the C compiler to actually produce a program. Then that program needs to be loaded up with:

  • a lexical analyzer function, yylex(void) β€” often generated by lex(1) if you're feeling fancy ✨
  • a main(int argc, char *argv[]) program
  • and an error handling routine, yyerror(char*)

all three, no skips, it's giving group project energy but make it compile πŸ’€

🌈 The options 🌈

  • -o output β€” direct output to the specified file instead of y.tab.c. you pick the name, you're the main character πŸ’…
  • -Dn β€” create file y.debug, containing diagnostic messages. To incorporate them in the parser, compile it with preprocessor symbol yydebug defined. The amount of diagnostic output from the parser is regulated by value n. The value 0 reports errors; 1 reports reductions; higher values (up to 4) include more information about state transitions. basically a volume knob for yapping, and honestly? we respect it πŸ”Š
  • -v β€” create file y.output, containing a description of the parsing tables and of conflicts arising from ambiguities in the grammar. receipts!! 🧾
  • -d β€” create file y.tab.h, containing #define statements that associate yacc-assigned token codes with user-declared token names. Include it in source files other than y.tab.c to give access to the token codes. so like, share the vocab with the rest of your files, be generous πŸ’–
  • -s stem β€” change the prefix of the file names y.tab.c, y.tab.h, y.debug, and y.output to stem. glow-up for your filenames ✨
  • -S β€” write a parser that uses Stdio instead of the print routines in libc. retro vibes, we stan a throwback 🌸
  • -l β€” disable #line directives in the generated parser. sometimes you just don't wanna be tracked, valid 🫢
  • -a β€” generate a parser that takes an argument of type Yyarg and passes this argument to each invocation of the lexer function, yylex. Yyarg contains per-instance state and a single user-visible member, arg, of type void*. per-instance state?? she's carrying her own baggage and that's self care πŸ’…

⭐ how it differs from the UNIX one ⭐

The specification of yacc itself is essentially the same as the UNIX version described in the references mentioned below. Besides the -D option, the main relevant differences are:

  • The interface to the C environment is by default through <libc.h> rather than <stdio.h>; the -S option reverses this. okay so default is Plan 9 flavored, -S flips it back to stdio, choose your fighter πŸ₯Š
  • The parser accepts UTF input text (see utf(7)), which has a couple of effects. First, the return value of yylex() no longer fits in a short; second, the starting value for non-terminals is now 0xE000 rather than 257. not the short!!! 😭 numbers changed, deal with it bestie
  • The generated parser can be recursive: actions can call yyparse, for example to implement a sort of #include statement in an interpreter. recursion in the parser?? it's giving mirror facing mirror πŸͺžβœ¨
  • Finally, some undocumented inner workings of the parser have been changed, which may affect programs that know too much about its structure. mind your business and your code will be fine πŸ™ˆ

πŸ’œ FILES πŸ’œ

  • y.output
  • y.tab.c
  • y.tab.h
  • y.debug
  • y.tmp.* β€” temporary file
  • y.acts.* β€” temporary file
  • /lib/yaccpar β€” parser prototype
  • /lib/yaccpars β€” parser prototype using stdio

πŸ‘‘ SOURCE πŸ‘‘

/src/cmd/yacc.c

🌈 SEE ALSO 🌈

  • lex(1)
  • S. C. Johnson and R. Sethi, ``Yacc: A parser generator'', Unix Research System Programmer's Manual, Tenth Edition, Volume 2
  • B. W. Kernighan and Rob Pike, The UNIX Programming Environment, Prentice Hall, 1984

homework but make it ✨academic✨ πŸ“š


πŸ’€ BUGS πŸ’€

The parser may not have full information when it writes to y.debug so that the names of the tokens returned by may be missing.

(and yeah, that sentence really does just end at "returned by" in the original β€” not me, I'm just the messenger πŸ™ˆ the manpage said what it said)


and that's the whole page, bestie!! this one's from the Plan 9 manual, section 1, and the footer signs off with YACC(1plan9) πŸ’– you understood the assignment, now go write that grammar and make it parse. periodt πŸ’…βœ¨

πŸ“¦ where this page comes from