diff options
author | David Robillard <d@drobilla.net> | 2010-12-02 06:16:29 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-02 06:16:29 +0000 |
commit | 563a807be78bfe12e5bfbb9ff0d6da44242696c4 (patch) | |
tree | 13cf7ce3b90d072d6e7106c7d2eb4da33209acb0 /src/lex.cpp | |
parent | 32ac40a9ef62d2109563e36fb7cd478426c3489f (diff) | |
download | resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.gz resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.bz2 resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.zip |
Represent code as list structure (i.e. traditional LISP lists built from pairs), rather than tuple structure.
Remove unused/crufty depoly stage.
Remove cps from AST interface (but keep cps.cpp code around for later).
Improved command line interface for compilation stages (options -T -L -S).
git-svn-id: http://svn.drobilla.net/resp/resp@277 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/lex.cpp')
-rw-r--r-- | src/lex.cpp | 25 |
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 } |