[antlr-interest] Simple questions
Eli Mesika
elim at tti-telecom.com
Thu Feb 28 08:52:22 PST 2002
HI folks
I have a real problem in using '!' in the Antlr Tokens section.
I have tried Matthew's solution, it doesn't work.
Attached please find connect.g which describes the "connect" language.
The language can recognize the following statement:
(connect a b)
However, the exact command is
(connect! a b)
if you are generating java files from it compiling and running Main it will
accept (connect a b)
However if you change the CONNECT token in the .g file to "connect!" and
test (connect! a b) you
will get an error.
Am I missing something ???
Please HELP.
Thanks
Eli
-----Original Message-----
From: Matthew Ford [mailto:Matthew.Ford at forward.com.au]
Sent: Sunday, February 24, 2002 7:39 PM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Simple questions
----- Original Message -----
From: "elimesika" <elim at tti-telecom.com>
To: <antlr-interest at yahoogroups.com>
Sent: Monday, February 25, 2002 3:29 AM
Subject: [antlr-interest] Simple questions
> HI
>
> I have two simple questions:
>
> 1) my grammer should recognize the char '!', I have a "connect!"
> command that I should identify. I have tried to define it in the
> Tokens area :
>
> tokens {
> CONNECT = "connect!";
> }
>
> and got a run time error.
> Writing
> tokens {
> CONNECT = "connect\!";
> }
> gives an antlr compilation error.
> I am using (in the Lexer option section):
> charVocabulary = '\3'..'\377';
> How can I handle that ???
options {
exportVocab=GAUSS_AD_LEXER; // call the vocabulary "Gauss"
caseSensitiveLiterals=false;
caseSensitive=false;
charVocabulary = '\3'..'\377';
testLiterals=false; // don't automatically test for literals
k=4; // four characters of lookahead
}
tokens {
IF = "if!";
DLLCALL = "dllcall!";
}
works for me
>
> 2) I am reading a file written in a certain language.
> I have to recognize only a subset of the language, but I want to
> keep the statements that I am not recognizing.
> I have tried to use the filter option and an IGNORE rule :
>
> options {
> k=2;
> filter=IGNORE;
> charVocabulary = '\3'..'\377';
> }
>
> protected
> IGNORE
> : c:.
> {System.out.println(c);}
> ;
>
> I don't get any printing when I type things that the parser don't
> recognize.
> Does anybody knows what's the problem or have a better way to do that?
>
> TIA
> Eli
>
Have a look at the generated code to see what is happening.
You seem to trying to IGNORE every thing (.)
also try
{
String text = $getText;
System.out.println(text);
}
and
{System.out.println($getText);}
might (should!) also work also
matthew
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: connect.g
Type: application/octet-stream
Size: 5748 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20020228/a581e30a/connect.obj
More information about the antlr-interest
mailing list