aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/resp.hpp b/src/resp.hpp
index 0c698a9..77f771c 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -117,8 +117,9 @@ ostream& operator<<(ostream& out, const Env<K,V>& env) {
* Lexer: Text (istream) -> S-Expressions (SExp) *
***************************************************************************/
+struct PEnv;
struct AST;
-AST* readExpression(Cursor& cur, std::istream& in);
+AST* read_expression(PEnv& penv, Cursor& cur, std::istream& in);
/***************************************************************************
@@ -141,11 +142,10 @@ enum Tag {
T_BOOL = 4,
T_FLOAT = 6,
T_INT32 = 8,
- T_LEXEME = 10,
- T_STRING = 12,
- T_SYMBOL = 14,
- T_TUPLE = 16,
- T_TYPE = 18
+ T_STRING = 10,
+ T_SYMBOL = 12,
+ T_TUPLE = 14,
+ T_TYPE = 16
};
/// Garbage collector
@@ -204,7 +204,6 @@ struct CEnv; ///< Compile-Time Environment
struct ATuple;
struct ASymbol;
struct AType;
-struct ALexeme;
class AST;
extern ostream& operator<<(ostream& out, const AST* ast);
@@ -241,7 +240,6 @@ struct AST : public Object {
const ASymbol* as_symbol() const { return as_a<const ASymbol>(T_SYMBOL); }
const ASymbol* to_symbol() const { return to_a<const ASymbol>(T_SYMBOL); }
- const ALexeme* to_lexeme() const { return to_a<const ALexeme>(T_LEXEME); }
const AType* as_type() const { return as_a<const AType>(T_TYPE); }
const AType* to_type() const { return to_a<const AType>(T_TYPE); }
@@ -265,12 +263,6 @@ struct ALiteral : public AST {
const T val;
};
-/// Lexeme (any atom in the CST, e.g. "a", "3.4", ""hello"", etc.)
-struct ALexeme : public AST {
- ALexeme(Cursor c, const string& s) : AST(T_LEXEME, c), cppstr(s) {}
- const string cppstr;
-};
-
/// String, e.g. ""a""
struct AString : public AST {
AString(Cursor c, const string& s) : AST(T_STRING, c), cppstr(s) {}
@@ -538,7 +530,6 @@ AST::operator==(const AST& rhs) const
}
case T_UNKNOWN:
- case T_LEXEME:
case T_STRING:
case T_SYMBOL:
return this == &rhs;
@@ -553,19 +544,10 @@ AST::operator==(const AST& rhs) const
/// Parse Time Environment (really just a symbol table)
struct PEnv : private map<const string, ASymbol*> {
PEnv() : symID(0) {}
- typedef const AST* (*PF)(PEnv&, const AST*, void*); ///< Parse Function
- struct Handler { Handler(PF f, void* a=0) : func(f), arg(a) {} PF func; void* arg; };
- map<const string, Handler> handlers; ///< List parse functions
- void reg(const string& s, const Handler& h) {
- handlers.insert(make_pair(sym(s)->str(), h));
- }
- const Handler* handler(const string& s) const {
- map<string, Handler>::const_iterator i = handlers.find(s);
- return (i != handlers.end()) ? &i->second : NULL;
- }
string gensymstr(const char* s="_") { return (format("%s_%d") % s % symID++).str(); }
ASymbol* gensym(const char* s="_") { return sym(gensymstr(s)); }
ASymbol* sym(const string& s, Cursor c=Cursor()) {
+ assert(s != "");
const const_iterator i = find(s);
if (i != end()) {
return i->second;