Browse files

README: document optimization flags

  • Loading branch information...
knieriem committed Apr 21, 2012
1 parent 04d3210 commit 5e5923410eac1d74d1fc0d17296c2091d4681023
Showing with 38 additions and 4 deletions.
  1. +9 −4
  2. +29 −0 util.go
@@ -11,18 +11,23 @@ To download and install, run
go get
-Run `make prepare` to bootstrap the peg parser, and to create
-the leg parser and the example parsers. There should be a binary
-`peg` in *./cmd/peg* now.
+Run `make` or `make prepare` to bootstrap the peg parser,
+and to create the leg parser and the example parsers. There
+should be a binary `peg` in *./cmd/peg* now.
To delete the generated source files and binaries that are
not part of the project, run `make clean`.
The desk calculator example from [peg(1)][] can be built by
typing `go build` in directory *./cmd/legcalc*.
+The parser generators now take on option -O to turn on various
+optimizations, with a single argument consisting either of a
+number of colon-separated flags, or the string "all".
+For the possible values of these flags, see [util.go](util.go).
-### Summary of modifications:
+### Summary of other modifications:
* AddPackage, AddPeg and AddState methods have been
replaced by a new method AddDefine, which stores
29 util.go
@@ -4,6 +4,35 @@ import (
+Possible optimizations:
+ 1 Thanks to the `switch' optimization, for the
+ first item of `case' sections it is already known what the
+ first character is. Otherwise the case branch would not have
+ been entered. This patch makes use of this information and
+ avoids testing for the same conditions again.
+ l Inline leaf rules, if they contain only one element of Dot, Char,
+ Class or Predicate type, or such an element embedded in a
+ expression out of + * ? ! &.
+ (p) When doing a peek for Dot, Char, Class, and Predicate,
+ don't modify position so that it doesn't have to be restored.
+ r If possible, try to avoid saving and restoring of
+ positions. For each rule two pairs of flags will be tracked,
+ which tell whether the reading position, or action thunk
+ position might advance in case the rule matches, and in case
+ it does not.
+ s if a sequence starts with one or more `!Char'
+ (PeekNot for Character), insert a switch expression
+Flags that are shown within braces are less effective now than they used
+to be, probably because of improvements of the Go compilers.
const (
AllOptimizations = "1:l:p:r:s"

0 comments on commit 5e59234

Please sign in to comment.