Alan Manuel Gloria:
> It should be trivial to create a Scheme interpreter in Java.
> Actually, you don't even need a scheme interpreter: you just need a
> set of classes to represent common Scheme types, and a virtual member
> function on the base class to print out an s-expression. That way we
> can use its output directly into a Scheme script that executes the
> Java code on the t-expr input, slurps its s-expr output, and compares
> it to the reference s-expr.
I've done something like that in Java, and it's working! I've created
output/scheme/Pair.java; a Pair represents a Scheme Pair, and it has static
Scheme-like routines like cons, list, append, nullp (for "null?"), pairp, and
so on. It's not a full Scheme, but it's enough so that action rules have a
trivial mapping to Scheme (they basically use Scheme procedure names, with Java
syntax). Scheme's () is represented as Java null, Scheme atoms are represented
as Java strings, and rule results are "$RULENAME.v". Data is represented as
Java type "Object" (which is the root of the Java class hierarchy).
Here's an example, it looks pretty clear to me:
body returns [Object v] :
i_expr (same body1=body {$v = cons($i_expr.v, $body1.v);}
| dedent {$v = list($i_expr.v);} ) ;
Thoughts?
I think this is better done in Java than in C++. For one thing, Java has
automatic garbage collection, and C++ doesn't, which makes Java a better match
to the problem.
--- David A. Wheeler
------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612
_______________________________________________
Readable-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/readable-discuss