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
|
|
|
|
|
|
|
interp.Close()
|
|
|
|
f.Close()
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
oops:
|
|
|
|
if interp != nil {
|
|
|
|
interp.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
if f != nil {
|
|
|
|
f.Close()
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|