| 1 4 package gnu.kawa.lispexpr; 5 import gnu.expr.*; 6 import gnu.mapping.*; 7 import gnu.text.*; 8 import gnu.lists.*; 9 import gnu.bytecode.Access; 10 import gnu.bytecode.Field; 11 import gnu.mapping.EnvironmentKey; 12 import gnu.kawa.reflect.StaticFieldLocation; 13 import kawa.lang.Translator; import kawa.lang.Syntax; 16 17 18 public abstract class LispLanguage extends Language 19 { 20 static public final String quote_sym = "quote"; 21 static public final String unquote_sym = "unquote"; 22 static public final String unquotesplicing_sym = "unquote-splicing"; 23 static public final String quasiquote_sym = "quasiquote"; 24 25 static public final String lookup_sym = "$lookup$"; 26 27 28 public ReadTable defaultReadTable = createReadTable(); 29 30 31 public abstract ReadTable createReadTable (); 32 33 public Lexer getLexer(InPort inp, SourceMessages messages) 34 { 35 return new LispReader(inp, messages); 36 } 37 38 public Compilation getCompilation (Lexer lexer, SourceMessages messages) 39 { 40 return new Translator (this, messages); 41 } 42 43 public boolean parse (Compilation comp, int options) 44 throws java.io.IOException , gnu.text.SyntaxException 45 { 46 kawa.lang.Translator tr = (kawa.lang.Translator) comp; 47 Lexer lexer = tr.lexer; 48 ModuleExp mexp = tr.mainLambda; 49 Values forms = new Values(); 50 LispReader reader = (LispReader) lexer; 51 Compilation save_comp = Compilation.getCurrent(); 52 try 53 { 54 Compilation.setCurrent(tr); 55 if (tr.pendingForm != null) 56 { 57 tr.scanForm(tr.pendingForm, mexp); 58 tr.pendingForm = null; 59 } 60 for (;;) 61 { 62 Object sexp = reader.readCommand(); 63 if (sexp == Sequence.eofValue) 64 { 65 if ((options & PARSE_ONE_LINE) != 0) 66 return false; break; 68 } 69 tr.scanForm(sexp, mexp); 70 if ((options & PARSE_ONE_LINE) != 0) 71 break; 72 if ((options & PARSE_PROLOG) != 0 73 && tr.getState() >= Compilation.PROLOG_PARSED) 74 { 75 return true; 76 } 77 } 78 if (lexer.peek() == ')') 79 lexer.fatal("An unexpected close paren was read."); 80 81 tr.finishModule(mexp); 83 84 if ((options & PARSE_PROLOG) == 0) 85 { 86 tr.firstForm = 0; 87 } 88 tr.setState(Compilation.BODY_PARSED); 89 } 90 finally 91 { 92 Compilation.setCurrent(save_comp); 93 } 94 return true; 95 } 96 97 98 public void resolve (Compilation comp) 99 { 100 Translator tr = (Translator) comp; 101 tr.resolveModule(tr.getModule()); 102 } 103 104 public Declaration declFromField (ModuleExp mod, Object fvalue, Field fld) 105 { 106 Declaration fdecl = super.declFromField(mod, fvalue, fld); 107 boolean isFinal = (fld.getModifiers() & Access.FINAL) != 0; 108 if (isFinal && fvalue instanceof Syntax) fdecl.setSyntax(); 110 return fdecl; 111 } 112 113 119 protected void defSntxStFld(String name, String cname, String fname) 120 { 121 Object property 122 = hasSeparateFunctionNamespace() ? EnvironmentKey.FUNCTION : null; 123 StaticFieldLocation loc = 124 StaticFieldLocation.define(environ, environ.getSymbol(name), property, 125 cname, fname); 126 loc.setSyntax(); 127 } 128 129 protected void defSntxStFld(String name, String cname) 130 { 131 defSntxStFld(name, cname, Compilation.mangleNameIfNeeded(name)); 132 } 133 134 135 public Expression makeBody(Expression[] exps) 136 { 137 return new BeginExp (exps); 138 } 139 140 public Expression makeApply (Expression func, Expression[] args) 141 { 142 return new ApplyExp(func, args); 143 } 144 145 public boolean selfEvaluatingSymbol (Object obj) 146 { 147 return obj instanceof Keyword; 148 } 149 150 151 public static Symbol langSymbolToSymbol (Object sym) 152 { 153 return ((LispLanguage) Language.getDefaultLanguage()).fromLangSymbol(sym); 154 } 155 156 protected Symbol fromLangSymbol (Object sym) 157 { 158 if (sym instanceof String ) 159 return getSymbol((String ) sym); 160 return (Symbol) sym; 161 } 162 } 163 | Popular Tags |