Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Perl not BNF-able??

by ikegami (Patriarch)
on Jul 04, 2005 at 20:12 UTC ( [id://472294]=note: print w/replies, xml ) Need Help??


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

Why do you say that snippet is not BNF-able? Parts of Perl cannot be expressed by BNF, but your snippet is not one of them as far as I can tell.

statement : sub_proto statement : sub_def term : anon_sub sub_proto : ws? "sub" ws? sym_name proto? ws? ";" sub_def : ws? "sub" ws? sym_name proto? ws? block anon_sub : ws? "sub" block sym_name : ident "::" sym_name sym_name : ident

Replies are listed 'Best First'.
Re^3: Perl not BNF-able??
by Anonymous Monk on Jul 05, 2005 at 09:00 UTC
    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://472294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-24 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found