C# ANTLR can't parse the Java Code with Non-latin/Non-ascii characters
- From: "Maulin Vasavada" <maulin.vasavada@xxxxxxxxx>
- Date: 11 Jul 2005 17:42:44 -0700
Hi all,
I am using ANTLR 2.7.5 for parsing Java files. I have following code in
the Java one of the files ,
(ch == 'ä') ||
(ch == 'ü') ||
(ch == 'ö') ||
(ch == 'ß') ||
(ch == 'Ä') ||
(ch == 'Ö') ||
(ch == 'Ü') ||
(ch == 'é'))
And I can't parse that file using the ANTLR parser. I get the following
error,
parser exception: Test1.java:17:33: unexpected char: '''
at JavaLexer.nextToken() in
c:\maulin\csharp\javaparser\javalexer.cs:line 541
at antlr.TokenBuffer.fill(Int32 amount)
at antlr.TokenBuffer.LA(Int32 i)
at antlr.LLkParser.LA(Int32 i)
at JavaRecognizer.identPrimary() in
c:\maulin\csharp\javaparser\javarecognize
r.cs:line 5663
at JavaRecognizer.primaryExpression() in
c:\maulin\csharp\javaparser\javareco
gnizer.cs:line 5180
at JavaRecognizer.postfixExpression() in
c:\maulin\csharp\javaparser\javareco
gnizer.cs:line 4828
I did some research and found that, this happens as those characters
are not latin or ASCII and as Java compiler (javac) converts them at
compile time to Unicode, in Java it works fine but this parser fails to
parse the file. I used 'native2ascii.exe' file to run on this file to
convert them to native to ascii characters and it worked BUT I can't do
this because I have tons of such files parsed programatically and this
is not feasible for me.
So I tried to do following which is supposed to covert the input stream
into the encoding we specify in the constructor...But still it doesn't
work. I don't get the exception any more BUT it converts those
characters into spaces instead of Unicode characters I see in .class
file like 'javac' (of course after decompiling).
JavaLexer lexer = new JavaLexer(new
StreamReader(s,System.Text.Encoding.GetEncoding("ISO-8859-1")));
I tried ASCII and Unicode encoding as well but nothing works. I keep
getting blank spaces in the parsing results.
Does anybody know how to resolve this issue? It would be great help.
Regards
Maulin
.
- Prev by Date: How to retrieve a property for a custom control.
- Next by Date: Downloading File
- Previous by thread: How to retrieve a property for a custom control.
- Next by thread: Downloading File
- Index(es):
Relevant Pages
|