[antlr-interest] ANTLR
Yassin.Chkouri at imag.fr
Yassin.Chkouri at imag.fr
Mon Apr 3 05:43:28 PDT 2006
Hello,
I wrote a code in antlr in a file (g), I have create another file and I wrote a
small program. and when I execute my program by using the class Main.java, the
console posts these error message (lower part ), but I am sure that there are no
errors neither in the program nor in the code written in antlr. I said can be I
have a problem in the instalation of antlr.
Can you could help me in this point???
here the mmessage of error posted in the console:
parser exception: line 2:10: expecting ':', found ' '
line 2:10: expecting ':', found ' '
at BipLexer.nextToken(BipLexer.java:286)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at BipParser.top(BipParser.java:51)
at Main.parseFile(Main.java:68)
at Main.doFile(Main.java:53)
at Main.main(Main.java:20)
**********************************************************************
The Grammar:
class BipParser extends Parser;
options {
k=4; // needed for newline junk
// buildAST=false;
// defaultErrorHandler=false;
}
top : (compDef)+
;
compDef
: COMPONENT IDENTIFIER opt_arg CODE END
;
opt_arg : ( LPAREN (arg_decl_list) RPAREN )?
;
arg_decl_list : arg_decl (COMMA arg_decl)*
;
arg_decl : type_id IDENTIFIER
;
type_id : IDENTIFIER
| CPPIDENTIFIER
;
c_code : CODE
;
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
class BipLexer extends Lexer;
options {
k=3; // needed for newline junk
charVocabulary='\u0000'..'\uFFFF'; // allow UNICODE
// caseSensitive = false;
// caseSensitiveLiterals = false;
// defaultErrorHandler=true;
}
tokens {
COMPONENT="component";
END="end";
BEHAVIOR="behavior";
STATE="state";
WITH="with";
ON="on";
PROVIDED="provided";
WHEN="when";
DO="do";
TO="to";
PORT="port";
DATA="data";
CONNECTOR="connector";
EAGER="eager";
DELAYABLE="delayable";
LAZY="lazy";
CONTAINS="contains";
CLASS="class";
PRIORITY="priority";
IF="if";
ELSE="else";
INIT="init";
RENAME="rename";
COMPLETE="complete";
INCOMPLETE="incomplete";
}
LPAREN: '(' ;
RPAREN: ')' ;
CO : "{#";
CC : "#}";
LCURLY: '{' ;
RCURLY: '}' ;
COLON: ':' ;
PLUS : '+' ;
MINUS : '-' ;
STAR : '*' ;
SEMI : ';' ;
COMMA : ',' ;
DOT : '.' ;
EQUALS: '=' ;
LT: '<' ;
GT: '>' ;
DIV: '/' ;
POURCENT: '%' ;
CHAPEAU : '^' ;
INTERO : '!' ;
LBRACKET : '[' ;
RBRACKET : ']' ;
XX : '#' ;
EQ : "==" ;
NE : "!=";
GE : ">=";
LE : "<=";
AND : "&&";
OR : "||";
DPT : "::";
IDENTIFIER : ('a'..'z'|'A'..'Z') ( ('_')? ('a'..'z'|'A'..'Z'|'0'..'9'))*
exception
catch [RecognitionException ex] {
reportError(ex);
consume();
}
;
CODE
:
"{#" (
options {
generateAmbigWarnings=false;
}
:
{ LA(2)!='#' || LA(3) != '}' }? '#'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('#'|'\n'|'\r')
)*
"#}"
;
CPPIDENTIFIER
: IDENTIFIER DPT IDENTIFIER
;
LETTER : ('a'..'z')|('A'..'Z') ;
DIGIT : ( '0'..'9' ) ;
ALPHA
: LETTER IDENTIFIER
;
INTEGER
: (DIGIT)+
;
REAL
: INTEGER DOT INTEGER
;
WS
: ( ' '
| '\t'
| '\f'
// handle newlines
| ( "\r\n" // DOS/Windows
| '\r' // Macintosh
| '\n' // Unix
)
// increment the line count in the scanner
{ newline(); }
)
{ $setType(Token.SKIP); }
;
SL_COMMENT
: "//"
(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
{$setType(Token.SKIP); newline();}
;
*************************************************************************
The text are parsing :
component worker
{# printf("xxxxx"); #}
end
component Team
end
***************************************************************************
Cordially
M.Y.CHKOURI
-------------------------------------------------
envoyé via Webmail/IMAG !
More information about the antlr-interest
mailing list