git @ Cat's Eye Technologies Parc / 7dce8df
Add documentation for `ParcAssertDemo.hs`. Chris Pressey 8 months ago
1 changed file(s) with 24 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7272 combinator can be used to apply arithmetic operators like `+` and `*`
7373 when parsing an arithmetic expression.
7474
75 ### `ParcAssert.hs`
76
77 With what we have so far, if we merely accumulate state as we parse,
78 we can parse only context-free languages.
79
80 But if we enable the parser to succeed or fail based on some predicate
81 applied to the parsing state, we can parse context-sensitive languages.
82
83 (Actually, if we don't restrict ourselves to sufficiently simple
84 predicates, we can parse languages quite beyond the context-sensitive
85 range. For example, we could use a predicate which checks if the
86 string passed to it is a valid sentence in Presburger arithmetic.
87 Formulating a set of parser combinators which actually (and provably)
88 is limited to parsing context-sensitive languages seems like a hard
89 (maybe open) problem.)
90
91 [`ParcAssertDemo.hs`](ParcAssertDemo.hs) uses `ParcSt2St` and adds a
92 combinator called `assert` that takes such a predicate on the parsing
93 state, and produces a parser which succeeds only when that predicate
94 is true on the current parsing state, failing otherwise.
95
96 The demo module gives an example of a parser for a classic
97 context-free language: strings of the form `a`^_n_ `b`^_n_ `c`^_n_.
98
7599 ### ... and more?
76100
77101 With luck, there will be further experiments added here over time.