本文整理汇总了C++中parseExpression函数的典型用法代码示例。如果您正苦于以下问题:C++ parseExpression函数的具体用法?C++ parseExpression怎么用?C++ parseExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parseExpression函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parseExpression
/***************************************************************
* Function: CodeParser::parseParamExpr()
* Purpose : Parse the XML code of a parameterized expression
* Initial : Maxime Chevalier-Boisvert on November 7, 2008
****************************************************************
Revisions and bug fixes:
*/
Expression* CodeParser::parseParamExpr(const XML::Element* pElement)
{
// Parse the symbol expression
Expression* pExpr = parseExpression(pElement->getChildElement(0));
// Compute the number of arguments
size_t numArgs = pElement->getNumChildren() - 1;
// Declare a vector for the arguments
ParamExpr::ExprVector arguments;
// For each child element
for (size_t i = 0; i < numArgs; ++i)
{
// Parse this argument
arguments.push_back(parseExpression(pElement->getChildElement(i + 1)));
}
// Create and return the new parameterized expression
return new ParamExpr(
pExpr,
arguments
);
}
开发者ID:debashish1711,项目名称:mcvm,代码行数:31,代码来源:parser.cpp
示例2: match
SymbolTableEntry* Parser::parseVariablePrime(SymbolTableEntry* prevEntry){
if(isNext(tc_LBRACKET)){
match(tc_LBRACKET);
parseExpression();
match(tc_RBRACKET);
if(m_parserError){
TokenCode synch[] = {tc_RBRACKET, tc_END, tc_ASSIGNOP, tc_MULOP, tc_RELOP, tc_THEN, tc_DO, tc_COMMA, tc_RPAREN, tc_NONE};
recover(synch);
// if(isNext(tc_RBRACKET)){
// match(tc_RBRACKET);
// }
}
}
return prevEntry;
}
开发者ID:nicolai490,项目名称:---endur,代码行数:15,代码来源:parser.cpp
示例3: consumeToken
/*!
* rule ::= 'id' ( '::=' | '->' ) expression
*/
RuleNode* Parser::parseRule()
{
std::string name = token_value_;
consumeToken();
if (token_ != Lexer::Token::coloncolonequal &&
token_ != Lexer::Token::minusgreater) {
return static_cast<RuleNode*>(errorNode("missing terminating character \"::=\" or\" ->\""));
}
consumeToken();
Node* node = parseExpression();
return new RuleNode(name, node);
}
开发者ID:marcioAlmada,项目名称:railroad-diagram-generator,代码行数:18,代码来源:parser.cpp
示例4: if
shared_ptr<Expression> Parser::parseFactor()
{
if (it->tag == IDENT || it->tag == INT || it->tag == FLOAT)
{
auto exp = make_shared<Expression>();
exp->value = *it;
return exp;
}
else if (it->tag == OpenBracket)
{
auto exp = parseExpression();
match(CloseBracket);
return exp;
}
}
开发者ID:caiyulun,项目名称:compiler2014,代码行数:15,代码来源:parser.cpp
示例5: parseExpressionStatement
Symbol parseExpressionStatement(CharacterSource* source)
{
CharacterSource s = *source;
Symbol expression = parseExpression(&s);
if (!expression.valid())
return Symbol();
Span span;
if (!Space::parseCharacter(&s, ';', &span))
return Symbol();
*source = s;
if (expression.atom() != atomFunctionCall)
source->location().throwError("Statement has no effect");
return Symbol(atomExpressionStatement, expression,
newSpan(spanOf(expression) + span));
}
开发者ID:mstram,项目名称:reenigne,代码行数:15,代码来源:statement.cpp
示例6: parseArrayDefineNode
void parseArrayDefineNode(std::string&result,ArrayDefineNode*seg){
if(seg == NULL){
return;
}
char numStr[N_INT_CHAR];
sprintf(numStr, "%d", ++lineno);
result+="{\"name\":\"" + std::string(numStr) + ": array define\",\"children\":[";
result+="{\"name\":\"" + std::string(seg->type) + "\"},";
result+="{\"name\":\"" + std::string(seg->name) + "\"},";
result += "{\"name\":\"nElement\",\"children\":[{\"name\":\"";
parseExpression(result, seg->exp);
result += "\"}]}";
result+="]}";
}
开发者ID:abucraft,项目名称:OALanguage,代码行数:15,代码来源:parser.cpp
示例7: parseFunctionCall
static bool parseFunctionCall(MemoryStack* stack, LexerCarriage* carriage, Array<SyntaxError>* errors, ASTNode* result)
{
LexerCarriage tmpCarriage = *carriage;
if (tmpCarriage.topToken.type == TOK_IDENTIFIER)
{
Token identifier = tmpCarriage.topToken;
parseNextToken(&tmpCarriage);
if (tmpCarriage.topToken.type == TOK_OPEN_BRACKET)
{
parseNextToken(&tmpCarriage);
result->nodeType = AST_FUNCTION_CALL;
result->functionCall.lineNumber = carriage->currentLineNumber;
result->functionCall.identifier = identifier.identifierValue;
result->functionCall.arguments = { };
if (tmpCarriage.topToken.type != TOK_CLOSE_BRACKET)
{
ASTNode argument;
do {
if (parseExpression(stack, &tmpCarriage, errors, &argument))
{
*pushElement(&result->functionCall.arguments, stack) = argument;
if (tmpCarriage.topToken.type == TOK_COMMA)
parseNextToken(&tmpCarriage);
else
break;
}
else
{
pushBack(errors, SyntaxError{ SET_EXPRESSION_EXPECTED });
break;
}
} while (true);
}
expectAndEat(&tmpCarriage, TOK_CLOSE_BRACKET, errors);
*carriage = tmpCarriage;
return true;
}
}
return false;
}
开发者ID:DRDivider,项目名称:TWIScript,代码行数:48,代码来源:Parser.cpp
示例8: ensureKeyword
IfNode* Parser::parseIf() {
uint32_t token = _currentTokenIndex;
ensureKeyword("if");
ensureToken(tLPAREN);
AstNode* ifExpr = parseExpression();
ensureToken(tRPAREN);
BlockNode* thenBlock = parseBlock(true);
BlockNode* elseBlock = 0;
if (currentTokenValue() == "else") {
consumeToken();
elseBlock = parseBlock(true);
}
return new IfNode(token, ifExpr, thenBlock, elseBlock);
}
开发者ID:nvmd,项目名称:spbau-mathvm,代码行数:16,代码来源:parser.cpp
示例9: ParserSyntaxException
/*** Parse a return statement ***/
Return* Parser::parseReturn()
{
if(!hasTokens() || peekToken().getType() != T_RETURN)
throw ParserSyntaxException(getToken(), "Expected \"return\" command!");
Token tok = getToken();
std::auto_ptr<Return> ret(new Return());
ret->setLineNumber(tok.getLineNumber());
ret->setColumnNumber(tok.getColumnNumber());
if(!hasTokens() || peekToken().getType() == T_EOL)
return ret.release();
std::auto_ptr<Object> expr(parseExpression());
ret->setExpression(expr.release());
return ret.release();
}
开发者ID:denrusio,项目名称:vak-opensource,代码行数:17,代码来源:parser.cpp
示例10: main
int main() {
TTable mujTable;
table = &mujTable;
tableInit(table);
tableInsertFunction(table, strCreateString("fce"));
functionInsertVar(table->lastAddedFunc, strCreateString("x"));
functionInsertVar(table->lastAddedFunc, strCreateString("y"));
functionInsertVar(table->lastAddedFunc, strCreateString("z"));
printf("\nJedna funkce: \n");
tablePrintOrder(*table);
printf("\n----------------------------\n");
//tiskniPrecTab();
FILE *f = fopen("testy/test-expr2.txt","r");
setSourceFile(f);
strInit(&attr);
listInit(&table->lastAddedFunc->tmpVar);
int err = EOK;
TVar *x = NULL;
int test = 1;
token = 1;
while(token != END_OF_FILE) {
token = getNextToken(&attr);
x = NULL;
err = parseExpression(table, &x);
printf("Test %d skoncil s chybou: %d a vysledkem: %d \n", test,err, (int)x);
test++;
while (token != END_OF_FILE && token != L_SEMICOLON) {
token = getNextToken(&attr);
}
}
tiskniList(&table->lastAddedFunc->instructions);
listDataDelete(&table->lastAddedFunc->tmpVar);
listDispose(&table->lastAddedFunc->tmpVar);
fclose(f);
tableClear(table);
strFree(&attr);
return EXIT_SUCCESS;
}
开发者ID:fkolacek,项目名称:FIT-VUT,代码行数:47,代码来源:test-expression.c
示例11: Error
// <parenexpr> ::= '(' <expression> ')'
IAstExpression *Parser::parseParenExpression() {
if (_curTokenType != '(') {
return Error("Expected '('.");
}
next(); // eat '('
IAstExpression *expr = parseExpression();
if (expr == nullptr) {
return nullptr;
}
if (_curTokenType != ')') {
return Error("Expected ')'.");
}
next(); // eat ')'
return expr;
}
开发者ID:traplol,项目名称:demiurge-lang,代码行数:18,代码来源:Parser.cpp
示例12: parsePrefixUnaryExpr
// <primary> ::= <parenexpr>
// | <identifier>
// | <string>
// | <bool>
// | <number>
IAstExpression *Parser::parsePrimary() {
if (_curToken->IsUnaryOperator())
{
IAstExpression *unary = parsePrefixUnaryExpr();
if (unary != nullptr) {
return unary;
}
}
switch (_curTokenType) {
default: return nullptr;
case '(': return parseParenExpression();
case ';': next(); return parseExpression();
case tok_identifier: return parseIdentifierExpression();
case tok_string: return parseStringExpression();
case tok_bool: return parseBooleanExpression();
case tok_number: return parseNumberExpression();
}
}
开发者ID:traplol,项目名称:demiurge-lang,代码行数:23,代码来源:Parser.cpp
示例13: parseAssignment
static PSmmAstNode parseAssignment(PSmmParser parser, PSmmAstNode lval) {
PSmmToken eqToken = parser->curToken;
getNextToken(parser);
PSmmAstNode val = parseExpression(parser);
if (val == &errorNode) {
findToken(parser, ';');
return &errorNode;
}
if (val->kind == nkSmmParamDefinition) return val;
PSmmAstNode assignment = smmNewAstNode(nkSmmAssignment, parser->a);
assignment->left = lval;
assignment->right = val;
assignment->type = lval->type;
assignment->token = eqToken;
return assignment;
}
开发者ID:igor84,项目名称:summus,代码行数:18,代码来源:smmparser.c
示例14: parseIncrementDecrementStatement
Symbol parseIncrementDecrementStatement(CharacterSource* source)
{
Span span;
Symbol function;
if (Space::parseOperator(source, increment, &span))
function = Symbol(atomIncrement);
else if (Space::parseOperator(source, decrement, &span))
function = Symbol(atomDecrement);
else
return Symbol();
CharacterSource s = *source;
Symbol lValue = parseExpression(&s);
*source = s;
Span span2;
Space::assertCharacter(source, ';', &span2);
return Symbol(atomFunctionCall, function, SymbolArray(lValue),
newSpan(span + span2));
}
开发者ID:mstram,项目名称:reenigne,代码行数:18,代码来源:statement.cpp
示例15: parseVariablePrime
void Parser::parseStatementPrime(SymbolTableEntry* prevEntry){
if(isNext(tc_LBRACKET) || isNext(tc_ASSIGNOP)){
SymbolTableEntry* var = parseVariablePrime(prevEntry);
match(tc_ASSIGNOP);
if(m_parserError){
TokenCode synch[] = {tc_ID, tc_NUMBER, tc_LPAREN, tc_NOT, tc_ADDOP, tc_NONE};
recover(synch);
// if(isNext(tc_ASSIGNOP)){
// match(tc_ASSIGNOP);
// }
}
SymbolTableEntry* exp = parseExpression();
m_code->generate(cd_ASSIGN, exp, NULL, var);
}
else{
parseProcedureStatementPrime(prevEntry);
}
}
开发者ID:nicolai490,项目名称:---endur,代码行数:18,代码来源:parser.cpp
示例16: parseExpression
Ptr<AST::Declaration> Parser::parseDeclaration ()
{
AST::Declaration *declaration = nullptr;
Token declarator = m_lexer.curr();
if (!declarator.is(TT::KeywordBool) &&
!declarator.is(TT::KeywordInt) &&
!declarator.is(TT::KeywordReal))
{
return nullptr;
}
m_lexer.pop();
Token identifier = m_lexer.curr();
if (!identifier.is(TT::Identifier))
{
return nullptr;
}
m_lexer.pop();
if (!m_lexer.curr().is(TT::Assignment))
{
return nullptr;
}
m_lexer.pop();
AST::Expression *expression = parseExpression();
if (expression == nullptr)
{
return nullptr;
}
if (!m_lexer.curr().is(TT::StatementSep))
{
return nullptr;
}
m_lexer.pop();
return declaration;
}
开发者ID:declued,项目名称:upl,代码行数:44,代码来源:parser.cpp
示例17: currentToken
AstNode* Parser::parseUnary() {
if (isUnaryOp(currentToken())) {
TokenKind op = currentToken();
consumeToken();
return new UnaryOpNode(_currentTokenIndex, op, parseUnary());
} else if (currentToken() == tIDENT && lookaheadToken(1) == tLPAREN) {
AstNode* expr = parseCall();
return expr;
} else if (currentToken() == tIDENT) {
AstVar* var = _currentScope->lookupVariable(currentTokenValue());
if (var == 0) {
error("undeclared variable: %s", currentTokenValue().c_str());
}
LoadNode* result = new LoadNode(_currentTokenIndex, var);
consumeToken();
return result;
} else if (currentToken() == tDOUBLE) {
DoubleLiteralNode* result =
new DoubleLiteralNode(_currentTokenIndex,
parseDouble(currentTokenValue()));
consumeToken();
return result;
} else if (currentToken() == tINT) {
IntLiteralNode* result =
new IntLiteralNode(_currentTokenIndex,
parseInt(currentTokenValue()));
consumeToken();
return result;
} else if (currentToken() == tSTRING) {
StringLiteralNode* result =
new StringLiteralNode(_currentTokenIndex,
currentTokenValue());
consumeToken();
return result;
} else if (currentToken() == tLPAREN) {
consumeToken();
AstNode* expr = parseExpression();
ensureToken(tRPAREN);
return expr;
} else {
error("Unexpected token: %s", tokenStr(currentToken()));
return 0;
}
}
开发者ID:nvmd,项目名称:spbau-mathvm,代码行数:44,代码来源:parser.cpp
示例18: parseAssignmentStatement
Symbol parseAssignmentStatement(CharacterSource* source)
{
CharacterSource s = *source;
Symbol lValue = parseExpression(&s);
Location operatorLocation = s.location();
if (!lValue.valid())
return Symbol();
Symbol function;
Span span;
if (Space::parseCharacter(&s, '=', &span))
function = Symbol(atomAssignment);
else if (Space::parseOperator(&s, addAssignment, &span))
function = Symbol(atomAddAssignment);
else if (Space::parseOperator(&s, subtractAssignment, &span))
function = Symbol(atomSubtractAssignment);
else if (Space::parseOperator(&s, multiplyAssignment, &span))
function = Symbol(atomMultiplyAssignment);
else if (Space::parseOperator(&s, divideAssignment, &span))
function = Symbol(atomDivideAssignment);
else if (Space::parseOperator(&s, moduloAssignment, &span))
function = Symbol(atomModuloAssignment);
else if (Space::parseOperator(&s, shiftLeftAssignment, &span))
function = Symbol(atomShiftLeftAssignment);
else if (Space::parseOperator(&s, shiftRightAssignment, &span))
function = Symbol(atomShiftRightAssignment);
else if (Space::parseOperator(&s, bitwiseAndAssignment, &span))
function = Symbol(atomBitwiseAndAssignment);
else if (Space::parseOperator(&s, bitwiseOrAssignment, &span))
function = Symbol(atomBitwiseOrAssignment);
else if (Space::parseOperator(&s, bitwiseXorAssignment, &span))
function = Symbol(atomBitwiseXorAssignment);
else if (Space::parseOperator(&s, powerAssignment, &span))
function = Symbol(atomPowerAssignment);
if (!function.valid())
return Symbol();
*source = s;
Symbol e = parseExpressionOrFail(source);
Space::assertCharacter(source, ';', &span);
return Symbol(atomFunctionCall, function, SymbolArray(Symbol(atomAddressOf, lValue), e),
new ExpressionCache(spanOf(lValue) + span));
}
开发者ID:mstram,项目名称:reenigne,代码行数:43,代码来源:statement.cpp
示例19: getNextToken
ExprAST *Parser::parseString (const std::string &f)
{
formula = parseBuffer = f;
getNextToken ();
ExprAST *result = parseExpression ();
// If there's any junk left over after an otherwise
// successful parse, there's an error
if (result && (currentToken != TOKEN_END || parseBuffer != ""))
{
error ("Parsed a complete expression, but content still remains in the formula!");
delete result;
return NULL;
}
return result;
}
开发者ID:cpence,项目名称:aformula,代码行数:19,代码来源:parser.cpp
示例20: Field
/**
* Compiles a field declaration
*/
int CodeParser::parseField( Scope* scope, const char* name, TypeReference* type, TokenStack* stack ) {
int errorCode = 0;
Token *t1, *t2;
const char* data;
// create the field, and attach it to the class
Field* field = new Field( name, type, this->modifiers );
printf( "field '%s' type='%s' modifiers = %s\n", name, type->getName(), toBinary( this->modifiers ) );
// reset the modifier for the current scope
this->modifiers = 0;
// is there also an assignment?
if( stack->hasNext() && !strcmp( stack->peek()->getText(), "=" ) ) {
// capture the
t1 = stack->next();
// there must be another token
if( !( t2 = stack->next() ) ) {
SYNTAX_ERROR( "Unexpected end of statement", t1 );
return NULL;
}
switch( t2->getType() ) {
case tok::SQUOTE_TEXT:;
case tok::DQUOTE_TEXT:
data = t2->getText();
setupAssignment( scope, field, data );
break;
default:
parseExpression( scope, stack );
}
}
// add the field to the scope
if( !errorCode ) {
scope->addField( field );
}
// TODO there may be an expression: int x = 5 * y + 1;
return errorCode;
}
开发者ID:ldaniels528,项目名称:cortex,代码行数:46,代码来源:CodeParser.cpp
注:本文中的parseExpression函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论