[JavaCC]: javacc how to avoid common methods.

View: New views
6 Messages — Rating Filter:   Alert me  

[JavaCC]: javacc how to avoid common methods.

by Nadun Herath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



In my javacc specification file

Have a production similar to

{

....

vardeclaration()*
methoddeclaration()*
........
}


Vardeclaration and methoddeclaration has common factor called
<IDENTIFIER>

vardeclaration()
{
    <IDENTIFIER>  | ....
}

methoddeclaration()
{
   <IDENTIFIER>  | ....
}

What is the possible way of resolving this.?




Re: [JavaCC]: javacc how to avoid common methods.

by Legéndi Richárd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Nadun,

I'd suggest reading the Lookahead mini tutorial [1], that's what you're
searching for.

There are several possibilities, for instance, if you declare variables in the
form of:

        Name() "="

where Name() is a simple node for an identifier, you could use the following
declaration:

{
...
(
LOOKAHEAD( Name() "=" )
vardeclaration()
        |
methoddeclaration()
)*
...
}

The code above may be useful for you if variable and method declarations are
allowed to follow each other.

Otherwise maybe a simple LOOKAHEAD(k) would be enough for you (k>=2).

---
Richard O. Legendi, programmer
AITIA International Inc.
E-mail: rlegendi@...

[1] - https://javacc.dev.java.net/doc/lookahead.html

Nadun Herath wrote:

>
>
> In my javacc specification file
>
> Have a production similar to
>
> {
>
> ....
>
> vardeclaration()*
> methoddeclaration()*
> ........
> }
>
>
> Vardeclaration and methoddeclaration has common factor called
> <IDENTIFIER>
>
> vardeclaration()
> {
>     <IDENTIFIER>  | ....
> }
>
> methoddeclaration()
> {
>    <IDENTIFIER>  | ....
> }
>
> What is the possible way of resolving this.?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: [JavaCC]: javacc how to avoid common methods.

by Nadun Herath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Richard

It helped to solve my problem. Thanks a lot mate.

But I have one more problem. It looks like a bug in the javacc.

Generated MiniJavaParserTokenManeger  it refers to a MyToken object like this

t = MyToken.newToken(jjmatchedKind, curTokenImage);

But there isn't any MyToken class generated. Only Token class. When MyToken change into Token
it works fine.

Thanks a lot.



On Wed, Jul 22, 2009 at 6:29 PM, Richard Oliver Legendi <roante@...> wrote:
Hi Nadun,

I'd suggest reading the Lookahead mini tutorial [1], that's what you're searching for.

There are several possibilities, for instance, if you declare variables in the form of:

       Name() "="

where Name() is a simple node for an identifier, you could use the following declaration:

{
...
(
LOOKAHEAD( Name() "=" )
vardeclaration()
       |
methoddeclaration()
)*
...
}

The code above may be useful for you if variable and method declarations are allowed to follow each other.

Otherwise maybe a simple LOOKAHEAD(k) would be enough for you (k>=2).

---
Richard O. Legendi, programmer
AITIA International Inc.
E-mail: rlegendi@...

[1] - https://javacc.dev.java.net/doc/lookahead.html


Nadun Herath wrote:


In my javacc specification file

Have a production similar to

{

....

vardeclaration()*
methoddeclaration()*
........
}


Vardeclaration and methoddeclaration has common factor called
<IDENTIFIER>

vardeclaration()
{
   <IDENTIFIER>  | ....
}

methoddeclaration()
{
  <IDENTIFIER>  | ....
}

What is the possible way of resolving this.?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: [JavaCC]: javacc how to avoid common methods.

by Tom Copeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 22, 2009, at 3:39 PM, Nadun Herath wrote:

> Hi Richard
>
> It helped to solve my problem. Thanks a lot mate.
>
> But I have one more problem. It looks like a bug in the javacc.
>
> Generated MiniJavaParserTokenManeger  it refers to a MyToken object  
> like this
>
> t = MyToken.newToken(jjmatchedKind, curTokenImage);
>
> But there isn't any MyToken class generated. Only Token class. When  
> MyToken change into Token
> it works fine.

Does the grammar file refer to MyToken anywhere?  Can you post your  
grammar here?

Yours,

Tom
http://generatingparserswithjavacc.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: [JavaCC]: javacc how to avoid common methods.

by Nadun Herath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tom

options {
  JAVA_UNICODE_ESCAPE = true;
  ERROR_REPORTING = true;
  STATIC = false;
  COMMON_TOKEN_ACTION = false;
  TOKEN_FACTORY = "MyToken";
 
}

In options section was the problem. I have included Mytoken there. When it changes to Token it works fine. But when you include MyToken it suppose to produce MyToken class isn't it.?

Thanks a lot



On Thu, Jul 23, 2009 at 2:12 AM, Tom Copeland <tom@...> wrote:

On Jul 22, 2009, at 3:39 PM, Nadun Herath wrote:

Hi Richard

It helped to solve my problem. Thanks a lot mate.

But I have one more problem. It looks like a bug in the javacc.

Generated MiniJavaParserTokenManeger  it refers to a MyToken object like this

t = MyToken.newToken(jjmatchedKind, curTokenImage);

But there isn't any MyToken class generated. Only Token class. When MyToken change into Token
it works fine.

Does the grammar file refer to MyToken anywhere?  Can you post your grammar here?

Yours,

Tom
http://generatingparserswithjavacc.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: [JavaCC]: javacc how to avoid common methods.

by Tom Copeland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Jul 23, 2009, at 7:00 AM, Nadun Herath wrote:

> Hi Tom
>
> options {
>   JAVA_UNICODE_ESCAPE = true;
>   ERROR_REPORTING = true;
>   STATIC = false;
>   COMMON_TOKEN_ACTION = false;
>   TOKEN_FACTORY = "MyToken";
>
> }
>
> In options section was the problem. I have included Mytoken there.  
> When it changes to Token it works fine. But when you include MyToken  
> it suppose to produce MyToken class isn't it.?

When you set the TOKEN_FACTORY option you are telling JavaCC that you  
have control over the creation of the Token objects.  So yes, you need  
to supply that class definition.

Yours,

Tom
http://generatingparserswithjavacc.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...