diff options
author | John Hodge (bugs) <tpg@mutabah.net> | 2014-12-07 10:53:56 +0800 |
---|---|---|
committer | John Hodge (bugs) <tpg@mutabah.net> | 2014-12-07 10:53:56 +0800 |
commit | 6178198e6a5f0ff2384660253347b6e9b5d686e2 (patch) | |
tree | 5289ad5107154f3dcebf4efaa98bb34558c3e027 /parse/lex.cpp | |
parent | c325b671c1a44c90c8ce570b901219bcc2ae0a38 (diff) | |
download | mrust-6178198e6a5f0ff2384660253347b6e9b5d686e2.tar.gz |
TTStream implementation, doesn't compile yet (need to fix TT storage)
Diffstat (limited to 'parse/lex.cpp')
-rw-r--r-- | parse/lex.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/parse/lex.cpp b/parse/lex.cpp index 99d787fb..e48cb9bb 100644 --- a/parse/lex.cpp +++ b/parse/lex.cpp @@ -541,6 +541,10 @@ const char* Token::typestr(enum eTokenType type) return os;
}
+TokenTree::TokenTree()
+{
+
+}
TokenTree::TokenTree(Token tok)
{
@@ -551,15 +555,34 @@ TokenTree::TokenTree(::std::vector<TokenTree> subtrees) }
TTStream::TTStream(const TokenTree& input_tt):
- m_input_tt(input_tt),
- m_cur_layer(&input_tt)
+ m_input_tt(input_tt)
{
+ m_stack.push_back( ::std::make_pair(0, &input_tt) );
}
TTStream::~TTStream()
{
}
Token TTStream::realGetToken()
{
+ while(m_stack.size() > 0)
+ {
+ // If current index is above TT size, go up
+ unsigned int& idx = m_stack.back().first;
+ const TokenTree& tree = *m_stack.back().second;
+ if(idx < tree.size())
+ {
+ if( tree[idx].size() == 0 ) {
+ idx ++;
+ return tree[idx-1].tok();
+ }
+ else {
+ m_stack.push_back( ::std::make_pair(0, &tree[idx] ) );
+ }
+ }
+ else {
+ m_stack.pop_back();
+ }
+ }
return Token(TOK_EOF);
}
|