in reply to Re^2: Perl not BNF-able??
in thread Perl not BNF-able??

So, where's the requirement that both the proto and the definition have the same signature? It's trivial to write BNF for a proto, it's trivial BNF for the definition (given the BNF for the block). It's impossible to use BNF for the requirement that the signatures (that is, name and prototype) are the same.

Your BNF is ok if you're allowed to write:

sub hello($); sub hello() {print("Hello, world");}
But you aren't. The signatures should be the same - and that's unexpressable with BNF.

Replies are listed 'Best First'.
Re^4: Perl not BNF-able??
by ikegami (Patriarch) on Jul 05, 2005 at 15:02 UTC

    BNF dictates syntax, and the above snippet is syntactically correct. perl -c agrees by saying "syntax OK".

    The following is syntactically correct C++:

    Type1 p; Type2 q; p = q;

    Are Type1* and Type2* assignment compatible? It doesn't matter as far as BNF is concerned because it only specifies the syntax.

    The error in your Perl snippet and the error in the above C++ snippet (if any) are semantic errors. Semantic analysis is usually done independant of parsing. Semantic analysis checks things such as types, and whether forward declerations have been resolved. These are things that don't affect the compiler's understanding of the code, but affect whether the code is consistent (valid) when looking at the bigger picture. BNF does not have a role in semantic analysis.

    BNF is therefore sufficient to handle the Perl in your post.