4 ms·
To take a stab at the second question, I think BNF that fits on one page https://docs.python.org/3.4/reference/grammar.html https://docs.python.org/3.4/referenc
by Demiurge 12y ago
To take a stab at the second question, I think BNF that fits on one page
https://docs.python.org/3.4/reference/grammar.html https://docs.python.org/3.4/reference/grammar.html
vs http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc%2fRE-for-the-Perl-language%3f http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc...
This basically means Perl is very complex and its grammar can be self contradicting, such that behavior is undefined. C++ has a similar problem to a lesser extent.
- riffraff 12y agoTo expand on the non-syntax, perl has an incredible amount of language-level features, which may appear very weird to people who have only seen it from afar. For example, perl formats[0] are language-level support for generating formatted text reports and charts, which is basically a whole sublanguage (much like perl regexen). [0] http://perldoc.perl.org/perlform.html http://perldoc.perl.org/perlform.html
- stcredzero 12y agoWhen I looked at such things last, Python had about 29 terminals & nonterminals in its grammar. Ruby had 110. (These are numbers I remember from playing with particular parser libraries, so YMMV.) By contrast, a commercial Smalltalk with some syntax extensions had 8. I have no idea about Perl, but I'd guess it's about the same as Ruby.
- dragonwriter 12y ago> To take a stab at the second question, I think BNF that fits on one page Maybe for python, but not for Ruby. Ruby is not particularly simple to parse (though it may be simpler to parse than Perl, and clearly seems to be simpler to implement -- or perhaps its just that more motivation exists to implement it.)
- Demiurge 12y agoFirst google result: http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf I think 2 pages is not bad :) The point is, Perl is just impossible to formally define, it depends on the implementation to make arbitrary choices. This means multiple implementations are much harder, if possible.
- dragonwriter 12y ago> First google result: http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf Yeah, but its not: 1) One page, or 2) Current (it claims to be for Ruby v1.4), or 3) (apparently, I can't verify this for the version of Ruby it claims to represent) Accurate [1] [1] http://stackoverflow.com/questions/663027/ruby-grammar http://stackoverflow.com/questions/663027/ruby-grammar But, yes, Ruby can be parsed independent of being execution, which makes means you can separate the work of a separate implementation into (1) building (or reusing) a parser, and (2) building a system to execute the result of the parsing. Being able to divide the work (and, as a result, to share the first part between different implementations) makes it easier to implement.
- Demiurge 12y agoI don't think it's as much about ease of implementation as it is about the finality of it and formal verification of completeness of any implementation. But of course, those are very much related :)
- dragonwriter 12y ago