Is there a java1.8.jj for javacc? - java

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.

Related

Java flight recorder programmatically parsing

I'm trying to Parse JFR dump using JAVA.
I followed this blog, http://hirt.se/blog/?p=446 .
But these methods are deprecated now. Is there any supported parsers for JFR to JAVA? if not can you point me is it possible to retrieve data from JFR dump?
There is currently no supported parser.
There are however many people both inside and outside of Oracle who are using the parsers mentioned in that blog post quite successfully.
There will possibly be a supported parser in the future, there will certainly be changes to the parser, I'm just no sure if it will be "supported" or not.
But the code you are writing now should work just fine with JDK 7 and 8 flight recordings, and will not will with JDK 9 recordings.
As Klara mentioned, there is no officially supported parser. Hopefully the JFR parser will be supported officially in JDK 9. For now, you can use the APIs mentioned in Hirt's blog. Don't worry about those being deprecated. :)
I have successfully used JFR parser in my jfr-flame-graph project. Please note that my project uses Maven and the JFR parsers are not available in Maven Central (or any other repository). Therefore the "Step 1" in the README is important and it'll copy JFR parser jars to a local repository and you can use those jars as dependencies in your pom.xml
I hope this helps.

java.nio.Files, java.nio.Paths on java 6

I need to rewrite some java 7 file IO code that should run on a Java 6 VM too.
The implementation uses handy Java 7 features like autoclosing, Paths and Files.
To be more specific, I need to handle expressions like /tmp/foo/*.bar to return all .bar files (currently implemented with Files.newDirectoryStream(dir, glob)).
Does anyone know a handy library for this?
The Apache Commons IO API is also a good choice. I used it for a similar work (rewrite some code from java7 to java6 that used Path object) and they work very well.
The Apache Ant API would be a good candidate for this, in particular their FileSet class might do the job.
guava runs on java6 and it has a nice I/O api.

Is there a version of Javacc that outputs javascript code?

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

Examples / tutorials for usage of javax.lang.model or ANTLR JavaParser to get information on Java Source Code

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 a tool for generating a DSL parser that does not require a runtime for the resultant parser?

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.

Categories