From 06a12b7e812fb38ebebc21c8add4cdf82af45b6a Mon Sep 17 00:00:00 2001 From: Shigeru Chiba Date: Fri, 14 May 2021 01:27:09 +0900 Subject: [PATCH] adds chap6.FileRunner --- src/chap6/BasicFileInterpreter.java | 28 ++++++++++++++++++++++++++++ src/chap6/FileRunner.java | 11 +++++++++++ src/chap6/sum.stone | 7 +++++++ 3 files changed, 46 insertions(+) create mode 100644 src/chap6/BasicFileInterpreter.java create mode 100644 src/chap6/FileRunner.java create mode 100644 src/chap6/sum.stone diff --git a/src/chap6/BasicFileInterpreter.java b/src/chap6/BasicFileInterpreter.java new file mode 100644 index 0000000..4ff2e1b --- /dev/null +++ b/src/chap6/BasicFileInterpreter.java @@ -0,0 +1,28 @@ +package chap6; +import stone.*; +import stone.ast.ASTree; +import stone.ast.NullStmnt; +import java.io.FileReader; +import java.io.FileNotFoundException; + +public class BasicFileInterpreter { + public static void main(String[] args) + throws ParseException, FileNotFoundException + { + run(new BasicParser(), new BasicEnv(), args[0]); + } + + public static void run(BasicParser bp, Environment env, String fileName) + throws ParseException, FileNotFoundException + { + FileReader reader = new FileReader(fileName); + Lexer lexer = new Lexer(reader); + while (lexer.peek(0) != Token.EOF) { + ASTree t = bp.parse(lexer); + if (!(t instanceof NullStmnt)) { + Object r = ((BasicEvaluator.ASTreeEx)t).eval(env); + System.out.println("=> " + r); + } + } + } +} diff --git a/src/chap6/FileRunner.java b/src/chap6/FileRunner.java new file mode 100644 index 0000000..e8550de --- /dev/null +++ b/src/chap6/FileRunner.java @@ -0,0 +1,11 @@ +package chap6; +import javassist.gluonj.util.Loader; + +// To run, +// java -cp ./bin:gluonj.jar chap6.FileRunner src/chap6/sum.stone + +public class FileRunner { + public static void main(String[] args) throws Throwable { + Loader.run(BasicFileInterpreter.class, args, BasicEvaluator.class); + } +} diff --git a/src/chap6/sum.stone b/src/chap6/sum.stone new file mode 100644 index 0000000..0b98ac4 --- /dev/null +++ b/src/chap6/sum.stone @@ -0,0 +1,7 @@ +sum = 0 +i = 1 +while i < 10 { + sum = sum + 1 + i = i + 1 +} +sum