views:

100

answers:

2

I want to parse some data, and I have a BNF grammar to parse it with. Can anyone recommend any grammar compilers capable of generating code that can be used on a mobile device?

Since this is for JavaME, the generated code must be:

  • Hopefully pretty small
  • Low dependencies on exotic Java libraries
  • Not dependant on any runtime jar files.
+1  A: 

I have used JFlex before, and I know it satisfies your second and third requirements. But I don't know how big the generated code might be. According to the manual, it generates a packed DFA table by default, so it might not be too bad.

Michael Myers
+1  A: 

The first question is do you have an existing grammar definition? When I've ported a LALR grammar to Java, I've used JFlex/CUP.

If your starting from scratch, I'd suggest you use JavaCC/FreeCC, which is an LL(k) parser. It's quite well documented and there are not runtime dependencies.

brianegge