A good way to list the next valid rule or token labels in the context of a parsed token/rule?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mila_F
Posted On:   Wednesday, June 12, 2002 07:40 AM

I need to write a CLI program that auto-completes the next token upon, say, entering of the TAB key before or during partially completed token. If there is a unique choice of a token at this point, I should be able to complete it. If the choice is not unique, I need to suggest possible choices (which may be derived from the grammar, or do some arbitrary calculation based on the context of the already parsed rules/tokens). Using a generated list of symbols does not help because it is "flat". What I need is context-sensitive, i.e. ability to access symbols in a hierarchical manner based what rule the parser has successfully processed. One of the FORUM's answers talks about generating HTML output usint -java antlr flag. This is not    More>>

I need to write a CLI program that auto-completes the next token upon, say, entering of the TAB key before or during partially completed token. If there is a unique choice of a token at this point, I should be able to complete it. If the choice is not unique, I need to suggest possible choices (which may be derived from the grammar, or do some arbitrary calculation based on the context of the already parsed rules/tokens).

Using a generated list of symbols does not help because it is "flat". What I need is context-sensitive, i.e. ability to access symbols in a hierarchical manner based what rule the parser has successfully processed.

One of the FORUM's answers talks about generating HTML output usint -java antlr flag. This is not as good as generated XML, but would probably do with some extra work. I wonder if there is a better solution that utilizes C++ generated parser without much of extra work.

It seems like a possible implementation could be to overwrite a method in the lexer to invoke a handler upon encountering the TAB key in the input stream. The handler could examine the AST tree and list the names of all the children of the current node in the grammar's AST tree, or do something else (like retrieve possible values from a DB using already entered tokens in the command).

Unfortunately I do not see how I could look at the AST node's children AHEAD of the parser, before it has processed the token

Please help.

Thanks, Alex

   <<Less
About | Sitemap | Contact