aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: f3083782ea3cfaf8d04c36ff77ab4094d3c014d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package main

//go:generate -command yacc goyacc
//go:generate yacc -o calc.go calc.y

import (
	"bufio"
	"fmt"
	"os"
)

const promt = "\t"

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	fmt.Print(promt)
	for scanner.Scan() {
		line := scanner.Text()
		result, ok, err := Parse(line)
		if err != nil {
			fmt.Printf("error: %v\n\n", err)
		} else if ok {
			fmt.Printf("%v\n\n", result)
		}
		fmt.Print(promt)
	}
}