aboutsummaryrefslogtreecommitdiffstats
path: root/src/lex.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-07-04 05:02:09 +0000
committerDavid Robillard <d@drobilla.net>2009-07-04 05:02:09 +0000
commit7164809b051050fb4f4877793b9739b6177bcab1 (patch)
treea0ac0ed6731ddf6e453c81a9391566202a6f6c09 /src/lex.cpp
parent9e12b8536648a30377040f407e06ea0713db91b4 (diff)
downloadresp-7164809b051050fb4f4877793b9739b6177bcab1.tar.gz
resp-7164809b051050fb4f4877793b9739b6177bcab1.tar.bz2
resp-7164809b051050fb4f4877793b9739b6177bcab1.zip
Ditch Exp type and use AST even at lex time.
git-svn-id: http://svn.drobilla.net/resp/tuplr@182 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/lex.cpp')
-rw-r--r--src/lex.cpp26
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);
}