[antlr-interest] ANTLR 2.7.7 C# Parser fails WHILE ANTLR 2.7.7 Java Parser succeeds.....why?
EXTERNAL Abdul-Rahman Atif (Praktikant; AE/PJM-WS)
external.Atif.Abdul-Rahman at de.bosch.com
Wed May 23 05:01:36 PDT 2007
Hi all,
First of all, thank you for this wonderful tool.
I have developed a working parser (in Java) for a specific text format
by using ANTLR 2.7.7.
However, when i change the target language in my grammar file from Java
to Csharp, I get a generated parser in C# which fails to parse the same
input file which was successfully parsed by the Java counterpart.
I have tried to compare the generated codes for both Java and C# and
find them to be similar in behavior. First I thought there is some
problem with my input streams (due to diff. Java and C# Stream Libs.)
but I have tested that as well, I didnt find any problems there.
Here is my grammar file:
------------------------------------------------------------------------
--------------------------------------
options {
language = CSharp;
}
//-----------------------------------------------------THE PARSER
CODE--------------------------------------------------------------------
--//
class TestDICParser extends Parser;
options {
buildAST = true;
exportVocab = DIC;
}
//----------------------------singeLine.g-------------------------------
------------
dic : FIRSTLINE^ (COMMENT)+ chart (condition)* (data_item)* ;
chart : BEGIN_CHART^ singleLine_Chart ;
condition : BEGIN_CONDITION singleLine_Condition END_CONDITION;
data_item : BEGIN_DATAITEM^ singleLine_Dataitem END_DATAITEM;
singleLine_Condition : (NEWLINE)* NAME DATA_STRUCTURE
(SHORT_DESCRIPTION)? definition ;
singleLine_Dataitem : (NEWLINE)* NAME USAGE_TYPE DATA_STRUCTURE
(SHORT_DESCRIPTION)? definition;
singleLine_Chart : (NAME! | COMMENT!)* (HTML_TAG)* END_CHART ;
definition : START_DEFINITION (~(END_DEFINITION))* END_DEFINITION;
//-----------------------------------------------------THE LEXER
CODE------------------------------------------------------------
class TestDICLexer extends Lexer;
options
{
k=6;
filter=true;
}
NAME : "name :" v:VALUESTRING {/*System.out.print(getText());
*/};//CONDITION AND DATAITEM BLOCKS
DATA_STRUCTURE : "data_structure :" v:VALUESTRING
{/*System.out.print(getText()); */};//CONDITION AND DATAITEM BLOCKS
USAGE_TYPE : "usage_type :" v:VALUESTRING
{/*System.out.print(getText()); */};//data item
protected NEWLINE : ('\n');
protected VALUESTRING : (~('\n'))* (NEWLINE);
protected SHORT_DESCRIPTION_COMMENT : '\''! (~('\''))* '\''! ;
SHORT_DESCRIPTION : "short description : " NEWLINE ('\t'
SHORT_DESCRIPTION_COMMENT)? NEWLINE ;
START_DEFINITION : "definition : " NEWLINE VALUESTRING ;
END_DEFINITION : "end definition" ;
END_CHART : "end chart";
protected HTML_TAG_START_SYMBOL : "<";
protected HTML_TAG_END_SYMBOL : ">";
protected TAG_TEXT : (~('<' | '>') )*;
protected HTML_TAG : HTML_TAG_START_SYMBOL tagname:TAG_TEXT
HTML_TAG_END_SYMBOL tagBody:TAG_TEXT HTML_TAG_START_SYMBOL
'/' tagnam1:TAG_TEXT HTML_TAG_END_SYMBOL ;
FIRSTLINE : "chart-file format version 4.2" ;
COMMENT : "--" (~('\n'))* ('\n')+ ;
BEGIN_CHART : "chart :" ;
BEGIN_CONDITION : "condition :" ;
END_CONDITION : "end condition" ;
BEGIN_DATAITEM : "data_item :" ;
END_DATAITEM : "end data_item" ;
------------------------------------------------------------------------
--------------------------------------------------
In the Csharp version, I always get an exception: unexpected token 'end
definition' .
I can't figure out what to check now. I have exhausted all options I
could think of. I am using antlr.bat provided with ANTLR 2.7.7 to
generate my parsers.
Regards,
Atif Abdul-Rahman.
More information about the antlr-interest
mailing list