Dear All,
I have in my grammar:
fragment UNIT_NAME :;
ID : ('a'..'z'|'_')*
{
if ( myLookUpMethod( *X* ) ) $type=UNIT_NAME;
}
;
===
Instead of *X*, I wanna refer to the text that is in red.. For example, the
token w_aw_s is ID. I want to take the text of this token
OK, Sorry for that!
Just after I have sent this message I realized that the problem is that
ANTLR cannot find my method myLookUpMethod..
I have defined it in @members{} part of the grammar file.. But ANTLR still
cannot find it.. Any idea?
On Tue, May 18, 2010 at 4:35 PM, Sameh W. Zaky
On Tue, 2010-05-18 at 17:10 +0200, Sameh W. Zaky wrote:
OK, Sorry for that!
Just after I have sent this message I realized that the problem is that
ANTLR cannot find my method myLookUpMethod..
I have defined it in @members{} part of the grammar file.. But ANTLR still
cannot find it.. Any
Well, err the method inArray() is an imaginary method that you will write. It
just needs to take a string and see if that string is currently something that
should be a UNIT_NAME. If it is real simple then you could just use a standard
List object of your choice.
Please replay to the list
On Tue, May 18, 2010 at 6:04 PM, Cameron Ross cr...@kojeware.com wrote:
Hi,
Is there a way to define custom constructors for ANTLR lexers and parsers?
Sure, you can create custom methods, c-tors and attributes in:
@parser::members {
// here
}
or
@lexer::members {
// here
}
Regards,
OK - just add the reporter to the paresr members and create a
setErrorReporter() method.
Jim
From: Cameron Ross [mailto:cr...@kojeware.com]
Sent: Tuesday, May 18, 2010 9:19 AM
To: Jim Idle
Cc: antlr-interest@antlr.org
Subject: Re: [antlr-interest] Custom lexer and parser constructors
That was helpful, thanks :-)
On Tue, May 18, 2010 at 5:31 PM, Jim Idle j...@temporal-wave.com wrote:
Well, err the method inArray() is an imaginary method that you will write.
It just needs to take a string and see if that string is currently something
that should be a UNIT_NAME. If it is
A lot of you have wondered why I'd don't use enum types for token types in the
generated Java-based parsers:
enum TokenType { ID(3), INT(4) };
I gave it my best shot but once again I found that enums just don't seem to
work for me. For example, without inheritance how can I define the match
There are several advantages to enums:
* there is a discrete set of values that can be used (no accidental
42's passed in when 42 isn't a token type)
* the enum value can carry extra information
* the enum values can override methods differently
OH - one of the things that's clouding this is that
A little clarification...
Start with (as Edgar said)
public interface TokenType { }
public enum CommonTypes implements TokenType {
EOF; // others?
}
public class Token {
private TokenType type;
public TokenType getType() {return type;}
...
}
public class Parser
hello everybody my name is Ernesto and i am calling for help on antlr
programming, i am a newby in this and i am in my second semester master ,
after 12 years ago that finish my degree in computer science but because the
circumstance never work in the computer field, but planning to get
11 matches
Mail list logo