mid-kid
4 years ago
1 changed files with 34 additions and 0 deletions
@ -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 <stdio.h> |
||||
|
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" |
Loading…
Reference in new issue