Home > Archive > Compilers > March 2007 > Grammar for variable and method declarations.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Grammar for variable and method declarations.
|
|
| wooks 2007-03-01, 10:13 pm |
| How do you define a grammar where you have a class construct that
starts with a list of instance variables and method declarations for a
language like Java.
The particular difficulty is that both start
public/private datatype id and are not distinguishable until the 4th
token.
I have tried left factoring and I end up getting conflicts on my when
I declare my method and instance variable lists?
Are there some general principles for these situations. Very new to
all this.
Thanks.
| |
| Chris Dollin 2007-03-04, 4:11 am |
| wooks wrote:
> How do you define a grammar where you have a class construct that
> starts with a list of instance variables and method declarations for a
> language like Java.
Do what I /think/ they do with Java: make the syntax more liberal,
so that you can get a clean grammar, and disallow the excessively
liberal constructs later (for some value of "later").
> The particular difficulty is that both start
>
> public/private datatype id and are not distinguishable until the 4th
> token.
>
> I have tried left factoring and I end up getting conflicts on my when
> I declare my method and instance variable lists?
Example?
> Are there some general principles for these situations. Very new to
> all this.
The grammar and grammar tools are your servants, not your masters.
Just because you /can/ do it in the grammar doesn't mean you /must/
do it in the grammar.
--
Chris "electric hedgehog" Dollin
"- born in the lab under strict supervision -", - Magenta, /Genetesis/
| |
| George Neuner 2007-03-04, 4:11 am |
| On 1 Mar 2007 21:33:40 -0500, "wooks" <wookiz@hotmail.com> wrote:
>How do you define a grammar where ...
>public/private datatype id and are not distinguishable until the 4th
>token.
The language is not LL(1), left factoring can not remove all the
conflicts. You need extended look ahead and/or predication and
backtracking to parse the language in LL.
LL(k>1) tools such as Antlr and JavaCC can handle this problem in the
natural way, as can any of the LR tools.
George
|
|
|
|
|