summaryrefslogtreecommitdiff
path: root/src/cmd/yacc
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-08-24 11:34:45 -0700
committerRob Pike <r@golang.org>2014-08-24 11:34:45 -0700
commitd76fac35e20fc4b8071dbd392750b061a5735fa7 (patch)
tree980957ba39da4f9ea557fe3f6dd0422b13b886d9 /src/cmd/yacc
parent05e94979c82d32da7be1d8baa09b424087acfe4d (diff)
downloadgo-d76fac35e20fc4b8071dbd392750b061a5735fa7.tar.gz
cmd/yacc: remove Makefile and build expr using go generate
It now serves as an example for go generate as well as for yacc. NOTE: Depends on go generate, which is not yet checked in. This is a proof of concept of the approach. That is http://codereview.appspot.com/125580044. LGTM=rsc R=rsc CC=golang-codereviews https://codereview.appspot.com/125620044
Diffstat (limited to 'src/cmd/yacc')
-rw-r--r--src/cmd/yacc/Makefile12
-rw-r--r--src/cmd/yacc/expr/README20
-rw-r--r--src/cmd/yacc/expr/expr.y (renamed from src/cmd/yacc/expr.y)5
-rw-r--r--src/cmd/yacc/expr/main.go15
4 files changed, 35 insertions, 17 deletions
diff --git a/src/cmd/yacc/Makefile b/src/cmd/yacc/Makefile
deleted file mode 100644
index f8c8169bd..000000000
--- a/src/cmd/yacc/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# Copyright 2009 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-TARG=expr$(shell go env GOEXE)
-
-$(TARG): yacc.go expr.y
- go run yacc.go -p expr expr.y
- go build -o $(TARG) y.go
-
-clean:
- rm -f y.go y.output $(TARG)
diff --git a/src/cmd/yacc/expr/README b/src/cmd/yacc/expr/README
new file mode 100644
index 000000000..302ef57a7
--- /dev/null
+++ b/src/cmd/yacc/expr/README
@@ -0,0 +1,20 @@
+This directory contains a simple program demonstrating how to use
+the Go version of yacc.
+
+To build it:
+
+ $ go generate
+ $ go build
+
+or
+
+ $ go generate
+ $ go run expr.go
+
+The file main.go contains the "go generate" command to run yacc to
+create expr.go from expr.y. It also has the package doc comment,
+as godoc will not scan the .y file.
+
+The actual implementation is in expr.y.
+
+The program is not installed in the binary distributions of Go.
diff --git a/src/cmd/yacc/expr.y b/src/cmd/yacc/expr/expr.y
index 77e9259da..09451949f 100644
--- a/src/cmd/yacc/expr.y
+++ b/src/cmd/yacc/expr/expr.y
@@ -11,11 +11,6 @@
%{
-// This tag will be copied to the generated file to prevent that file
-// confusing a future build.
-
-// +build ignore
-
package main
import (
diff --git a/src/cmd/yacc/expr/main.go b/src/cmd/yacc/expr/main.go
new file mode 100644
index 000000000..8d5b6911f
--- /dev/null
+++ b/src/cmd/yacc/expr/main.go
@@ -0,0 +1,15 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file holds the go generate command to run yacc on the grammar in expr.y.
+// To build expr:
+// % go generate
+// % go build
+
+//go:generate -command yacc go tool yacc
+//go:generate yacc -o expr.go -p "expr" expr.y
+
+// Expr is a simple expression evaluator that serves as a working example of
+// how to use Go's yacc implemenation.
+package main