void VMTapeParser:: parseStatement(_ScriptReader& reader, ScriptBookmark& bm, TapeWriter& writer) { if (reader.compare("*")) { bm = reader.read(); writeArgument(writer, bm.state, reader.lookup(bm)); } else if (reader.compare("=")) { bm = reader.read(); writeArray(writer, bm.state, reader.lookup(bm)); } else if (reader.compare("^")) { bm = reader.read(); writeMessage(writer, reader.lookup(bm), SEND_TAPE_MESSAGE_ID); } else if (reader.compare("%")) { bm = reader.read(); ident_t message = reader.lookup(bm); if (message.find('.') != NOTFOUND_POS) { writeExtension(writer, reader.lookup(bm), PUSHE_TAPE_MESSAGE_ID); } else writeMessage(writer, reader.lookup(bm), PUSHM_TAPE_MESSAGE_ID); } else writeObject(writer, bm.state, reader.lookup(bm)); }
bool CFParser :: parseGrammarMode(_ScriptReader& reader) { ScriptBookmark bm = reader.read(); while (!reader.compare(";")) { if (reader.compare("symbolic")) { _symbolMode = true; } // else throw EParseError(reader.info.column, reader.info.row); bm = reader.read(); } return true; }
void TreeScriptParser :: parseScope(_ScriptReader& reader, ScriptBookmark& bm, SyntaxWriter& writer) { bm = reader.read(); while (!reader.Eof() && !reader.compare(")")) { parseStatement(reader, bm, writer); bm = reader.read(); } }
void TreeScriptParser :: parseStatement(_ScriptReader& reader, ScriptBookmark& bm, SyntaxWriter& writer) { int type = _tokens.get(reader.lookup(bm)); if (type != 0) { writer.newNode((LexicalType)type); bm = reader.read(); if (reader.compare("(")) { parseScope(reader, bm, writer); } else if (reader.compare("=")) { bm = reader.read(); writer.appendNode(lxTerminal, reader.lookup(bm)); } else throw EParseError(bm.column, bm.row); writer.closeNode(); } else throw EParseError(bm.column, bm.row); }
bool CFParser :: parseGrammarRule(_ScriptReader& reader) { ScriptBookmark bm = reader.read(); if (bm.state != dfaIdentifier) throw EParseError(bm.column, bm.row); size_t ruleId = mapRuleId(reader.lookup(bm)); reader.read(); if (!reader.compare("::=")) throw EParseError(bm.column, bm.row); bm = reader.read(); Rule rule; defineGrammarRule(reader, bm, rule, ruleId); addRule(ruleId, rule); return true; }
void CFParser :: defineGrammarRule(_ScriptReader& reader, ScriptBookmark& bm, Rule& rule, ref_t ruleId) { // read: terminal [nonterminal] ; // read: nonterminal [nonterminal2] ; rule.type = rtNormal; int applyMode = 0; while (!reader.compare(";") || bm.state == dfaQuote) { if (bm.state == dfaQuote) { if (rule.terminal) { rule.nonterminal = defineGrammarRule(reader, bm, ruleId, rule.nonterminal); break; } else if (rule.nonterminal) { rule.type = rtChomski; rule.terminal = defineGrammarRule(reader, bm, ruleId); break; } else rule.terminal = writeBodyText(reader.lookup(bm)); } else if (reader.compare("<=")) { saveScript(reader, rule, applyMode); } else if (bm.state == dfaPrivate) { if (rule.terminal) { rule.nonterminal = defineGrammarRule(reader, bm, ruleId, rule.nonterminal); break; } else if (rule.nonterminal) { rule.type = rtChomski; rule.terminal = defineGrammarRule(reader, bm, ruleId); break; } else { rule.terminal = -1; // rule.prefixPtr = defineDSARule(token, reader); if (reader.compare(LITERAL_KEYWORD)) { applyMode = LITERAL_MODE; } else if (reader.compare(NUMERIC_KEYWORD)) { applyMode = NUMERIC_MODE; } else if (reader.compare(EPS_KEYWORD)) { if (rule.nonterminal) throw EParseError(bm.column, bm.row); rule.nonterminal = -1; rule.terminal = -1; applyMode = IDLE_MODE; } else if (reader.compare(EOF_KEYWORD)) { applyMode = EOF_MODE; } else if (reader.compare(REFERENCE_KEYWORD)) { applyMode = REFERENCE_MODE; } else if (reader.compare(IDENTIFIER_KEYWORD)) { applyMode = IDENTIFIER_MODE; } else if (reader.compare(EOL_KEYWORD)) { applyMode = EOL_MODE; } else if (reader.compare(ANYCHR_KEYWORD)) { applyMode = LETTER_MODE; } } } else if (bm.state == dfaIdentifier) { if (rule.nonterminal == 0) { //rule.prefixPtr = defineDSARule(token, reader); rule.nonterminal = mapRuleId(reader.lookup(bm)); } else if (rule.terminal == 0) { rule.type = rtChomski; rule.terminal = mapRuleId(reader.lookup(bm)); } else { if (rule.type == rtChomski) { rule.terminal = defineGrammarRule(reader, bm, ruleId, rule.terminal); } else rule.nonterminal = defineGrammarRule(reader, bm, ruleId, rule.nonterminal); break; } } bm = reader.read(); } // rule.postfixPtr = defineDSARule(token, reader); defineApplyRule(rule, applyMode); }
void CFParser :: saveScript(_ScriptReader& reader, Rule& rule, int& mode) { bool prefixMode = false; if (rule.terminal == 0 && rule.nonterminal == 0) { prefixMode = true; rule.prefixPtr = _body.Length(); } else rule.postfixPtr = _body.Length(); MemoryWriter writer(&_body); ScriptBookmark bm = reader.read(); while (!reader.compare("=>") || bm.state == dfaQuote) { if (bm.state == dfaPrivate) { if (rule.saveTo != NULL) throw EParseError(bm.column, bm.row); if (reader.compare(REFERENCE_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveReference; mode = REFERENCE_MODE; } else if (reader.compare(IDENTIFIER_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveReference; mode = IDENTIFIER_MODE; } else if (reader.compare(LITERAL_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveLiteral; mode = LITERAL_MODE; } else if (reader.compare(NUMERIC_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveReference; mode = NUMERIC_MODE; } writer.writeChar((char)0); rule.postfixPtr = _body.Length(); } else if (bm.state == dfaQuote && reader.compare(REFERENCE_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveLiteral; mode = REFERENCE_MODE; } else if (bm.state == dfaQuote && reader.compare(IDENTIFIER_KEYWORD)) { rule.terminal = -1; rule.saveTo = saveLiteral; mode = IDENTIFIER_MODE; } else { ident_t token = reader.lookup(bm); if (bm.state == dfaQuote) { writer.writeChar('\"'); writer.writeLiteral(token, getlength(token)); writer.writeChar('\"'); } else writer.writeLiteral(token, getlength(token)); writer.writeChar(' '); } bm = reader.read(); } writer.writeChar((char)0); }