2023-07-21 09:32:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
pcl "pcl/interp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var (
|
|
|
|
interp *pcl.Interp
|
|
|
|
f *os.File
|
|
|
|
r *bufio.Reader
|
|
|
|
c rune
|
|
|
|
node *pcl.Cnode_t
|
2023-08-04 09:41:30 +00:00
|
|
|
v pcl.Value_t
|
|
|
|
|
|
|
|
err error
|
2023-07-21 09:32:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if len(os.Args) != 2 {
|
|
|
|
fmt.Printf("Usage: %s filename\n", path.Base(os.Args[0]))
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
interp, err = pcl.NewInterp(1000, true)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err = os.Open(os.Args[1])
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
interp.BeginFeed()
|
|
|
|
|
|
|
|
r = bufio.NewReader(f)
|
|
|
|
for {
|
|
|
|
c, _, err = r.ReadRune()
|
|
|
|
if err != nil {
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
fmt.Printf("Error in ReadRune - %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
err = interp.FeedRune(c)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error in FeedRune - %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node, err = interp.EndFeed()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error in EndFeed %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
interp.Dump(node)
|
|
|
|
fmt.Printf("------------- Executing ----------------\n")
|
|
|
|
v, err = interp.Execute(node)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Error in Execute - %s\n", err.Error())
|
|
|
|
goto oops
|
|
|
|
}
|
|
|
|
|
|
|
|
if v == nil {
|
|
|
|
panic("return value mut not be nil")
|
|
|
|
}
|
2023-08-04 09:41:30 +00:00
|
|
|
fmt.Printf("RETURN VALUE = [%s]\n", *v.(*string))
|
2023-07-21 09:32:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
err = interp.FeedRunes([]rune(`
|
|
|
|
proc inc{x} {
|
|
|
|
puts {10 20}
|
|
|
|
return [expr $x + 1]
|
|
|
|
}
|
|
|
|
\{abc 11 2\ \1011 \ 2\x65 \uBc29\uaD6cdefg\uZZ\xZZ\U0000BC29\UAD6cZZ \
|
|
|
|
[donkey 1 [expr [expr 2 + 3] + 3] ]
|
|
|
|
hello { world { }man}
|
|
|
|
"command { l a n g }"
|
|
|
|
set a [puts "1111" "22 22" "3333 [expr "123" + 2] 4444"]
|
|
|
|
abc [expr [expr 2 + "4[expr 2 * 6]"] + 9]
|
|
|
|
puts $a ${ kkk qqq }
|
|
|
|
puts "\x65\ubc29\n"
|
|
|
|
{}`))
|
|
|
|
*/
|
|
|
|
//err = interp.FeedRunes([]rune(`hello [world [1 9] 2]
|
|
|
|
//`))
|
|
|
|
/*
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR %s\n", err)
|
|
|
|
} else {
|
|
|
|
err = interp.EndFeed()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR %s\n", err)
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
interp.Close()
|
|
|
|
f.Close()
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
oops:
|
|
|
|
if interp != nil {
|
|
|
|
interp.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
if f != nil {
|
|
|
|
f.Close()
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|