A Beginner's Question concering Brackets.

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

A Beginner's Question concering Brackets.

by RagnarZero :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey, this is my first post here, so hi to everyone :)

I have recently startet to parse a language called XPro in JavaCC (don't mind if you don't know it, it is better that way) and have a problem with a simple case in this language.

I want to parse a line like this:
goal(sometexthere).

i have a token for any character:
<ANYCHAR: ~[]  >

and 2 for the brackets
  <BRACKETOPEN: "(">
|  <BRACKETCLOSE: ").">

and this is how i parse it:

void Brackets() :
{}
{
    <BRACKETOPEN> ( (<ANYCHAR>)*) <BRACKETCLOSE>
}

the problem is, when I try to parse it says to me:
Exception in thread "main" parser.ParseException: Encountered " <ANYCHAR> "( "" at line 10, column 5.
Was expecting:
    "(" ...

I just don't get this, I am sorry if this is stupid, I just began to get to use to the syntax.
I hope you can help me out.

Regards,
RagnarZero

Re: A Beginner's Question concering Brackets.

by J.Chris Findlay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Be sure that your ANYCHAR token is defined last or all single character tokens defined after it will never match.  In JavaCC, the longest match wins, otherwise they are applied in order so the first matching definition wins.

On Mon, May 11, 2009 at 5:06 AM, RagnarZero <janeknet@...> wrote:

Hey, this is my first post here, so hi to everyone :)

I have recently startet to parse a language called XPro in JavaCC (don't
mind if you don't know it, it is better that way) and have a problem with a
simple case in this language.

I want to parse a line like this:
goal(sometexthere).

i have a token for any character:
<ANYCHAR: ~[]  >

and 2 for the brackets
 <BRACKETOPEN: "(">
|  <BRACKETCLOSE: ").">

and this is how i parse it:

void Brackets() :
{}
{
   <BRACKETOPEN> ( (<ANYCHAR>)*) <BRACKETCLOSE>
}

the problem is, when I try to parse it says to me:
Exception in thread "main" parser.ParseException: Encountered " <ANYCHAR> "(
"" at line 10, column 5.
Was expecting:
   "(" ...

I just don't get this, I am sorry if this is stupid, I just began to get to
use to the syntax.
I hope you can help me out.

Regards,
RagnarZero
--
View this message in context: http://www.nabble.com/A-Beginner%27s-Question-concering-Brackets.-tp23471997p23471997.html
Sent from the java.net - javacc users mailing list archive at Nabble.com.


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




--
- J.Chris Findlay
  (c: