I have defined a set of grammar rules. Consider this as a sample rules.
public bodylist
: bodyset*
;
public bodyset
: ruleSet
| media
| page
;
If I have to parse using this rules, I have to do this as below.
Stream inputStream = Console.OpenStandardInput();
ANTLRInputStream input = new ANTLRInputStream(inputStream);
CLexer lexer = new CLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
CParser parser = new CParser(tokens);
parser.bodylist();
I am confused with the way of accessing the bodyset matching set of segments in the stream. It seems I have to do another parse as below
parser.bodyset();
There can be morethan one bodyset grammar matching set of segments in the stream.
Lets say in the input stream we have more than one places where this rule is matched. What I want is to get information on the set of these bodyset
information (in each, what is the start of the grammar rule and the end).
I was unable to find a way to access the information of the set of matches of bodyset
grammar rule in the stream. I am confused with the API.
ANTLR 3 does not automatically create parse trees with listeners and visitors like ANTLR 4 does. You'll need to do one of the following:
bodylist
method will return a BodylistContext
object, which provides a bodyset()
method that returns a collection of BodysetContext
objects (one for each bodyset
that was parsed). output=AST
feature and tree grammars to process the input.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.