Exemple #1
0
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);
}
Exemple #2
0
void saveReference(_ScriptReader& scriptReader, CFParser* parser, ref_t ptr, ScriptLog& log)
{
   ScriptBookmark bm;
   parser->readScriptBookmark(ptr, bm);

   log.write(scriptReader.lookup(bm));
}
Exemple #3
0
void CFParser :: generateOutput(int offset, _ScriptReader& scriptReader, ScriptLog& log)
{
   if (offset == 0)
      return;

   MemoryReader reader(&_body, offset);
   Stack<TraceItem> stack(TraceItem(0));
   TraceItem item;
   reader.read(&item, sizeof(TraceItem));
   while (true) {
      stack.push(item);
      if (item.previous == 0)
         break;

      reader.seek(item.previous);
      reader.read(&item, sizeof(TraceItem));
   }

   Stack<size_t> postfixes;
   while (stack.Count() > 0) {
      TraceItem item = stack.pop();
      if (item.ruleKey == 0) {
         size_t ptr = postfixes.pop();
         if (ptr)
            log.write(getBodyText(ptr));
      }
      else {
         ident_t keyName = retrieveKey(_names.start(), item.ruleKey >> 8, DEFAULT_STR);

         Rule rule = _table.get(item.ruleKey);
         if (rule.prefixPtr != 0) {
            log.write(getBodyText(rule.prefixPtr));

            if (rule.saveTo != NULL)
               rule.saveTo(scriptReader, this, item.terminal, log);

            // HOTFIX: to prevent too long line
            log.write('\n');
         }

         postfixes.push(rule.postfixPtr);
      }

   }
   log.write((char)0);
}
Exemple #4
0
void CFParser :: parse(_ScriptReader& reader, MemoryDump* output)
{
   if (_symbolMode)
      reader.switchDFA(dfaSymbolic);

   ScriptLog log;

   size_t startId = mapRuleId("start");
   while (!reader.Eof()) {
      MemoryWriter writer(&_body);
      int presaved = writer.Position();

      int trace = buildDerivationTree(reader, startId, writer);
      generateOutput(trace, reader, log);

      IdentifierTextReader logReader((const char*)log.getBody());
      ScriptReader scriptReader(&logReader);
      
      _baseParser->parse(scriptReader, output);

      _body.trim(presaved);
      log.clear();
   }
}