Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Jun 17, 2018
1 parent 122e25b commit f54f051
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 @@ -35,6 +35,10 @@ func (g *Generator) compileStatement(is *InstructionSet, statement ast.Statement
scope.line++
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 vm/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,7 @@ func TestMultiplePrefixMethodVariableWithSigns(t *testing.T) {
-1,
},
{
"a=1;(+a+1)", // TODO: needs fix: Some panic happen token: (. Line: 0
"a=1;+a+1", // TODO: needs fix: Some panic happen token: (. Line: 0
2,
},
}
Expand Down

0 comments on commit f54f051

Please sign in to comment.