-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frontend]: assigning values to variable (#35)
* feat: variable assignment * fix: assigning undeclared variable is not returning exception * chore: minor change * test: add new test cases to interpreter for variable assignment * chore: minor cleaning * refactor: rename `smt` into `stmt` * test: more test cases * fix: weak condition in test case * test: more check in interpreter test cases
- Loading branch information
1 parent
164eaae
commit 5969220
Showing
10 changed files
with
236 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ast | ||
|
||
import "glox/token" | ||
|
||
type StmtVisitor interface { | ||
VisitPrintStmt(*PrintStmt) any | ||
VisitExprStmt(*ExpressionStmt) any | ||
VisitLetStmt(*LetStmt) any | ||
} | ||
|
||
type Statement interface { | ||
Accept(StmtVisitor) any | ||
} | ||
|
||
type PrintStmt struct { | ||
Exp Expression | ||
} | ||
|
||
type LetStmt struct { | ||
Name token.Token | ||
Value Expression | ||
} | ||
|
||
func NewLetStmt(name token.Token, value Expression) *LetStmt { | ||
return &LetStmt{Name: name, Value: value} | ||
} | ||
|
||
func (stmt *LetStmt) Accept(v StmtVisitor) any { | ||
return v.VisitLetStmt(stmt) | ||
} | ||
|
||
func NewPrintStmt(exp Expression) *PrintStmt { | ||
return &PrintStmt{Exp: exp} | ||
} | ||
|
||
func (stmt *PrintStmt) Accept(v StmtVisitor) any { | ||
return v.VisitPrintStmt(stmt) | ||
} | ||
|
||
type ExpressionStmt struct { | ||
Exp Expression | ||
} | ||
|
||
func NewExprStmt(exp Expression) *ExpressionStmt { | ||
return &ExpressionStmt{Exp: exp} | ||
} | ||
|
||
func (stmt *ExpressionStmt) Accept(v StmtVisitor) any { | ||
return v.VisitExprStmt(stmt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.