From e1d5009229fb5cea5845cd08e0abdc8fe440ee86 Mon Sep 17 00:00:00 2001 From: vanhauser-thc Date: Fri, 9 Jul 2021 10:32:14 +0200 Subject: fixes --- .../gramatron/preprocess/prep_automaton.sh | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 custom_mutators/gramatron/preprocess/prep_automaton.sh (limited to 'custom_mutators/gramatron/preprocess/prep_automaton.sh') diff --git a/custom_mutators/gramatron/preprocess/prep_automaton.sh b/custom_mutators/gramatron/preprocess/prep_automaton.sh new file mode 100755 index 00000000..28d99fb0 --- /dev/null +++ b/custom_mutators/gramatron/preprocess/prep_automaton.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# This script creates a FSA describing the input grammar *.g4 + +if [ ! "$#" -lt 4 ]; then + echo "Usage: ./prep_pda.sh [stack_limit]" + exit 1 +fi + +GRAMMAR_FILE=$1 +GRAMMAR_DIR="$(dirname $GRAMMAR_FILE)" +START="$2" +STACK_LIMIT="$3" + +# Get filename +FILE=$(basename -- "$GRAMMAR_FILE") +echo "File:$FILE" +FILENAME="${FILE%.*}" +echo "Name:$FILENAME" + + +# Create the GNF form of the grammar +CMD="python gnf_converter.py --gf $GRAMMAR_FILE --out ${FILENAME}.json --start $START" +$CMD + +# Generate grammar automaton +# Check if user provided a stack limit +if [ -z "${STACK_LIMIT}" ]; then +CMD="python3 construct_automata.py --gf ${FILENAME}.json" +else +CMD="python construct_automata.py --gf ${FILENAME}.json --limit ${STACK_LIMIT}" +fi +echo $CMD +$CMD + +# Move PDA to the source dir of the grammar +echo "Copying ${FILENAME}_automata.json to $GRAMMAR_DIR" +mv "${FILENAME}_automata.json" $GRAMMAR_DIR/ -- cgit 1.4.1