本文整理汇总了C++中Lexer::advance方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexer::advance方法的具体用法?C++ Lexer::advance怎么用?C++ Lexer::advance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer::advance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseTermPrefix
ExpPtr parseTermPrefix (Lexer& lex)
{
Token tok = lex.current();
switch (tok.tok)
{
case tNumberInt:
tok = lex.advance();
return Exp::make(eInt, tok.valueInt, {}, tok.span);
case tNumberReal:
tok = lex.advance();
return Exp::make(eReal, tok.valueReal, {}, tok.span);
case tString:
tok = lex.advance();
return Exp::make(eString, tok.str, {}, tok.span);
case tTrue:
case tFalse:
tok = lex.advance();
return Exp::make(eBool, tok == tTrue, {}, tok.span);
case tIdent:
tok = lex.advance();
return Exp::make(eVar, tok.str, bool(true), {}, tok.span);
case tLParen:
return parseTuple(lex);
case tIf:
return parseCond(lex);
case tLCurl:
return parseBlock(lex);
case tLBrack:
return parseList(lex);
case tFunc: case tLambda:
return parseLambda(lex);
case tiMake: return parseiMake(lex);
case tiGet: return parseiGet(lex);
case tiPut: return parseiPut(lex);
case tiCall: return parseiCall(lex);
default:
//lex.expect("term");
lex.unexpect();
return nullptr;
}
}
示例2: parseCond
ExpPtr parseCond (Lexer& lex)
{
Span spStart, spEnd;
ExpPtr expCond, expThen, expElse;
bool blockRequired = true;
spStart = lex.eat(tIf).span;
expCond = parseExp(lex);
if (lex.current() == tThen)
{
lex.advance();
blockRequired = false;
}
expThen = blockRequired ?
parseBlock(lex) :
parseExp(lex);
if (lex.current() == tElse)
{
lex.advance();
if (blockRequired)
{
// if {} else {}
// if {} else if ...
if (lex.current() != tIf)
lex.expect(tLCurl);
expElse = parseExp(lex);
}
else
expElse = parseExp(lex);
spEnd = expElse->span;
}
else if (!blockRequired)
lex.expect(tElse);
else
{
auto expUnit = Exp::make(eTuple, {}, spStart);
expThen->subexps.push_back(expUnit);
expElse = expUnit; // no else => unit (zero tuple)
spEnd = expThen->span;
}
return Exp::make(eCond, { expCond, expThen, expElse }, spStart + spEnd);
}
示例3: parseFor
ExpPtr parseFor (Lexer& lex)
{
Span spStart, spEnd;
ExpPtr val1, val2, body;
spStart = lex.eat(tFor).span;
auto var = lex.eat(tIdent).str;
lex.eat(tColon);
val1 = parseExp(lex);
if (lex.current() == tArrow)
{
lex.advance();
val2 = parseExp(lex);
}
else
val2 = nullptr;
body = parseBlock(lex);
spEnd = body->span;
if (val2 == nullptr)
return Exp::make(eForEach, var,
{ val1, body }, spStart + spEnd);
else
return Exp::make(eForRange, var,
{ val1, val2, body }, spStart + spEnd);
}
示例4: parseBlockExp
void parseBlockExp (Lexer& lex, ExpList& list)
{
switch (lex.current().tok)
{
case tSemicolon:
lex.advance();
break;
case tLet:
list.push_back(parseLet(lex));
lex.eat(tSemicolon);
break;
case tLCurl:
list.push_back(parseBlock(lex));
break;
case tIf:
list.push_back(parseCond(lex));
break;
case tLoop:
list.push_back(parseLoop(lex));
break;
case tFor:
list.push_back(parseFor(lex));
break;
// everthing else does
default:
list.push_back(parseAssign(lex, parseExp(lex)));
if (lex.current() != tSemicolon)
lex.expect(tRCurl);
else
lex.eat(tSemicolon);
break;
}
}
示例5: parseLambda
ExpPtr parseLambda (Lexer& lex)
{
Span spStart, spEnd;
SigPtr sig;
ExpPtr body;
spStart = lex.current().span;
if (lex.current() == tFunc)
{
lex.advance();
sig = parseSigParens(lex);
body = parseBlock(lex);
}
else
{
lex.eat(tLambda);
sig = parseSig(lex, true);
lex.eat(tArrow);
body = parseExp(lex);
}
spEnd = body->span;
return Exp::make(eLambda, sig->toSigType(), "", { body }, spStart + spEnd);
}
示例6: parseVar
void parseVar (Lexer& lex, std::string& name, TyPtr& ty, Span& sp)
{
sp = lex.current().span;
name = lex.eat(tIdent).str;
if (lex.current() == tColon)
{
Span spEnd;
lex.advance();
ty = parseType(lex, spEnd);
sp = sp + spEnd;
}
else
ty = Ty::makeWildcard();
}
示例7: parseTypeDecl
TypeDecl parseTypeDecl (Lexer& lex)
{
Span spStart, spEnd, spType;
std::vector<FuncDecl> ctors;
spStart = lex.eat(tType).span;
auto ty = parseType(lex, spType);
if (ty->kind != tyConcrete)
throw spType.die("invalid form of type in declaration");
for (auto sub = ty->subtypes; !sub.nil(); ++sub)
{
auto sty = sub.head();
if (sty->kind != tyPoly)
throw spType.die("arguments to type must be polytypes");
for (auto sty2 : sub.tail())
if (sty2->kind == tyPoly &&
sty->name == sty2->name)
throw spType.die("identical polytypes in declaration");
}
lex.eat(tEqual);
for (;;)
{
auto ctor = parseConstructor(lex);
spEnd = ctor.span;
ctors.push_back(ctor);
if (lex.current() == tComma)
lex.advance();
else
break;
}
return TypeDecl
{
ty->name,
ty->subtypes,
std::move(ctors),
spStart + spEnd
};
}
示例8: esNif
bool Importar::esNif(const std::string &lin, Lexer &lex)
{
bool toret = false;
unsigned int pos = lex.getCurrentPos();
if ( std::isalpha( lex.getCurrentChar() ) ) {
lex.advance();
if ( Lexer::StandardDelimiters.find( lex.getCurrentChar() ) != std::string::npos
|| this->esSeparador( lex.getCurrentChar() ) )
{
toret = true;
}
}
lex.reset( pos );
return toret;
}
示例9: parseTypeTupleRaw
static void parseTypeTupleRaw (Lexer& lex, std::vector<TyPtr>& out, Span& sp)
{
Span spStart, spEnd;
spStart = lex.eat(tLParen).span;
while (lex.current() != tRParen)
{
out.push_back(parseType(lex, spEnd));
if (lex.current() == tComma)
lex.advance();
else
break;
}
spEnd = lex.eat(tRParen).span;
sp = spStart + spEnd;
}
示例10: parseList
ExpPtr parseList (Lexer& lex)
{
Span spStart, spEnd;
ExpList vals;
spStart = lex.eat(tLBrack).span;
while (lex.current() != tRBrack)
{
vals.push_back(parseExp(lex));
if (lex.current() == tComma)
lex.advance();
else
break;
}
spEnd = lex.eat(tRBrack).span;
return Exp::make(eList, std::move(vals), spStart + spEnd);
}
示例11: parseTypeTuple
TyPtr parseTypeTuple (Lexer& lex, Span& sp)
{
Span spStart, spEnd;
std::vector<TyPtr> inners;
parseTypeTupleRaw(lex, inners, spStart);
if (lex.current() == tArrow)
{
lex.advance();
inners.push_back(parseType(lex, spEnd));
sp = spStart + spEnd;
return Ty::makeFn(inners);
}
sp = spStart;
if (inners.size() == 1)
return inners[0];
return Ty::makeConcrete("Tuple", inners);
}
示例12: parseType
TyPtr parseType (Lexer& lex, Span& sp)
{
switch (lex.current().tok)
{
case tLambda:
return parseTypePoly(lex, sp);
case tLBrack:
return parseTypeList(lex, sp);
case tLParen:
return parseTypeTuple(lex, sp);
case tIdent:
return parseTypeConcrete(lex, sp);
case tWildcard:
sp = lex.current().span;
lex.advance();
return Ty::makeWildcard();
default:
lex.expect("type");
return nullptr;
}
}
示例13: parseTuple
ExpPtr parseTuple (Lexer& lex)
{
ExpList exps;
ExpPtr e;
Span spStart, spEnd;
spStart = lex.eat(tLParen).span;
while (lex.current() != tRParen)
{
e = parseExp(lex);
exps.push_back(e);
if (lex.current() == tComma)
lex.advance();
else
break;
}
spEnd = lex.eat(tRParen).span;
return Exp::make(eTuple, exps, spStart + spEnd);
}
示例14: parseSig
SigPtr parseSig (Lexer& lex, bool anything)
{
auto res = std::make_shared<Sig>();
// sig := (<var> (',' <var>)*)?
for (;; anything = true)
{
if (anything)
lex.expect(tIdent);
else if (lex.current() != tIdent)
break;
parseVar(lex, res);
if (lex.current() == tComma)
lex.advance();
else
break;
}
return res;
}
示例15: parseExp
ExpPtr parseExp (Lexer& lex)
{
Span spStart, spEnd;
ExpList vals;
ExpPtr e;
Token tok;
e = parseTerm(lex);
vals.push_back(e);
spStart = spEnd = e->span;
while (lex.current() == tIdent)
if (lex.current().isOperator())
{
// <op>
tok = lex.advance();
e = Exp::make(eVar, tok.str, bool(true), {}, tok.span);
vals.push_back(e);
// <term>
e = parseTerm(lex);
vals.push_back(e);
spEnd = e->span;
}
else
lex.expect("operator");
if (vals.size() == 1)
return vals[0];
// else if (vals.size() == 3)
// return Exp::make(eCall, { vals[1], vals[0], vals[2] },
// spStart + spEnd);
else
return Exp::make(eInfix, vals, spStart + spEnd);
}