Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

a copy of _why's greg (re-entrant peg/leg, with some bug fixes)

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 samples
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Makefile
Octocat-spinner-32 README
Octocat-spinner-32 compile.c
Octocat-spinner-32 greg.c
Octocat-spinner-32 greg.g
Octocat-spinner-32 greg.h
Octocat-spinner-32 greg.use
Octocat-spinner-32 tree.c
greg is a re-entrant peg/leg, with some bug fixes.

the most comprehensive example of greg usage is in
nagaqueen, an ooc grammar, used in rock, an ooc
compiler written in ooc.

peg/leg is copyright (c) 2007 by Ian Piumarta
released under an MIT license. as is greg.

This fork of greg supports the memoization of
failed rule application attempts.  For a language
with more elaborated syntax and operators, a PEG
parser can spend exponentially long time to try
the same rule application at the same input
location.  The typical solution for this problem
is to assume that a grammar rule always returns
the same result (or fail) at the same location and
remember the value (or failure), effectively in
the 2D table of (location, rule_id) -> value.

An interesting feature that Ian's leg has is that it
defers the semantic action execution until the
system "commits" a successfull parse.  (That is
why putting printf() in a failed choice in a rule
does not show any debug log, BTW.)  Because of
this, we cannot remember the successful result; as
it is calculated later while attempting a lot of
reduandant failures.  So, instead, this fork only
remembers the fact that the rule failed; next time
it trys the same rule at the location, it
short-cuts the work and fails.
Something went wrong with that request. Please try again.