Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2775
| From | Jan Ziak <0xe2.0x9a.0x9b@gmail.com> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? |
| Date | 2021-12-29 16:05 -0800 |
| Organization | Compilers Central |
| Message-ID | <21-12-020@comp.compilers> (permalink) |
| References | <21-12-003@comp.compilers> <21-12-017@comp.compilers> |
On Wednesday, December 29, 2021 at 11:28:34 PM UTC+1, Kaz Kylheku wrote: > On 2021-12-16, Roger L Costello wrote: > > Question: Opine about why languages are usually defined and implemented with > > ambiguous grammars. > But they aren't. > > Languages are processed as a stream of characters or tokens, with hidden > rules about how those relate together and the meaning that emerges. > All of the rules are hidden, including the entire grammar. > > If you're only aware of some of the hidden rules, but not others, then > you see ambiguity. > > But if you're only aware of some of the hidden rules, but not others, > then you are not working with the correct language. > > For instance, I don't know of any mainstream language in which if/else > is actually ambiguous. They have a hidden rule like that the else goes > with the closest preceding if statement. When designing a grammar and implementing a parser: the grammar can either be unambiguous by design or unambiguous by accident. The viewpoint that "there isn't any mainstream language in which if/else is actually ambiguous" is actually the latter option: unambiguous by accident. A primary reason why grammars in many mainstream languages (that don't have a parser generated straight from a verified grammar) are unambiguous isn't intentional design, but rather it is a consequence of the fact that those parsers are directly implemented in a language that is executing statements/expressions/instructions without verifying consequences of the executions. Some examples of languages with such execution properties: assembly language (such as: i386, ARM), C, Haskell. Contrary to the accidental approach, a parser generator by design cares about consequences and it is verifying that the specification actually is unambiguous despite the fact that in the end the parser gets compiled down into machine instructions. Verification means to search the whole search space (or at least a reasonably large subspace of it) - but asm/C/Haskell will run a search only if it is explicitly (step by step) forced by the programmer to perform a search. -atom
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Kaz Kylheku <480-992-1380@kylheku.com> - 2021-12-29 18:48 +0000
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Jan Ziak <0xe2.0x9a.0x9b@gmail.com> - 2021-12-29 16:05 -0800
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Kaz Kylheku <480-992-1380@kylheku.com> - 2021-12-30 18:00 +0000
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Kaz Kylheku <480-992-1380@kylheku.com> - 2021-12-30 20:08 +0000
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? gah4 <gah4@u.washington.edu> - 2021-12-29 18:41 -0800
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Kaz Kylheku <480-992-1380@kylheku.com> - 2021-12-30 18:14 +0000
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? Jan Ziak <0xe2.0x9a.0x9b@gmail.com> - 2021-12-30 13:47 -0800
Re: What does = mean, was Why are ambiguous grammars usually a bad idea? Jan Ziak <0xe2.0x9a.0x9b@gmail.com> - 2021-12-30 17:10 -0800
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? mac <acolvin@efunct.com> - 2022-01-03 19:51 +0000
Re: for or against equality, was Why are ambiguous grammars usually a bad idea? gah4 <gah4@u.washington.edu> - 2022-01-03 21:07 -0800
Re: for or against equality, was Why are ambiguous grammars usually a bad idea? Thomas Koenig <tkoenig@netcologne.de> - 2022-01-04 19:23 +0000
Re: for or against equality, was Why are ambiguous grammars usually a bad idea? gah4 <gah4@u.washington.edu> - 2022-01-04 13:26 -0800
Re: Why are ambiguous grammars usually a bad idea? Why are languages usually defined and implemented with ambiguous grammars? gah4 <gah4@u.washington.edu> - 2021-12-30 13:40 -0800
Re: why do people choose a language, was Why are ambiguous grammars usually a bad idea? Jan Ziak <0xe2.0x9a.0x9b@gmail.com> - 2021-12-30 20:19 -0800
csiph-web