当前位置: 首页>>代码示例>>C++>>正文


C++ Lexer::eat方法代码示例

本文整理汇总了C++中Lexer::eat方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexer::eat方法的具体用法?C++ Lexer::eat怎么用?C++ Lexer::eat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lexer的用法示例。


在下文中一共展示了Lexer::eat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
	}
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:34,代码来源:Parser.cpp

示例2: 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);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:29,代码来源:Parser.cpp

示例3: 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);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:25,代码来源:Parser.cpp

示例4: parseImportDecl

ImportDecl parseImportDecl (Lexer& lex)
{
	Span spStart, spEnd;

	spStart = lex.eat(tImport).span;
	auto nameTok = lex.eat(tIdent, tString);
	auto name = nameTok.str;
	spEnd = nameTok.span;

	return ImportDecl
		{
			.isPublic = false,
			.name = name,
			.span = spStart + spEnd
		};
}
FuncDecl parseFuncDecl (Lexer& lex)
{
	Span spStart, spEnd;

	spStart = lex.eat(tFunc).span;
	auto name = lex.eat(tIdent).str;
	auto sig = parseSigParens(lex);
	
	ExpPtr body;
/*	if (lex.current() == tEqual)
	{
		lex.advance();
		body = parseExp(lex);
	}
	else */
		body = parseBlock(lex);

	spEnd = sig->span;

	return FuncDecl
		{
			.isPublic = false,
			.name = name,
			.signature = sig,
			.body = body,
			.span = spStart + spEnd
		};
}

static FuncDecl parseConstructor (Lexer& lex)
{
	Span spStart, spEnd;
	FuncDecl result;

	result.name = lex.current().str;
	spStart = lex.eat(tIdent).span;
	result.signature = parseSigParens(lex);
	spEnd = result.signature->span;
	result.span = spStart + spEnd;
	result.body = nullptr;
	return result;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:58,代码来源:Parser.cpp

示例5: parseMem

ExpPtr parseMem (Lexer& lex, ExpPtr in)
{
	lex.eat(tDot);

	auto mem = lex.eat(tIdent);

	return Exp::make(eMem, mem.str, { in }, 
			in->span + mem.span);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:9,代码来源:Parser.cpp

示例6: parseTypePoly

TyPtr parseTypePoly (Lexer& lex, Span& sp)
{
	Span spStart, spEnd;

	spStart = lex.eat(tLambda).span;
	spEnd = lex.current().span;
	auto name = lex.eat(tIdent).str;

	sp = spStart + spEnd;
	return Ty::makePoly(name);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:11,代码来源:Parser.cpp

示例7: parseTypeList

TyPtr parseTypeList (Lexer& lex, Span& sp)
{
	Span spStart, spEnd;

	spStart = lex.eat(tLBrack).span;
	auto inner = parseType(lex, spEnd);
	spEnd = lex.eat(tRBrack).span;

	sp = spStart + spEnd;
	return Ty::makeConcrete("List", { inner });
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:11,代码来源:Parser.cpp

示例8: parseSigParens

SigPtr parseSigParens (Lexer& lex)
{
	Span spStart, spEnd;

	spStart = lex.eat(tLParen).span;
	auto res = parseSig(lex, false);
	spEnd = lex.eat(tRParen).span;

	res->span = spStart + spEnd;
	return res;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:11,代码来源:Parser.cpp

示例9: parseBlock

ExpPtr parseBlock (Lexer& lex)
{
	Span spStart, spEnd;
	ExpList exps;

	spStart = lex.eat(tLCurl).span;

	while (lex.current() != tRCurl)
		parseBlockExp(lex, exps);

	spEnd = lex.eat(tRCurl).span;

	return Exp::make(eBlock, exps, spStart + spEnd);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:14,代码来源:Parser.cpp

示例10: parseiGet

ExpPtr parseiGet (Lexer& lex)
{
	// ^get <ty> <idx> <term>

	Span spStart, spEnd, spType;

	spStart = lex.eat(tiGet).span;
	auto ty = parseType(lex, spType);
	auto idx = lex.eat(tNumberInt).valueInt;
	auto body = parseTerm(lex);
	spEnd = body->span;

	auto e = Exp::make(eiGet, idx, { body }, spStart + spEnd);
	e->setType(ty);

	return e;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:17,代码来源:Parser.cpp

示例11: 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
		};
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:46,代码来源:Parser.cpp

示例12: parseiCall

ExpPtr parseiCall (Lexer& lex)
{
	// ^call <ty> <name>
	Span spStart, spEnd, spType;

	spStart = lex.eat(tiCall).span;
	auto ty = parseType(lex, spType);
	spEnd = lex.current().span;
	auto tag = lex.eat(tString).str;

	if (ty->kind != tyConcrete || ty->name != "Fn")
		throw spType.die("^call expects function type");

	auto e = Exp::make(eiCall, tag, {}, spStart + spEnd);
	e->setType(ty);

	return e;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:18,代码来源:Parser.cpp

示例13: parseLet

ExpPtr parseLet (Lexer& lex)
{
	Span spStart, spEnd;
	std::string name;
	TyPtr ty;
	ExpPtr init;

	// 'let' <var> '=' <exp> ';'

	spStart = lex.eat(tLet).span;
	parseVar(lex, name, ty, spEnd);
	lex.eat(tEqual);
	init = parseExp(lex);
	spEnd = init->span;

	auto e = Exp::make(eLet, ty, name, { init }, spStart + spEnd);
	return e;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:18,代码来源:Parser.cpp

示例14: 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;
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:18,代码来源:Parser.cpp

示例15: 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);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:19,代码来源:Parser.cpp


注:本文中的Lexer::eat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。