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


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

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


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

示例1: 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

示例2: 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

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

示例4: parseTypeConcrete

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

	std::vector<TyPtr> sub;
	spStart = lex.current().span;
	auto kind = lex.eat(tIdent).str;

	if (lex.current() == tLParen)
		parseTypeTupleRaw(lex, sub, spEnd);

	sp = spStart + spEnd;

	return Ty::makeConcrete(kind, sub);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:15,代码来源:Parser.cpp

示例5: 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

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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: parsePublic

void parsePublic (Lexer& lex, GlobProto& proto)
{
	Span span = lex.eat(tPub).span;

	if (lex.current() == tFunc)
	{
		auto fn = parseFuncDecl(lex);
		fn.isPublic = true;
		fn.span = span + fn.span;
		proto.funcs.push_back(fn);
	}
	else if (lex.current() == tImport)
	{
		auto imp = parseImportDecl(lex);
		imp.isPublic = true;
		imp.span = span + imp.span;
		proto.imports.push_back(imp);
	}
	else
		lex.unexpect();
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:21,代码来源:Parser.cpp

示例12: parseAssign

ExpPtr parseAssign (Lexer& lex, ExpPtr left)
{
	if (lex.current() != tEqual)
		return left;

	lex.eat(tEqual);

	auto right = parseExp(lex);

	lex.expect(tSemicolon);

	return Exp::make(eAssign, { left, right }, left->span + right->span);
}
开发者ID:iitalics,项目名称:Jupiter,代码行数:13,代码来源:Parser.cpp

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

示例14: 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

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


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