1
0
mirror of https://github.com/golang/go synced 2024-10-01 11:38:34 -06:00

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
This commit is contained in:
Rob Pike 2014-08-24 11:34:45 -07:00
parent 41fc05d023
commit 7dc25960b4
4 changed files with 35 additions and 17 deletions

View File

@ -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)

20
src/cmd/yacc/expr/README Normal file
View File

@ -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.

View File

@ -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 (

15
src/cmd/yacc/expr/main.go Normal file
View File

@ -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