reassign values
This commit is contained in:
@@ -127,6 +127,11 @@ func (p *Parser) noPrefixParseFnError(t token.TokenType) {
|
||||
p.errors = append(p.errors, msg)
|
||||
}
|
||||
|
||||
func (p *Parser) noInfixParseFnError(t token.TokenType) {
|
||||
msg := fmt.Sprintf("no infix parse function for %s found", t)
|
||||
p.errors = append(p.errors, msg)
|
||||
}
|
||||
|
||||
func (p *Parser) ParseProgram() *ast.Program {
|
||||
program := &ast.Program{}
|
||||
program.Statements = []ast.Statement{}
|
||||
@@ -143,6 +148,10 @@ func (p *Parser) ParseProgram() *ast.Program {
|
||||
}
|
||||
|
||||
func (p *Parser) parseStatement() ast.Statement {
|
||||
if p.peekToken.Type == token.ASSIGN {
|
||||
return p.parseAssignmentStatement()
|
||||
}
|
||||
|
||||
switch p.curToken.Type {
|
||||
case token.LET:
|
||||
return p.parseLetStatement()
|
||||
@@ -218,7 +227,8 @@ func (p *Parser) parseExpression(precedence int) ast.Expression {
|
||||
for !p.peekTokenIs(token.SEMICOLON) && precedence < p.peekPrecedence() {
|
||||
infix := p.infixParseFns[p.peekToken.Type]
|
||||
if infix == nil {
|
||||
return leftExp
|
||||
p.noInfixParseFnError(p.peekToken.Type)
|
||||
//return leftExp
|
||||
}
|
||||
|
||||
p.nextToken()
|
||||
@@ -516,3 +526,19 @@ func (p *Parser) parseWhileExpression() ast.Expression {
|
||||
|
||||
return expression
|
||||
}
|
||||
|
||||
func (p *Parser) parseAssignmentStatement() ast.Statement {
|
||||
stmt := &ast.AssignmentStatement{Token: p.peekToken}
|
||||
stmt.Name = &ast.Identifier{Token: p.curToken, Value: p.curToken.Literal}
|
||||
|
||||
p.nextToken()
|
||||
p.nextToken()
|
||||
|
||||
stmt.Value = p.parseExpression(LOWEST)
|
||||
|
||||
if p.peekTokenIs(token.SEMICOLON) {
|
||||
p.nextToken()
|
||||
}
|
||||
|
||||
return stmt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user