misc/parser.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 26 Dec 2022 16:49:53 +0000
changeset 458 d9f8245d0861
parent 342 aa47abb9e723
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
342
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
#!/bin/bash
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
# to make the script fail safely
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
set -euo pipefail
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
out=${1:-output}
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
# compilation tests
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
function scala_compile {
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
  (ulimit -t 60; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> ptmp 1> ptmp)
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
}
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
# purity test
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
function scala_vars {
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
   (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|mutable|new Array' ptmp 2> /dev/null 1> /dev/null)
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
}
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
### compilation test
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
echo "collatz.scala runs?" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
if (scala_compile collatz.scala)
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
then
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
  echo "  --> success" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
  tsts0=$(( 0 ))
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
else
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
  echo "  --> scala collatz.scala did not run successfully" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
  tsts0=$(( 1 )) 
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
fi
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
# var, .par return, ListBuffer test
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
#
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
if  [ $tsts0 -eq 0 ]
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
then
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
  echo "collatz.scala does not contain var, return etc?" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
  if (scala_vars tmp)
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
  then
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
    echo "  --> test failed" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
    tsts=$(( 1 ))
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
  else
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
    echo "  --> success" | tee -a $out
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
    tsts=$(( 0 )) 
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
  fi
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
fi  
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
###rm tmp
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54