From 7dc25960b470fa34845d2c1257a9113a9133d7a4 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sun, 24 Aug 2014 11:34:45 -0700 Subject: [PATCH] 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 https://golang.org/cl/125580044. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/125620044 --- src/cmd/yacc/Makefile | 12 ------------ src/cmd/yacc/expr/README | 20 ++++++++++++++++++++ src/cmd/yacc/{ => expr}/expr.y | 5 ----- src/cmd/yacc/expr/main.go | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 src/cmd/yacc/Makefile create mode 100644 src/cmd/yacc/expr/README rename src/cmd/yacc/{ => expr}/expr.y (96%) create mode 100644 src/cmd/yacc/expr/main.go diff --git a/src/cmd/yacc/Makefile b/src/cmd/yacc/Makefile deleted file mode 100644 index f8c8169bd1..0000000000 --- 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 0000000000..302ef57a7d --- /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 similarity index 96% rename from src/cmd/yacc/expr.y rename to src/cmd/yacc/expr/expr.y index 77e9259dae..09451949ff 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 0000000000..8d5b6911f0 --- /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