Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaCC

 
J Ba
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to know which tokens are possible to follow a partial
string according to a grammar, whose JavaCC parser was generated?

For example:

Lets say you have:

x ::= yz
y ::= "y"
z ::= "a" | "b"

Is it possible that through a JavaCC parser for the above grammar, I
have some kind of framework where if I will provide "y", I will get an
array of the next possible tokens "a" and "b".

For a better understanding of what I need, I want to generate a sort
of small wizard application for a small grammar. This wizard would help the
user in constructing the syntactically correct statements by popping
up the possibilities and the user chooses from them. For example, it
is very similar to how JBuilder pops up a window with the
possibilities in the editor window.
 
Daniel Schreiber
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm very interested in this problem too. The only solution
I thought of is to feed the current input to a different TokenManager object and try to continue with all tokens. The tokens that pass
without an error are the possible extensions at this point.

Haven't implemented it yet because I have no idea how to do this
so far, and it sounds a bit time consuming to try all possible tokens
all the time.

Would be nice if you post your solution.

best regards
Daniel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!