forked from ooc-lang/greg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
README
34 lines (30 loc) · 1.35 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
greg is a re-entrant peg/leg, with some bug fixes.
<http://piumarta.com/software/peg/>
the most comprehensive example of greg usage is in
nagaqueen, an ooc grammar, used in rock, an ooc
compiler written in ooc.
<http://github.com/nddrylliog/nagaqueen>
<http://github.com/nddrylliog/rock>
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.