Re: Looking for Perl Grammar



Khamis Abuelkomboz wrote:
Joe Smith wrote:

Khamis Abuelkomboz wrote:

I'm writing a Perl parser and I'm looking for a pure perl grammar.

You won't find it.

My favorite example is this:

#!/usr/bin/perl -l
print time / 2 ; #/;  die  'This die() is not executed';
print cos  / 2 ; #/;  warn 'But this warn() is!';

To resolve the ambiguity of / as numerator/denominator versus m//
requires knowledge of which functions require arguments and which
do not.  And if the program has 'use Module;', to determine which
user-defined functions take arguments and which do not requires
actually parsing the Module.  You can't do that with pure grammar.

you got the problem, there is no clear way, when to figure out, using "/", if it is a numeric operator or a string match clause.
However I'm really not writing grammar for perl, but use similar way, how perl parse itself. my parsing gools is reporting functions, classes and variables plus cross-referencing.
I have resolved the most problems I have, however a 99% rate for "correct" interpreting the perl files is enough for me.


However I still find clauses like

if ( s{foo}{bar} ) ...
if ( s[foo][var] ) ...
if ( s<foo><bar> ) ...

If you like those how about:

if ( s{foo} <bar> ) ...
if ( s[foo]	/bar/ ) ...
if ( s<foo>
      ^bar^ ) ...



John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • Re: Looking for Perl Grammar
    ... And if the program has 'use Module;', to determine which user-defined functions take arguments and which do not requires actually parsing the Module. ... However I'm really not writing grammar for perl, but use similar way, how perl parse itself. ... my parsing gools is reporting functions, ...
    (comp.lang.perl.misc)
  • Re: Looking for Perl Grammar
    ... > documentation from perl is not a pure grammar, ... > documentation of the perl language. ...
    (comp.lang.perl.misc)