Posted By:
Sylvanna_Rodriguez
Posted On:
Friday, July 29, 2005 09:23 AM
I'm doing a natural language parser and here is a part of the code that I've written: class MyParser extends Parser; options { k = 3; } sentence : subject predicate ; subject : pronoun | noun ; pronoun : "I" | "you" | "he" | "she" | "him" | "her" | "they" | "them" { System.out.println( "pronoun matched" );} ; noun : "apple" | "banana" | "cherry" { System.out.println( "noun matched" );} ; class TagJapLexer extends Lexer; options { k = 3; filter = true; }
More>>
I'm doing a natural language parser and here is a part of the code that I've written:
class MyParser extends Parser;
options { k = 3; }
sentence : subject predicate
;
subject : pronoun | noun
;
pronoun : "I" | "you" | "he" | "she" | "him" | "her" |
"they" | "them"
{ System.out.println( "pronoun matched" );}
;
noun : "apple" | "banana" | "cherry"
{ System.out.println( "noun matched" );}
;
class TagJapLexer extends Lexer;
options { k = 3; filter = true; }
ALPHA : ( 'a'..'z' | 'A'..'Z' | '-' )+
{ System.out.println( "Word: " + getText() ); }
;
My problem is I don't know how to get the text from the parser for each matching rule, because I would like it to be displayed like this:
noun found: apple
pronoun found: I
I've tried using
{ System.out.println( "pronoun matched" + getText());}
but it still didn't work. Can anybody help me solve this problem. Thanks!
<<Less