I am looking for a parser generator that accepts a Javacc grammar file (.jj) and generates a parser in Javascript (instead of Java). Does such a thing exist? Alternately how difficult would it be to convert the .jj file to something that ANTLR (which can output Javascript) can understand?
I am looking for a parser generator that accepts a Javacc grammar file (.jj) and generates a parser in Javascript (instead of Java). Does such a thing exist?
Apparently, no.
Alternately how difficult would it be to convert the .jj file to something that ANTLR (which can output Javascript) can understand?
It would be non-trivial, and you'd need to do it by hand. But the actual degree of difficulty probably depends on the grammar you are trying to convert.
It is worth noting that there are other parser generators that output parsers in Javascript. (And, no, I'm not going to list them or recommend one!)
Obviously, the input language will be different to Javacc input.
Google's GWT compiles java code to JavaScript, as long as only a specific subset of the JDKis used. I'm also not sure how much GWT-specific cruft it brings along. But that might be a possibility: using javacc to generate java code, and then GWT to translate it to JavaScript.
I recently added support for a GWT compatible parser target to JavaCC (no dependencies on Java IO classes). I recently wrote a pair of blogs on how to use JavaCC so that a JavaScript parser can be generated via GWT. Link below:
Building parsers for the web with JavaCC & GWT (My blog post)
JavaCC 6.1 Development Build
If you don't mind rewriting your grammar,
I have written a parser builder in Kotlin common code, so it will run on a JavaScript platform.
The grammar syntax is fairly simple and EBNF like.
You can see details here, and there is a link to a demo running in the browser if you want to try it out.
https://medium.com/#dr.david.h.akehurst/a-kotlin-multi-platform-parser-usable-from-a-jvm-or-javascript-59e870832a79
Related
I was using ant to build some files and I was going through javacc. I found that javacc 6.0 has some .jj files for java 1.5 and 1.6, does anyone know if it was updated with a java1.8.jj file?
JavaParser is a mature parser for Java which supports Java 8 (and we are starting working on Java 9).
It is based on JavaCC, so it contains a JavaCC grammar for Java 8. Depending on what you need to do you could use the whole project or just adapt the grammar to your need.
JavaParser is released under Apache License 2.0 and LGPL: you can choose under which terms to use it.
Source: I am a contributor to JavaParser
Please see javaparser-core/java_1_8.jj.
In addition to the other comments: the grammar in the JavaParser project has been "enhanced" with Java code for several nasty situations and it is not recommended to use it without the rest of the library.
Firstly there is an almost identical question but the answer is not really satisfactory.
Is there a Java or Ruby library for generating MOBI ebook documents?
The answer basically gives a link to amazon and discusses using command line tools which is not really satisfactory for a web app. I want a regular jar file w/ an api that i can invoke without any nasty process invocation.
Does anyone know of a FOSS library that provides this functionality ? I would rather simething like ITEXT that allows me to build the document and then writes the mobi file rather than something that converts an already ready PDF into the MOBI.
The best I've been able to find is a ruby library called KindleR. https://github.com/josh/kindler
I've only used it to convert basic HTML pages to mobi with pretty good success. I've never converted anything with more complicated formatting, so YMMV.
I would like to create an automatic Flowchart-like visualization to simple Java Logic, for this I need to parse Java Source code, I have 2 candidates, ANTLR and javax.lang.model of Java 6. Neither are easy.
I have yet to find a single working example that will be even remotely close to what I want to achieve.
I want to find simple variable declarations, assignments, and flows (if, for, switch, boolean conditions etc)
Is there a simple example or tutorial for either of these?
I found very few ANTLR examples (non of them are working out of the box without significant "homework") and absolutely none for javax.lang.model
Is there a particular reason you want to generate a parser yourself? IMO, it would be easier to let an existing parser create an AST for you which you "simply" traverse in order to collect your data about the source file(s). Using your favorite search engine with the keywords "get ast java source" will result in many relevant hits.
At a first glance, these look like suitable candidates:
Eclipse JDT API
javaparser
You could use ANTLR of course, there are many ANTLR grammars for Java available for you, but there is quite the learning curve when choosing this tool (or some other parser generator, for that matter). If you do choose ANTLR, I'm more than happy to answer any questions regarding it.
Best of luck!
I would try that with Eclipse Xtext, it uses ANTLR under the hood, it is also (relative) easy to use it together with Eclipse GMF for visualization.
I suggest you to go with Java Soot a Java Optimization Framework. Which will help you to parse the java source, can generate the CFG and various options available.
Also you can find eclipse plugin here
Is there any Grammar editor utility for context-free grammars developed in Java?
The one I know about would be XText.
Might be a bit over-kill:
Xtext is a framework for development of programming languages and domain specific languages (DSLs). Just describe your very own DSL using Xtext's simple EBNF grammar language and the generator will create a parser, an AST-meta model (implemented in EMF) as well as a full-featured Eclipse text editor from that.
The DSL editor looks like:
alt text http://www.eclipse.org/Xtext/documentation/latest/images/getting-started-grammar.png
Allowing you to play with the language you just defined:
alt text http://www.eclipse.org/Xtext/documentation/latest/images/getting-started-editor.png
ANTLRWorks the GUI development environment for ANTLR is quite nice. I've used it with ease in the past.
http://www.antlr.org/works/index.html
I also found that:
http://ozark.hendrix.edu/~burch/proj/grammar/
If you prefer compiler built into your app without generating any source files, take a look at Parboiled: https://github.com/sirthias/parboiled
I'm doing a lot of work with a DSLs at the moment and was wondering if anyone knew of a tool that could generate a parser for my bnf specification that does not require a run-time library (pure java source parser)?
I'm committed to using XTEXT for a future Eclipse plug-in but I need a nice small version for my library itself and don't want to add another jar dependency.
It seems that ANTLR requires a run-time to parse files and I performed a Google search with no avail. Can anyone help out?
Thanks,
Chris
Javacc generates java parsers from BNF-like input, and does not require a runtime library. You may need to modify the BNF slightly, I think there are some caveats as to what Javacc can accept.