/** * Parses the expression from the given token stack */ int CodeParser::parseExpression( Scope* scope, TokenStack* stack ) { int errorCode = 0; Token* t; // gather the arguments up to the end of the statement TokenStack* substack = getStackToEndOfStatement( stack ); // get the argument list while( !errorCode && substack->hasNext() && ( t = substack->next() ) ) { printf( "CodeParser::parseExpression: '%s' [%s]\n", t->getText(), t->getTypeName() ); // handle the token by type switch( t->getType() ) { case tok::ALPHA_NUMERIC: // is the argument a field? if( scope->lookupField( t->getText() ) ) { printf( "CodeParser::parseExpression: Field - [%s]\n", t->getText() ); } // is it a method call? else if( substack->hasNext() && substack->peek()->getType() == tok::PARENTHESIS_BLOCK ) { errorCode = parseExpression_MethodCall( t->getText(), scope, substack ); } break; case tok::DECIMAL: case tok::INTEGER: break; case tok::DQUOTE_TEXT: break; case tok::SQUOTE_TEXT: break; case tok::OPERATOR: break; case tok::PARENTHESIS_BLOCK: break; default: errorCode = -1; SYNTAX_ERROR( "unexpected token", substack->last() ); } } // delete the stack delete substack; // return the error code return errorCode; }
/** * Parses method call parameters */ int CodeParser::parseMethodParameters( Scope* scope, TokenStack* stack, list<Parameter*> params ) { Token* t; // the next token must be a parenthesis block (e.g. "( .. )") if( !( t = stack->next() ) || ( t->getType() != tok::PARENTHESIS_BLOCK ) ) { SYNTAX_ERROR( "Symbol '(' expected", stack->last() ); return -1; } // get the sub-stack TokenStack* substack = ((ComplexToken*)t)->getChildren(); // gather the parameters while( ( t = substack->next() ) ) { printf( "CodeParser::parseMethodParameters token: %s\n", t->getText() ); // TODO add method parameter parsing logic here } return 0; }