3

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?

4
  • 1
    I didn't get it. Are you looking for something like ANTLR? antlr.org Commented Nov 9, 2011 at 6:06
  • @zengr I believe so. Please follow this: stackoverflow.com/questions/278480/antlr-tutorials and this jnb.ociweb.com/jnb/jnbJun2008.htm Commented Nov 9, 2011 at 7:26
  • Maybe OP only wants the tokens and not an actual parser for the implied simple grammar? Commented Nov 9, 2011 at 9:47
  • ANTLR might be a little too heavy for such a simple thing. but if you all recommend ANTLR, I'll try it. thanks. Commented Nov 9, 2011 at 18:05

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

for really basic needs you can use either java.util.StringTokenizer or java.io.StreamTokenizer.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.