Posted By:
Anonymous
Posted On:
Monday, July 26, 2004 04:26 AM
Hi, I'm interested in parsing only certain parts of a program file (i.e. structures in C), and I don't want to specify the complete grammar (and use the filter option in Lexer). But how can I tell antlr to ignore everything untila struct variable is found, process it, and than ignore the rest. The description in the ANTLR user guide is too short and it is not easy to guess how this would be done from the HTML filtering example given there. Therefore any help is appreciated. I've tried something like following, but it didn't work. This is for some other Pascal like language: class RecordParser extends P
More>>
Hi,
I'm interested in parsing only
certain parts of a program file (i.e. structures in C),
and I don't want to
specify the complete grammar (and use the filter option in Lexer).
But how can I tell antlr to ignore everything untila struct
variable is found, process it, and than ignore the rest.
The description in the ANTLR user guide is too short and
it is not easy to guess how this would be done from
the HTML filtering example given there. Therefore any help
is appreciated.
I've tried something like following, but it didn't work. This
is for some other Pascal like language:
class RecordParser extends Parser;
record :
"RECORD" ID SEMICOLON
(variable | COMMENT )+
"END" "RECORD" SEMICOLON
;
variable:
... //rules and actions here
class RecordLexer extends Lexer;
options {
charVocabulary = 'u0000'..'u00FF';
filter=true;
}
COMMENT : '!'
('
' {newline();} |
~('!' | '
'))*
'!'
{$setType(Token.SKIP);}
;
ID : ('A'..'Z')('A'..'Z' | NUM)* ;
INDEX :'(' NUM ')' ;
NUM : ('0'..'9')+ ;
SEMICOLON : ';' ;
WS :
( ' ' | ' ' | '
' {newline();} )
{_ttype = Token.SKIP;}
;
thanks in advance...
BR,
hba
<<Less