4 ms·
> Grammar composition is hard. Composing grammars may not be possible, but it's easy to define a new grammar that provides the composition of two other grammar
by thaumasiotes 5y ago
> Grammar composition is hard.
Composing grammars may not be possible, but it's easy to define a new grammar that provides the composition of two other grammars along with boilerplate that serves the purpose of determining whether you're in a "grammar A" context or a "grammar B" context. You just need tokens that aren't valid in grammar A or grammar B.
No statement in such a grammar would be valid in either subgrammar, because of the boilerplate, but they would all be trivially reducible to valid statements in the appropriate subgrammar.
- PaulHoule 5y agoIt drives people nuts but I say there are many characters in Unicode https://unicode-table.com/en/sets/quotation-marks/ https://unicode-table.com/en/sets/quotation-marks/ if you need a new kind of quote, so you could write Integer index = 77; Statement s = « SELECT COUNT(*) FROM that WHERE x = @index »; People ask me "How do you type those on the keyboard?" and I say, "I don't type them on the keyboard, I cut and paste them." I use >128 codepoints all the time and mostly I don't need to because autocomplete works with them. No reason you can't write out.println(√(41.0))
- lproven 5y agoI suggest learning to use the Compose key. For instance with no clipboard use at all, it enables «this». Compose+<+< and then to close compose+>+> Also see “curly” quotes: compose+<+" and compose+>+". This illustrates the power of composing: I had forgotten the shortcut, because I rarely use it, but I was able to guess it in 3 tries.