#!/bin/bash # Build the P6 Pascal syntax validator from p6_pascal.atg. # Needs: CR (Coco/R V1.53), gm2 -fiso, parser/scanner frames, FileIO. # Note: link via the two-step module list; a single-step link trips # over pre-existing errors in this gm2 build's own ISO library .defs. set -e CR="${CR:-/home/eric/Projets/Projets-Modula2/MyWork/CocoGm2/CR}" GM2="${GM2:-/home/eric/bin/Modula2/Gm2/bin/gm2}" FRAMES="${CRFRAMES:-/home/eric/Projets/Projets-Modula2/MyWork/Theia/GNU-grammar/build}" M2LIB="${M2LIB:-/home/eric/Projets/Projets-Modula2/MyWork/Theia/GNU-grammar/build}" HERE="$(cd "$(dirname "$0")" && pwd)" B="$HERE/build" rm -rf "$B" mkdir -p "$B" cp "$HERE/p6_pascal.atg" "$B/" cp "$M2LIB/FileIO.def" "$M2LIB/FileIO.mod" "$B/" cd "$B" echo "=== CR ==="; CRFRAMES="$FRAMES" "$CR" -m -C p6_pascal.atg echo "=== patch: EOF check ===" python3 - <<'EOF' s = open('P6P.mod').read() old = ''' P6S.Reset; Get; P6; END Parse;''' assert old in s, 'EOF patch pattern missing' s = s.replace(old, ''' P6S.Reset; Get; P6; IF sym # 0 THEN SynError(0) END; END Parse;''') open('P6P.mod', 'w').write(s) print('patched') EOF echo "=== check: no degenerate code ===" if grep -q "IF FALSE\|WHILE FALSE" P6P.mod; then echo "DEGENERATE GENERATION (IF/WHILE FALSE)"; exit 1; fi echo "=== compile ===" for m in FileIO P6S P6P P6; do "$GM2" -fiso -I . -c "$m.mod"; done echo "=== link ===" # NOTE: the gen step exits 1 on pre-existing errors in gm2's own # ISO library .defs, but still writes a usable modules.lst. "$GM2" -fiso -I . -fgen-module-list=modules.lst -o /dev/null FileIO.o P6S.o P6P.o P6.mod || true "$GM2" -fiso -I . -fuse-list=modules.lst -o P6 FileIO.o P6S.o P6P.o P6.mod echo "=== smoke ===" printf 'PROGRAM Hello;\nBEGIN\n WriteLn('"'"'hi'"'"');\nEND.\n' > Hello.pas ./P6 Hello.pas printf 'PROGRAM T;\nBEGIN\nEND. GARBAGE\n' > Garbage.pas if ./P6 Garbage.pas 2>&1 | grep -q "Incorrect"; then echo "trailing-garbage rejected"; else echo "EOF CHECK FAILED"; exit 1; fi ./P6 "$HERE/tests/deep.pas" rm -f Hello.pas Hello.LST Garbage.pas Garbage.LST "$HERE/tests/deep.LST"