Re: Semicolon wrangling (was Re: [friam] Minutes)
"Jonathan S. Shapiro" <[email protected]> Sun, 21 Oct 2012 00:56:51 -0700
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <CAAP=3QNMKarjR09usxqe8iF3wcA1KY+v8u2xcdn=r6kyTUMzfQ@mail.gmail.com> |
In most languages, support for "trailing separators" (that is: terminators) tends to be very *ad hoc*. For example, a trailing ',' eventually came to be permitted in C/C++ enumerations, but not in arguments. >From a grammar perspective, support for optional trailing separators can introduce parse ambiguities that can take a fair bit of grammar complexity to work around. That seems like a high price to pay. In later versions of BitC, the issue was resolved by making many separators optional in much the way that was done in Haskell and similar languages. A stateful intermediate pass is injected between the parser and the lexer that inserts missing tokens (in our case mainly based on indentation). In the usual algorithm, most such separators end up turning into terminators (i.e. the last one is no longer optional by the time the parser is seeing the token stream). The intermediate pass is stateful mainly because it needs to keep track of various forms of brackets, and because the main grammar requires two-token lookahead to identify missing tokens in certain cases and can end up pushing a bracket back onto the input token stream. Once I had the two-token lookahead and the pushback mechanism working, the resulting grammar turned out to be surprisingly clean. People have strong views pro and con about significant white space. What I would mainly note here is that automatic terminator insertion tends to finesse the problem by (a) making the last separator *appear* optional by virtue of auto-insertion while (b) nonetheless retaining a regular and consistent grammar. I grumbled a lot about the difficulty of doing whitespace-driven insertion. To do it well does require that the underlying language honor certain bracketing properties. But if the language grammar is designed with auto-insertion in mind, the results can be *very* pleasant. Jonathan _______________________________________________ e-lang mailing list [email protected] http://www.eros-os.org/mailman/listinfo/e-lang