I want to use Java to parse a very simple grammar, for example:
/*comments*/
"aaa" = "bbb"
That's all. I want all tokens (comment, string, equals).
Is there any Java library that can handle this?
I want to use Java to parse a very simple grammar, for example:
/*comments*/
"aaa" = "bbb"
That's all. I want all tokens (comment, string, equals).
Is there any Java library that can handle this?
You gonna have to write the base grammar that recognize everyone of these tokens and then generate the parser (lexical and syntaxic) with a tool like SableCC or JavaCC (They both produce Java classes). Then you'll have a parser that can parse your language.
I hope it is what you meant by parse a [...] grammar
.
for really basic needs you can use either java.util.StringTokenizer or java.io.StreamTokenizer.
You can code a recursive descent parser pretty easily for a simple language. See Is there an alternative for flex/bison that is usable on 8-bit embedded systems?