[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: Parsing Specific Productions

Hi Patricio

> Let's supose that in certain grammar you have a main production, let's
> call it P1, and you have an internal production called P2.
> Due to P2 is part of a bigger production P1, I can only reach it by
> parsing P1, an example of that is the Java grammar, taking P1 as the
> production of a class, and P2 the production of a method.

I can see your point. Do you want it in general or just for classes and
methods (and maybe blocks)?  I do not really know how to do it in general
sense, but in case of just several such productions, where you know in
advance what you would like to be able to parse, simply add all your
productions as alternatives to the top level production.  E.g.
I have modified a Java grammar because I wanted not only be able to parse:

in File1.java:

 class File1
    blah, blah, blah

but also:

in File2.mariusz_java_script

  int a = 10;

(to have Java-like scripts in seperate files).

So, the first is just ordinary goal - compilation_unit production, and for
the second to parse I have added:

compilation_unit =
    package_declaration? import_declaration* type_declaration* |
    {script} block ;

so I can get the second thing parsed as well, as
                                         goal - script_compilation_unit

It should work for classes/methods as well in your case. It should work
for most cases, where there is no conflict between alternatives in the
top most production, and, the only not nice thing is that you need to
know in advance what productions you can have as the top most
productions and you need to specify them all.

Hope that will help you to move on with the project,

best regards