-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |