本文整理汇总了C++中Scanner::scan方法的典型用法代码示例。如果您正苦于以下问题:C++ Scanner::scan方法的具体用法?C++ Scanner::scan怎么用?C++ Scanner::scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner::scan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseKeyword
bool ScriptParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{
if (keyword==Scanner::K_while || keyword==Scanner::K_if || keyword==Scanner::K_elseif)
{
mControlParser.reset();
if (mControlParser.parseKeyword (keyword, loc, scanner))
scanner.scan (mControlParser);
mControlParser.appendCode (mOutput.getCode());
return true;
}
/// \todo add an option to disable this nonsense
if (keyword==Scanner::K_endif)
{
// surplus endif
getErrorHandler().warning ("endif without matching if/elseif", loc);
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return true;
}
if (keyword==Scanner::K_end && mEnd)
{
return false;
}
mLineParser.reset();
if (mLineParser.parseKeyword (keyword, loc, scanner))
scanner.scan (mLineParser);
return true;
}
示例2: parseWhileBody
bool ControlParser::parseWhileBody (int keyword, const TokenLoc& loc, Scanner& scanner)
{
if (keyword==Scanner::K_endwhile)
{
Codes loop;
Codes expr;
mExprParser.append (expr);
Generator::jump (loop, -static_cast<int> (mCodeBlock.size()+expr.size()));
std::copy (expr.begin(), expr.end(), std::back_inserter (mCode));
Codes skip;
Generator::jumpOnZero (skip, mCodeBlock.size()+loop.size()+1);
std::copy (skip.begin(), skip.end(), std::back_inserter (mCode));
std::copy (mCodeBlock.begin(), mCodeBlock.end(), std::back_inserter (mCode));
Codes loop2;
Generator::jump (loop2, -static_cast<int> (mCodeBlock.size()+expr.size()+skip.size()));
if (loop.size()!=loop2.size())
throw std::logic_error (
"internal compiler error: failed to generate a while loop");
std::copy (loop2.begin(), loop2.end(), std::back_inserter (mCode));
mState = WhileEndwhileState;
return true;
}
else if (keyword==Scanner::K_if || keyword==Scanner::K_while)
{
// nested
ControlParser parser (getErrorHandler(), getContext(), mLocals, mLiterals);
if (parser.parseKeyword (keyword, loc, scanner))
scanner.scan (parser);
parser.appendCode (mCodeBlock);
return true;
}
else
{
mLineParser.reset();
if (mLineParser.parseKeyword (keyword, loc, scanner))
scanner.scan (mLineParser);
return true;
}
}
示例3: parseArguments
void ExprParser::parseArguments (const std::string& arguments, Scanner& scanner,
std::vector<Interpreter::Type_Code>& code, bool invert)
{
ExprParser parser (getErrorHandler(), getContext(), mLocals, mLiterals, true);
StringParser stringParser (getErrorHandler(), getContext(), mLiterals);
std::stack<std::vector<Interpreter::Type_Code> > stack;
for (std::string::const_iterator iter (arguments.begin()); iter!=arguments.end();
++iter)
{
if (*iter=='S' || *iter=='c')
{
stringParser.reset();
if (*iter=='c') stringParser.smashCase();
scanner.scan (stringParser);
if (invert)
{
std::vector<Interpreter::Type_Code> tmp;
stringParser.append (tmp);
stack.push (tmp);
}
else
stringParser.append (code);
}
else
{
parser.reset();
scanner.scan (parser);
std::vector<Interpreter::Type_Code> tmp;
char type = parser.append (tmp);
if (type!=*iter)
Generator::convert (tmp, type, *iter);
if (invert)
stack.push (tmp);
else
std::copy (tmp.begin(), tmp.end(), std::back_inserter (code));
}
}
while (!stack.empty())
{
std::vector<Interpreter::Type_Code>& tmp = stack.top();
std::copy (tmp.begin(), tmp.end(), std::back_inserter (code));
stack.pop();
}
}
示例4: main
int main(int argc, char** argv)
{
if (argc<3)
{
cout << "Not enough arguments. You must provide a valid infile." << endl;
return 0;
}
ofstream out;
out.open(argv[2]);
Scanner* s = new Scanner();
try
{
s->scan(argv[1]);
print_toks(s->toks,out);
out << "Total Tokens = " << s->toks.size() << endl;
out.close();
delete s;
}
catch (exception& e)
{
print_toks(s->toks, out);
// cout << e.what();
out << e.what();
out.close();
delete s;
}
}
示例5: skip
bool Compiler::QuickFileParser::parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner)
{
SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip);
return true;
}
示例6: parseSpecial
bool FileParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{
if (code==Scanner::S_newline)
{
if (mState==BeginState)
{
// ignore empty lines
return true;
}
if (mState==BeginCompleteState)
{
// parse the script body
mScriptParser.reset();
scanner.scan (mScriptParser);
mState = EndNameState;
scanner.allowNameStartingwithDigit();
return true;
}
if (mState==EndCompleteState || mState==EndNameState)
{
// we are done here -> ignore the rest of the script
return false;
}
}
return Parser::parseSpecial (code, loc, scanner);
}
示例7: runScanner
void ScannerPage::runScanner ()
{
QString s;
config.getData(Config::ScannerPath, s);
QString s2("*");
SymbolDialog *dialog = new SymbolDialog(this,
s,
s,
s2,
Q3FileDialog::ExistingFiles);
dialog->setCaption(tr("Select scanners to run"));
int rc = dialog->exec();
if (rc == QDialog::Accepted)
{
QStringList l = dialog->selectedFiles();
int loop;
QDir dir;
for (loop = 0; loop < (int) l.count(); loop++)
{
QFileInfo fi(l[loop]);
Scanner *sdialog = new Scanner(fi.fileName(), chartIndex);
connect(sdialog, SIGNAL(exitScanner()), this, SLOT(refreshList()));
connect(sdialog, SIGNAL(message(QString)), this, SIGNAL(message(QString)));
sdialog->show();
sdialog->scan();
delete sdialog;
}
}
delete dialog;
}
示例8: parseExpression
void LineParser::parseExpression (Scanner& scanner, const TokenLoc& loc)
{
mExprParser.reset();
if (!mExplicit.empty())
{
mExprParser.parseName (mExplicit, loc, scanner);
if (mState==MemberState)
mExprParser.parseSpecial (Scanner::S_member, loc, scanner);
else
mExprParser.parseSpecial (Scanner::S_ref, loc, scanner);
}
scanner.scan (mExprParser);
char type = mExprParser.append (mCode);
mState = EndState;
switch (type)
{
case 'l':
Generator::report (mCode, mLiterals, "%g");
break;
case 'f':
Generator::report (mCode, mLiterals, "%f");
break;
default:
throw std::runtime_error ("unknown expression result type");
}
}
示例9: parseName
bool ScriptParser::parseName (const std::string& name, const TokenLoc& loc,
Scanner& scanner)
{
mLineParser.reset();
if (mLineParser.parseName (name, loc, scanner))
scanner.scan (mLineParser);
return true;
}
示例10: parseProgram
Status* Parser::parseProgram(const string& code) {
Scanner scanner;
try {
Status* s = scanner.scan(code, _tokens);
if (s) {
return s;
}
} catch (ErrorInfoHolder* error) {
return new Status(error->getMessage(), error->getPosition());
}
return parseTopLevel();
}
示例11: parseName
bool ControlParser::parseName (const std::string& name, const TokenLoc& loc, Scanner& scanner)
{
if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState ||
mState==WhileBodyState)
{
scanner.putbackName (name, loc);
mLineParser.reset();
scanner.scan (mLineParser);
return true;
}
return Parser::parseName (name, loc, scanner);
}
示例12: parseKeyword
bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{
if (mState==StartState)
{
if (keyword==Scanner::K_if || keyword==Scanner::K_elseif)
{
if (keyword==Scanner::K_elseif)
getErrorHandler().warning ("elseif without matching if", loc);
mExprParser.reset();
scanner.scan (mExprParser);
mState = IfEndState;
return true;
}
else if (keyword==Scanner::K_while)
{
mExprParser.reset();
scanner.scan (mExprParser);
mState = WhileEndState;
return true;
}
}
else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState ||
mState==IfElseJunkState)
{
if (parseIfBody (keyword, loc, scanner))
return true;
}
else if (mState==WhileBodyState)
{
if ( parseWhileBody (keyword, loc, scanner))
return true;
}
return Parser::parseKeyword (keyword, loc, scanner);
}
示例13: parseExtInstMnemo
Inst ExtManager::parseExtInstMnemo(Scanner& scanner, Brigantine& bw, int* vx) const
{
assert(scanner.peek().kind() == EExtInstName);
// Parse mnemo prefix adding suffices until there is an extension which can handle it.
// This prefix has the form <vendor>_<extension>
string prefix = scanner.scan().text();
while (!isMnemoPrefix(prefix) && scanner.peek().kind() == EExtInstSuff)
{
prefix += scanner.scan().text();
}
// Parse remaining part of instruction mnemo (typically in the form <opcode>_<suff>)
if (const Extension* e = getByPrefix(prefix)) return e->parseInstMnemo(prefix, scanner, bw, vx);
// Enabled extensions failed to parse this mnemo.
// Search for a disabled extension which might have handled it
const char* s = 0;
for (unsigned i = 0; i < size(); ++i)
{
if (!isEnabled[i] && (s = extension[i]->matchInstMnemo(prefix)) != 0)
{
scanner.syntaxError(string("Instruction \"") + s + "\" cannot be used (extension \"" + extension[i]->getName() + "\" is not enabled)");
return Inst();
}
}
// Extensions (including disabled) cannot handle this mnemo
if (!hasEnabled()) scanner.scan(); // show offending token
scanner.syntaxError("Undefined instruction");
return Inst();
}
示例14: parseSpecial
bool ScriptParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{
if (code==Scanner::S_newline) // empty line
return true;
if (code==Scanner::S_open) /// \todo Option to switch this off
{
scanner.putbackSpecial (code, loc);
return parseKeyword (Scanner::K_if, loc, scanner);
}
mLineParser.reset();
if (mLineParser.parseSpecial (code, loc, scanner))
scanner.scan (mLineParser);
return true;
}
示例15: parseMnemoGcnMem
Inst parseMnemoGcnMem(unsigned opCode, Scanner& scanner, Brigantine& bw, int* vx)
{
OptionalU const vector = scanner.tryEatToken(EMVector);
string const segment = scanner.scan().text();
if (segment != AMD_GCN_SEGMENT_SUFF) scanner.syntaxError("missing or invalid segment name");
int vx2 = -1;
InstMem res = parseMnemoMem(opCode, scanner, bw, &vx2);
if (res.segment() != BRIG_SEGMENT_FLAT) scanner.syntaxError("invalid segment");
if (vx2 != 1) scanner.syntaxError("invalid vX suffix");
res.segment() = BRIG_SEGMENT_AMD_GCN;
if (vx) *vx = vector.isInitialized() ? vector.value() : 1;
return res;
}