source: project/release/4/genturfahi/trunk/chicken-csi.scm @ 22502

Last change on this file since 22502 was 22502, checked in by Alan Post, 10 years ago

genturfa'i: refactor behavior of grouping "()" operator.

Structurally, this parser generator has the following components:

javni: the individual elements that make up a production, like

'*', '?', &c.

valsi: the tokens that are constructed when a rule matches and

placed into the parse tree.

compiler: the translation from PEG to scm, which manages the

interface between all of the javni and they way their
created valsi are constructed into a parse tree.

This commit formalizes the interation between rule creation and
token creation. This was done so that the grouping operator doesn't
affect the resulting parse tree. The following rules (and those
like them) are the same:

a <- a b c
a <- (a b) c
a <- (a (b c)

When a grouping operator is encountered, the result rule is spliced
into the sequence it surrounds. Formalizing this behavior required
handling a lot of edge cases, so this commit is fairly large.

Noteworthy changes:

  • group splicing is handled by the porjahe and porsumti flags, which describe whether to generate a list to splice or whether to accept a list to splice from a contained rule.
  • I'm now using the matchable egg when generating valsi rules. These rules are generated based on a combination of several flags, and the matchable egg allows the structure of these choices to be seen.
  • the je production in the PEG grammar acts as a glue interface, generating code based on a fairly broad look at incoming rules. I'm also using the matchable egg here.

This code is smaller (I think!) and not as complex. In particular,
there are fewer choice points in most of the code, the flags
generating the correct behavior which is then assumed by the rest of
the system, with almost all of the glue layer now in the compiler.

I like the interface between these systems much better now, and I
believe the runtime performance of the parser is improved by
removing the checks I had added for various states.

File size: 1.8 KB
Line 
1;;;;
2;;;; genturfahi - lo la .ckim. ke pe'a jajgau ratcu ke'e genturfa'i
3;;;;            `-> A Scheme packrat parser.
4;;;;
5;;;; Copyright (c) 2010 ".alyn.post." <alyn.post@lodockikumazvati.org>
6;;;;
7;;;; Permission to use, copy, modify, and/or distribute this software for any
8;;;; purpose with or without fee is hereby granted, provided that the above
9;;;; copyright notice and this permission notice appear in all copies.
10;;;;
11;;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12;;;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13;;;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14;;;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15;;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16;;;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17;;;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18;;;;
19
20(use srfi-1)
21(use srfi-9)
22(use srfi-13)    ; String Libraries
23(use srfi-14)    ; Character Classes
24(use srfi-28)    ; Basic Format Strings
25(use srfi-37)    ; args-fold
26(use srfi-39)    ; parameter objects
27(use srfi-69)    ; hash tables
28(use extras)     ; format, pretty-print
29(use matchable)
30(use sandbox)    ; safe-eval
31
32(include "chicken-platform.scm")
33
34; genturfahi (lib)
35;
36(include "lerfu-porsi.scm")
37(include "javni-valsi.scm")
38(include "secuxna.scm")
39(include "nunjavni.scm")
40(include "morji.scm")
41(include "nunvalsi.scm")
42(include "cfisisku.scm")
43(include "junla.scm")
44(include "genturfahi.scm")
45(include "version.scm")
46
47; genturfahi-peg
48;
49(include "eval.scm")
50(include "samselpla.scm")
51(include "bootstrap.scm")
52(include "peg.scm")
53
54; genturfahi (bin)
55;
56(include "license.scm")
57(include "main-srfi-37.scm")
58
59(main)
60(exit (secuxna-exit-status))
Note: See TracBrowser for help on using the repository browser.