From 500f073ce5b4dd6afa756ae27d802db4b274b05a Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sun, 20 Dec 2020 02:33:58 +0100 Subject: [PATCH] Add day 19 bison solution out of spite at this point I swear to fuck I was so close with it. Fucking %glr-parser --- d19.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 d19.sh diff --git a/d19.sh b/d19.sh new file mode 100755 index 0000000..f8c83ca --- /dev/null +++ b/d19.sh @@ -0,0 +1,34 @@ +#!/bin/sh +tmp="$(mktemp -d)" +trap "rm -rf '$tmp'" EXIT +set -ex + +cat "$1" | tr '\n' - | sed -e 's/--.*//' | tr - '\n' | tr '"' \' | sed -e 's/[0-9]\+/_&/g' -e 's/$/;/' > "$tmp/r" +cat "$1" | tr '\n' - | sed -e 's/.*--//' | tr - '\n' > "$tmp/m" + +cat > "$tmp/run.y" << EOF +%code top { +#include +int yylex() { return getchar(); } +void yyerror() {} +int count = 0; +} +%glr-parser +%% +input: %empty | input line; +line: '\n' | _0 '\n' { count++; } | error '\n' { yyerrok; }; +$(cat "$tmp/r") +%% +int main() +{ + yyparse(); + printf("%d\n", count); +} +EOF +#cat "$tmp/run.y" +#cat "$tmp/m" +sed -e '/^_8:/c_8: _42 | _42 _8;' -e '/^_11:/c_11: _42 _31 | _42 _11 _31;' "$tmp/run.y" > "$tmp/run2.y" +bison -o /dev/stdout "$tmp/run.y" | cc -o "$tmp/run" -xc - +bison -o /dev/stdout "$tmp/run2.y" | cc -o "$tmp/run2" -xc - +cat "$tmp/m" | "$tmp/run" +cat "$tmp/m" | "$tmp/run2"