Compiler in Rust (lexer, parser, checker, C codegen), maps, chars, dino fmt, dino lsp (diagnostics, formatting, outline, definition, hover, completion, signature help), docs, examples, VS Code/Vim files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
44 lines
1.0 KiB
Plaintext
44 lines
1.0 KiB
Plaintext
import parser
|
|
import eval
|
|
import os
|
|
|
|
// Evaluates one line and prints the answer or the problem.
|
|
func run_line(scope: shared eval.Scope, line: string) {
|
|
var text = line.trim()
|
|
if text == "" { return }
|
|
var tree, err = parser.parse(text)
|
|
if err != nil {
|
|
print(" error:", err)
|
|
return
|
|
}
|
|
var value, err2 = scope.eval(tree)
|
|
if err2 != nil {
|
|
print(" error:", err2)
|
|
return
|
|
}
|
|
print(" =", value)
|
|
}
|
|
|
|
// Reads lines from the file named on the command line, or from the keyboard.
|
|
func main() {
|
|
var scope = shared eval.new_scope()
|
|
var args = os.args
|
|
if args.len() > 1 {
|
|
var text, err = os.read_file(args[1])
|
|
if err != nil {
|
|
print("cannot read", args[1], err)
|
|
os.exit(1)
|
|
}
|
|
for line in text.lines() {
|
|
print(line)
|
|
run_line(scope, line)
|
|
}
|
|
return
|
|
}
|
|
for {
|
|
var line = os.read_line()
|
|
if line == nil { break }
|
|
run_line(scope, line)
|
|
}
|
|
}
|