Added basics for lexing index expressions

This commit is contained in:
Deukhoofd 2019-06-05 21:01:59 +02:00
parent 7f79c4d8bb
commit b275e1fbd6
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 21 additions and 3 deletions

View File

@ -65,8 +65,14 @@ IToken* Lexer::LexNext(char c){
return new SimpleToken(TokenKind::OpenParenthesis, this -> _position - 1, 1);
case ')':
return new SimpleToken(TokenKind::CloseParenthesis, this -> _position - 1, 1);
case '[':
return new SimpleToken(TokenKind::OpenSquareBracket, this -> _position - 1, 1);
case ']':
return new SimpleToken(TokenKind::CloseSquareBracket, this -> _position - 1, 1);
case ',':
return new SimpleToken(TokenKind::CommaToken, this -> _position - 1, 1);
case '.':
return new SimpleToken(TokenKind::PeriodToken, this -> _position - 1, 1);
case '=':
if (Lexer::Peek() == '='){
Lexer::Next();

View File

@ -139,9 +139,17 @@ ParsedStatement *Parser::ParseFunctionDeclaration(IToken *current) {
ParsedExpression* Parser::ParseExpression(IToken* current){
auto expression = this -> ParseBinaryExpression(current, OperatorPrecedence::No);
while (this -> Peek() -> GetKind() == TokenKind::OpenParenthesis){
expression = this->ParseFunctionCallExpression(expression);
//TODO: Function Evaluation
auto peekKind = this->Peek()->GetKind();
while (peekKind == TokenKind::OpenParenthesis ||
peekKind == TokenKind::OpenSquareBracket ||
peekKind == TokenKind::PeriodToken){
if (peekKind == TokenKind::OpenParenthesis){
expression = this->ParseFunctionCallExpression(expression);
} else if (peekKind == TokenKind::OpenSquareBracket){
//TODO: index expression
} else {
//TODO: index period expression
}
}
return expression;
}

View File

@ -15,6 +15,10 @@ enum class TokenKind{
InequalityToken,
OpenParenthesis,
CloseParenthesis,
OpenSquareBracket,
CloseSquareBracket,
PeriodToken,
CommaToken,
Identifier,