goyacc

command module
v0.0.0-...-3db37af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2014 License: BSD-3-Clause Imports: 18 Imported by: 0

README

goyacc

Goyacc is a version of yacc generating Go programs.

Installation

$ go get github.com/cznic/goyacc

Documentation: godoc.org/github.com/cznic/goyacc

Documentation

Overview

Goyacc is a version of yacc generating Go parsers.

Usage:

goyacc [options] [input]

options and (defaults)
	-c                  report state closures (false)
	-dlval              debug value when runtime yyDebug >= 3 ("lval")
	-dlvalf             debug format of -dlval ("%+v")
	-ex                 explain how were conflicts resolved (false)
	-l                  disable line directives, for compatibility only - ignored (false)
	-la                 report all lookahead sets (false)
	-o outputFile       parser output ("y.go")
	-p prefix           name prefix to use in generated code ("yy")
	-v reportFile       create grammar report ("y.output")
	-xe examplesFile    generate error messages by examples ("")

If no non flag arguments are given, goyacc reads standard input.

The generated parser is reentrant and mostly backwards compatible with parsers generated by go tool yacc[0]. yyParse expects to be given an argument that conforms to the following interface:

type yyLexer interface {
	Lex(lval *yySymType) int
	Error(e string)
}

Lex should return the token identifier, and place other token information in lval (which replaces the usual yylval). Error is equivalent to yyerror in the original yacc.

Code inside the parser may refer to the variable yylex, which holds the yyLexer passed to Parse.

Multiple grammars compiled into a single program should be placed in distinct packages. If that is impossible, the "-p prefix" flag to yacc sets the prefix, by default yy, that begins the names of symbols, including types, the parser, and the lexer, generated and referenced by yacc's generated code. Setting it to distinct values allows multiple grammars to be placed in a single package.

Differences wrt go tool yacc

- goyacc implements ideas from "Generating LR Syntax Error Messages from Examples"[1]. Use the -xe flag to pass a name of the example file. For more details about the example format please see [2].

- The grammar report includes example token sequences leading to the particular state. Can help understanding conflicts.

- Minor changes in parser debug output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL