45 lines
901 B
Bash
45 lines
901 B
Bash
|
#/bin/sh
|
||
|
|
||
|
BINDIR=../pegasus/bin/
|
||
|
|
||
|
tokenfile=$1
|
||
|
TMPERRORFILE="/tmp/TMPERRORFILE$$"
|
||
|
|
||
|
on_error()
|
||
|
{
|
||
|
if [ $? -ne 0 ]; then
|
||
|
err=$1
|
||
|
echo $err
|
||
|
cat ${TMPERRORFILE}
|
||
|
rm ${TMPERRORFILE}
|
||
|
exit 1
|
||
|
fi
|
||
|
val=`wc -l ${TMPERRORFILE} | cut -d ' ' -f 1`
|
||
|
if [ ${val} -ne 0 ]; then
|
||
|
echo $err
|
||
|
cat ${TMPERRORFILE}
|
||
|
rm ${TMPERRORFILE}
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
if [ $# -eq 0 ]
|
||
|
then
|
||
|
echo "usage $0 token-and-rules-file"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
echo "pegasus reading the grammar"
|
||
|
${BINDIR}/pegasus < "${tokenfile}" > "${tokenfile}.json" 2>${TMPERRORFILE}
|
||
|
on_error "cannot read the grammar"
|
||
|
|
||
|
echo "pegasus creating a dot file"
|
||
|
${BINDIR}/pegasus-dot < "${tokenfile}.json" > "${tokenfile}.dot"
|
||
|
# echo VAL RET $?
|
||
|
on_error "cannot create the dot file"
|
||
|
|
||
|
echo "pegasus trying an example on the generated parser"
|
||
|
cat "${tokenfile}.example" | ${BINDIR}/pegasus-sim -i "${tokenfile}.json"
|
||
|
# echo VAL RET $?
|
||
|
on_error "cannot parse the example"
|