Skip to content

Commit

Permalink
adds chap6.FileRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
chibash committed May 13, 2021
1 parent 5f1f2e6 commit 06a12b7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/chap6/BasicFileInterpreter.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
11 changes: 11 additions & 0 deletions src/chap6/FileRunner.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 7 additions & 0 deletions src/chap6/sum.stone
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sum = 0
i = 1
while i < 10 {
sum = sum + 1
i = i + 1
}
sum

0 comments on commit 06a12b7

Please sign in to comment.