aboutsummaryrefslogtreecommitdiffstats
path: root/src/lex.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lex.cpp')
-rw-r--r--src/lex.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lex.cpp b/src/lex.cpp
index f633b00..5b6eb73 100644
--- a/src/lex.cpp
+++ b/src/lex.cpp
@@ -41,15 +41,15 @@ readChar(Cursor& cur, istream& in)
AST*
readExpression(Cursor& cur, istream& in)
{
-#define PUSH(s, t) { if (t != "") { s.top()->push_back(new ALexeme(loc, t)); t = ""; } }
+#define PUSH(s, t) { if (t != "") { s.top().push_back(new ALexeme(loc, t)); t = ""; } }
#define YIELD(s, t) { if (s.empty()) { return new ALexeme(loc, t); } else PUSH(s, t) }
- stack<ATuple*> stk;
- string tok;
- Cursor loc; // start of tok
+ stack< List<ATuple, AST> > 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")
+ THROW_IF(!stk.empty(), cur, "unexpected end of file");
return new ATuple(cur);
case ';':
while ((c = readChar(cur, in)) != '\n') {}
@@ -80,7 +80,7 @@ readExpression(Cursor& cur, istream& in)
YIELD(stk, tok);
break;
case '(':
- stk.push(new ATuple(cur));
+ stk.push(List<ATuple, AST>());
break;
case ')':
switch (stk.size()) {
@@ -89,12 +89,12 @@ readExpression(Cursor& cur, istream& in)
throw Error(cur, "unexpected `)'");
case 1:
PUSH(stk, tok);
- return stk.top();
+ return stk.top().head;
default:
PUSH(stk, tok);
- ATuple* l = stk.top();
+ List<ATuple, AST> l = stk.top();
stk.pop();
- stk.top()->push_back(l);
+ stk.top().push_back(l.head);
}
break;
case '#':
@@ -109,8 +109,9 @@ readExpression(Cursor& cur, istream& in)
}
switch (stk.size()) {
case 0: return new AString(loc, tok);
- case 1: return stk.top();
- default: throw Error(cur, "missing `)'");
+ case 1: return stk.top().head;
+ default: throw Error(cur, "missing `)'");
}
- return new ATuple(cur);
+ assert(false);
+ return new ATuple(cur); // never reached
}