implementing a scheme-like interpreter in Java - data type choice

Discussion in 'Java' started by metaperl, Aug 22, 2007.

  1. metaperl

    metaperl Guest

    Ok, I have been using SableCC (http://www.SableCC) to develop an
    interpreter for a scheme-like language. In fact, a language with J
    ( language semantics, but scheme syntax.

    So, if you check out the HEAD:

    svn checkout redick

    and follow the build/install instructions:

    then you have an interpreter which works.

    Now, I have several future goals, but my instinct tells me the next
    thing to do is implement a hierarchy of types. I have studied the
    design document for Norvig's Jscheme -

    but am leaning towards the decision he chose not to make. I want to
    make a base LispObject class and then use composition on Java types
    to extend and customize them.

    I'm not sure why I'm opting for that, but it just seems more

    That being said, my instincts are further guiding me to the idea that
    having LispString, LispDouble, etc is a violation of DRY and that
    I need some sort of package for my datatypes. And that is where I am
    hitting the wall.

    Should I do something like:

    package redick.types;

    public abstract class LispObject {

    Object val;

    java.lang.String toString ();


    public class String {

    java.lang.String toString () {

    return ("'" + (String)val + "'");


    So, I do want to be able to call Java methods, but I dont see why
    Norvig thought that would be harder with the LispObject approach as
    opposed to trying to hijack Java types like he did.

    Any feedback on which typing approach is better is appreciated.

    I think SICP is a good enough guide to how to write an interpreter. I
    understand Section 3.2 on how to create environments for expression
    evaluation and will be doing that shortly after I get the type system
    locked down.

    Of course any other feedback is welcome too.
    metaperl, Aug 22, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.