. "$BST_LIB" require byacc byacc/present # byacc (Berkeley Yacc) reads a yacc grammar spec and emits an LALR(1) C parser. # The recipe renames the installed binary to "byacc" (--program-transform-name). # Drive it on a minimal grammar in a scratch dir — byacc writes y.tab.c into the # current directory, so run it from there. work=${TMPDIR:-/tmp}/bst-byacc.$$ rm -rf "$work"; mkdir -p "$work" cat > "$work/calc.y" <<'YACC' %token NUM %% expr : NUM | expr '+' NUM ; %% YACC # -d emits the parser (y.tab.c) and the token header (y.tab.h). ( cd "$work" && byacc -d calc.y ) >"$work/byacc.log" 2>&1; rc=$? # The C parser source is produced and byacc exits 0. if [ "$rc" -eq 0 ] && [ -f "$work/y.tab.c" ]; then bst_ok byacc/generate else bst_notok byacc/generate "rc=$rc $(_bst_1line "$(cat "$work/byacc.log" 2>&1)")"; fi # The generated parser carries the yacc driver routine yyparse(). check_out byacc/parser "yyparse" cat "$work/y.tab.c" # -d wrote the token header with a #define for the declared token. check_out byacc/defines "NUM" cat "$work/y.tab.h" rm -rf "$work"