github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/yacc/doc.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 7 Yacc is a version of yacc for Go. 8 It is written in Go and generates parsers written in Go. 9 10 Usage: 11 12 go tool yacc args... 13 14 It is largely transliterated from the Inferno version written in Limbo 15 which in turn was largely transliterated from the Plan 9 version 16 written in C and documented at 17 18 http://plan9.bell-labs.com/magic/man2html/1/yacc 19 20 Adepts of the original yacc will have no trouble adapting to this 21 form of the tool. 22 23 The file units.y in this directory is a yacc grammar for a version of 24 the Unix tool units, also written in Go and largely transliterated 25 from the Plan 9 C version. It needs the flag "-p units_" (see 26 below). 27 28 The generated parser is reentrant. Parse expects to be given an 29 argument that conforms to the following interface: 30 31 type yyLexer interface { 32 Lex(lval *yySymType) int 33 Error(e string) 34 } 35 36 Lex should return the token identifier, and place other token 37 information in lval (which replaces the usual yylval). 38 Error is equivalent to yyerror in the original yacc. 39 40 Code inside the parser may refer to the variable yylex, 41 which holds the yyLexer passed to Parse. 42 43 Multiple grammars compiled into a single program should be placed in 44 distinct packages. If that is impossible, the "-p prefix" flag to 45 yacc sets the prefix, by default yy, that begins the names of 46 symbols, including types, the parser, and the lexer, generated and 47 referenced by yacc's generated code. Setting it to distinct values 48 allows multiple grammars to be placed in a single package. 49 50 */ 51 package main