Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any Java library to parse a simple grammar?

Tags:

java

parsing

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?

like image 979
disorderdev Avatar asked Aug 14 '26 18:08

disorderdev


2 Answers

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.

like image 132
talnicolas Avatar answered Aug 17 '26 07:08

talnicolas


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

like image 21
Dmitry B. Avatar answered Aug 17 '26 06:08

Dmitry B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!