www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why Dlang use parsing expression grammar (PEG) parser not BNF?

reply lili <akozhao tencent.com> writes:
Hi:
    I want implementation Lua on D, I find that a PEG parser 
https://github.com/PhilippeSigaud/Pegged
    why do not use BNF parser. Is PEG better than BNF?
Oct 31 2019
next sibling parent Dennis <dkorpel gmail.com> writes:
On Thursday, 31 October 2019 at 08:40:42 UTC, lili wrote:
 Hi:
    I want implementation Lua on D, I find that a PEG parser 
 https://github.com/PhilippeSigaud/Pegged
    why do not use BNF parser. Is PEG better than BNF?
The readme has a link to the reference article: https://bford.info/pub/lang/peg Which says in the abstract:
 The power of generative grammars to express ambiguity is 
 crucial to their original purpose of modelling natural 
 languages, but this very power makes it unnecessarily difficult 
 both to express and to parse machine-oriented languages using 
 CFGs. Parsing Expression Grammars (PEGs) provide an 
 alternative, recognition-based formal foundation for describing 
 machine-oriented syntax, which solves the ambiguity problem by 
 not introducing ambiguity in the first place.
Nov 01 2019
prev sibling parent user4567 <user4567 1234.te> writes:
On Thursday, 31 October 2019 at 08:40:42 UTC, lili wrote:
 Hi:
    I want implementation Lua on D, I find that a PEG parser 
 https://github.com/PhilippeSigaud/Pegged
    why do not use BNF parser. Is PEG better than BNF?
IIRC the PEG for D is not complete. You have an EBNF here https://libdparse.dlang.io/grammar.html, which you can use to feed a library generating the parser. Note however that the lexical part is missing (so the regex-like for numbers, literals, etc.).
Nov 01 2019