void CFParser :: parse(_ScriptReader& reader, TapeWriter& writer) { // if (_symbolMode) // reader.switchDFA(dfaSymbolic); ScriptLog log; TokenInfo token(this, &log); token.read(reader); size_t readerRollback = reader.Position(); //size_t outputRollback = compiler->Position(); size_t startId = mapRuleId("start"); if (token.state != dfaEOF) { if (!applyRule(startId, token, reader)) throw EParseError(token.column, token.row); if (token.state != dfaEOF) throw EParseError(token.column, token.row); } IdentifierTextReader logReader((ident_t)log.getBody()); CachedScriptReader scriptReader(&logReader); _baseParser->parse(scriptReader, writer); }
bool CFParser :: applyRule(size_t ruleId, TokenInfo& token, _ScriptReader& reader) { ident_t name = retrieveKey(_names.start(), ruleId, DEFAULT_STR); size_t readerRollback = reader.Position(); size_t coderRollback = token.LogPosition(); RuleMap::Iterator it = _rules.getIt(ruleId); while(!it.Eof()) { CFParser::TokenInfo tokenCopy(token); if ((*it).apply(*it, tokenCopy, reader)) { tokenCopy.save(token); return true; } // roll back reader.seek(readerRollback); token.trimLog(coderRollback); it = _rules.getNextIt(ruleId, it); } return false; }