简体   繁体   中英

Is there a type of parser generator that handles all deterministic context-free grammars?

I need a way of generating parsers for all deterministic context-free grammars.

I know that every deterministic context-free grammar can be parsed by some LR(k) parser. The problem is that I need to generate parsers for grammars of unknown k . So, to handle every deterministic context-free grammar, k would need to be infinite.

I also know that GLR parsers can parse all context-free grammars, deterministic or not. But I need to reject non-deterministic grammars. I'm not sure if GLR can detect that property from an input grammar.

Is there a type of parser generator that can handle all deterministic context-free grammars, while rejecting non-deterministic grammars, without needing a k input? (The only input is the grammar itself)

The problem of “given a CFG, decide whether it's LR(k) for any k” is, surprisingly, undecidable, This means that it's not possible for any parser generator to always be able to take an arbitrary grammar and determine which choice of k to use. or even if such a choice of k exists.

In practice, most grammars that we care about are fairly close to LR(1), for some definition of “fairly close,” which is why most parser generators focus on that simpler case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM