Skip to content

Commit

Permalink
Fix method call, index and prefix's precedence.
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored and hachi8833 committed Aug 19, 2018
1 parent 8498074 commit 0bf6f88
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions compiler/bytecode/statement_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (g *Generator) compileStatements(stmts []ast.Statement, scope *scope, table
func (g *Generator) compileStatement(is *InstructionSet, statement ast.Statement, scope *scope, table *localTable) {
switch stmt := statement.(type) {
case *ast.ExpressionStatement:
if stmt.Expression == nil {
return
}

if !g.REPL && stmt.Expression.IsStmt() {
g.compileExpression(is, stmt.Expression, scope, table)
is.define(Pop, statement.Line())
Expand Down
8 changes: 4 additions & 4 deletions compiler/parser/expression_parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ func (p *Parser) parseExpression(precedence int) ast.Expression {

leftExp := parseFn()

if leftExp == nil {
return nil
}

/*
Precedence example:
Expand Down Expand Up @@ -194,10 +198,6 @@ func (p *Parser) parseExpression(precedence int) ast.Expression {
leftExp = infixFn(leftExp)
}

if p.peekTokenIs(token.Semicolon) {
p.nextToken()
}

return leftExp
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (p *Parser) ParseProgram() (program *ast.Program, err *errors.Error) {
if recover() != nil {
err = p.error
if err == nil {
msg := fmt.Sprintf("Some panic happen token: %s. Line: %d", p.curToken.Literal, p.curToken.Line)
msg := fmt.Sprintf("Some panic happen token: %s Line: %d", p.curToken.Literal, p.curToken.Line)
err = errors.InitError(msg, errors.SyntaxError)
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/parser/precedence/precedence.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const (
Sum
Product
BangPrefix
Index
Call
MinusPrefix
Index
)

// LookupTable maps token to its corresponding precedence
Expand Down

0 comments on commit 0bf6f88

Please sign in to comment.