-
Notifications
You must be signed in to change notification settings - Fork 0
/
sugar
executable file
·44 lines (39 loc) · 1.67 KB
/
sugar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
set -e
[ "$#" -gt 0 ] && BASE=${1%.*} || BASE=Main
S=${BASE}.sugar
J=${BASE}.java
function sugarc {
shead
grep $S -e '^ *import' | cat
echo "public class $BASE {"
echo ' public static final BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));'
echo ' public static final PrintWriter outWriter = new PrintWriter(System.out);'
grep $S -v -e '^ *import' | \
spy | \
sed -E 's;^\{;void main() {;;
s;^class ([^ {<]*).*\{;\0\n#undef CLS\n#define CLS \1;;
s;^[^ {}#@/];public static \0;;
s;^ (\(.*?\)); CLS\1;; #SPACE!
s;^ %; private ;; #SPACE!
s;^ \.; public ;; #SPACE!
s;^; ;;'
echo ' public static void main(String[] args) { main(); flush(); }'
echo ' public static StringTokenizer tokenizer = null;'
echo ' public static String nextLine() {'
echo ' try { return buffer.readLine(); } catch (IOException e) { throw new UncheckedIOException(e); }'
echo ' }'
echo ' public static String next() {'
echo ' while (tokenizer == null || !tokenizer.hasMoreElements()) { tokenizer = new StringTokenizer(nextLine()); }'
echo ' return tokenizer.nextToken();'
echo ' }'
echo ' public static int nextInt() { return Integer.parseInt(next()); }'
echo ' public static long nextLong() { return Long.parseLong(next()); }'
echo ' public static double nextDouble() { return Double.parseDouble(next()); }'
echo '}'
}
[ -e $S ] || (echo $S not found... && false)
sugarc | tee /tmp/${BASE}.raw | cpp -P | sed 's/__//g; s/></,/g' > $J
myjavac $J #|| (cat -n $J && false)
echo Running... 1>&2
time myjava $BASE #|| (cat -n $J && false)