Skip to content

Commit

Permalink
pseudo: execInputStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Feb 14, 2025
1 parent 594a398 commit 7214b2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion demo/gop-parser/pseudo/gauss.pseudo
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
CONSTANT n <- 100
DECLARE n : INTEGER
DECLARE i : INTEGER
DECLARE sum : INTEGER
OUTPUT "please input n:"
INPUT n
i <- 1
sum <- 0
WHILE i <= n DO
Expand Down
10 changes: 9 additions & 1 deletion demo/gop-parser/pseudo/state.gox
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import (
"fmt"
"gop/ast"
"gop/token"
"math"
Expand Down Expand Up @@ -78,7 +79,14 @@ func execOutputStmt(stmt *OutputStmt) {
}

func execInputStmt(stmt *InputStmt) {
panic("todo")
name := stmt.Name
oldv, ok := vars[name]
if !ok {
panic("undefined variable `${name}`")
}
v := reflect.new(reflect.typeOf(oldv))
fmt.scanln(v.Interface())!
vars[name] = v.elem.Interface()
}

func execIfStmt(stmt *IfStmt) {
Expand Down

0 comments on commit 7214b2c

Please sign in to comment.