diff options
Diffstat (limited to 'src/lex.cpp')
-rw-r--r-- | src/lex.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/lex.cpp b/src/lex.cpp index bfdd9c1..b5c89e9 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -16,7 +16,7 @@ */ /** @file - * @brief Lexing (build a SExp from a string) + * @brief Lexing (build an unparsed textual AST from a string) */ #include <stack> @@ -36,19 +36,19 @@ readChar(Cursor& cur, istream& in) } /// Read an expression from @a in -SExp +AST* readExpression(Cursor& cur, istream& in) { -#define PUSH(s, t) { if (t != "") { s.top().push_back(SExp(loc, new AString(loc, t))); t = ""; } } -#define YIELD(s, t) { if (s.empty()) { return SExp(loc, new AString(loc, t)); } else PUSH(s, t) } - stack<SExp> stk; - string tok; - Cursor loc; // start of tok +#define PUSH(s, t) { if (t != "") { s.top()->push_back(new AString(loc, t)); t = ""; } } +#define YIELD(s, t) { if (s.empty()) { return new AString(loc, t); } else PUSH(s, t) } + stack<ATuple*> stk; + string tok; + Cursor loc; // start of tok while (int c = readChar(cur, in)) { switch (c) { case EOF: THROW_IF(!stk.empty(), cur, "unexpected end of file") - return SExp(cur); + return new ATuple(cur); case ';': while ((c = readChar(cur, in)) != '\n') {} case '\n': case ' ': case '\t': @@ -60,7 +60,7 @@ readExpression(Cursor& cur, istream& in) YIELD(stk, tok + '"'); break; case '(': - stk.push(SExp(cur)); + stk.push(new ATuple(cur)); break; case ')': switch (stk.size()) { @@ -71,9 +71,9 @@ readExpression(Cursor& cur, istream& in) return stk.top(); default: PUSH(stk, tok); - SExp l = stk.top(); + ATuple* l = stk.top(); stk.pop(); - stk.top().push_back(l); + stk.top()->push_back(l); } break; case '#': @@ -87,9 +87,9 @@ readExpression(Cursor& cur, istream& in) } } switch (stk.size()) { - case 0: return SExp(loc, new AString(loc, tok)); + case 0: return new AString(loc, tok); case 1: return stk.top(); default: throw Error(cur, "missing `)'"); } - return SExp(cur); + return new ATuple(cur); } |