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 bylex(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 π
-ooutput β direct output to the specified file instead ofy.tab.c. you pick the name, you're the main character π-Dnβ create filey.debug, containing diagnostic messages. To incorporate them in the parser, compile it with preprocessor symbolyydebugdefined. The amount of diagnostic output from the parser is regulated by value n. The value0reports errors;1reports reductions; higher values (up to4) include more information about state transitions. basically a volume knob for yapping, and honestly? we respect it π-vβ create filey.output, containing a description of the parsing tables and of conflicts arising from ambiguities in the grammar. receipts!! π§Ύ-dβ create filey.tab.h, containing#definestatements that associate yacc-assignedtoken codeswith user-declaredtoken names. Include it in source files other thany.tab.cto give access to the token codes. so like, share the vocab with the rest of your files, be generous π-sstem β change the prefix of the file namesy.tab.c,y.tab.h,y.debug, andy.outputto stem. glow-up for your filenames β¨-Sβ write a parser that uses Stdio instead of the print routines inlibc. retro vibes, we stan a throwback πΈ-lβ disable#linedirectives in the generated parser. sometimes you just don't wanna be tracked, valid π«Ά-aβ generate a parser that takes an argument of typeYyargand passes this argument to each invocation of the lexer function,yylex.Yyargcontains per-instance state and a single user-visible member,arg, of typevoid*. 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-Soption reverses this. okay so default is Plan 9 flavored,-Sflips 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 ofyylex()no longer fits in ashort; second, the starting value for non-terminals is now0xE000rather than257. not theshort!!! π numbers changed, deal with it bestie - The generated parser can be recursive: actions can call
yyparse, for example to implement a sort of#includestatement 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.outputy.tab.cy.tab.hy.debugy.tmp.*β temporary filey.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
- debian bookworm: 9base 1:6-13 Β· Lucent
- debian trixie: 9base 1:6-14 Β· Lucent
- ubuntu jammy: 9base 1:6-11 Β· Lucent
- ubuntu noble: 9base 1:6-14 Β· Lucent
- ubuntu questing: 9base 1:6-15
- ubuntu resolute: 9base 1:6-15build1 Β· Lucent
- ubuntu stonking: 9base 1:6-15build1 Β· Lucent
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms