I'm looking for general purpose source parser in Java.
Library which can help me to parser PL/SQL code. Extract functions, procedures, packages and show dependencies between them.
Consider looking at ANTLR tool. There exist already PL/SQL grammar. Please spend some time for reading about this tool. It should surely solve your problem.
There is a plsql-parser on GitHub, quote:
This is a [almost] full parser for PL/SQL language that includes a Lexer, Parser (that optionally generates an Abstract Syntax Tree) and a TreeWalker. Current version is target for Java language, but may be easy to port it to any other target.
I am interested in porting PL/SQL data structures to Java and will try it the next weeks.
Another option could be https://stackoverflow.com/a/6631453/734687, but note that you have to port the target language from C to Java.
Related
Do you know of a C++ library (open source, or free for non-commercial use) that can parse Java source codes, for example from a jar file or defined classpath? I want to extract classes, class members, methods, method calls and relations between these artifacts.
I've spent all day googling for a solution. Either I'm blind, or can't read! :)
You can't get source codes from a jar file, since that is really a set of (binary) class files. Assuming you means the source codes that might have been used to produce a jar file, then there's a decent answer.
If you want an open source solution, you can try ANTLR, which has a Java 1.5 grammar and AFAIK will build AST. From that you can "extract" the trees for the items you want, or at least the line numbers for the subtree of interest; from there, you can extract the code you want.
I believe ANTLR can be configured to produce a C++-based parser.
To capture relations between these, you need full name and type resolution, so you know which definition an identifier actually references. For this, ANTLR being just a parser won't do the trick; you need to live a Life After Parsing.
An alternative might be the Java compiler; it offers some kind of API.
There are a number of decompilers available for Java. These aren't based on C++ necessarily, but they can convert Java classes and libraries back into source.
Examples: JD Core, DJ Java Decompiler. more
I need to extract from c/c++ source code files, function/class/macro names and their locations in their files. I need to do this in java and over a lot of files (~100/150). How can I do this?
So basically I need something similar to ctags but in java.
The easiest thing to do would probably be to write a Java Native Interface wrapper for ctags!
You could also look at finding a C++ parser in Java. Maybe abduct the parser Eclipse uses for syntax highlighting. Writing your own parser will be extremely painful since it's not a LALR grammar (I know this from experience).
The project I'm doing is written in Java and parsers source code files. (Java src up to now). Now I'd like to enable parsing Ruby code as well.
Therefore I am looking for a parser in Java that parses Ruby source code.
The only thing I have been able to find up to now are Ruby parsers in Ruby (ParseTree and RubyParser...).
I could maybe parse the source files I want with a Ruby parser in JRuby, and then access my Java stuff from there.
But that would mean that I will not be able to reuse a lot of my previously written Java code.
Is there a decent Ruby parser in Java out there and have I just not be able to find it? Or does someone see a better solution?
See http://kenai.com/projects/jruby-parser/
You could let ANTLR generate a lexer/parser for you. They have a simplified Ruby grammar available: http://www.antlr.org/grammar/1160820213459/rubyParserLexerSPGrammar.g which may be sufficient for your needs.
I'm working on a compiler design project in Java. Lexical analysis is done (using jflex) and I'm wondering which yacc-like tool would be best(most efficient, easiest to use, etc.) for doing syntactical analysis and why.
If you specifically want YACC-like behavior (table-driven), the only one I know is CUP.
In the Java world, it seems that more people lean toward recursive descent parsers like ANTLR or JavaCC.
And efficiency is seldom a reason to pick a parser generator.
In the past, I've used ANLTR for both lexer and parser, and the JFlex homepage says it can interoperate with ANTLR. I wouldn't say that ANTLR's online documentation is that great. I ended up investing in 'The Definitive ANTLR reference', which helped considerably.
GNU Bison has a Java interface,
http://www.gnu.org/software/bison/manual/html_node/Java-Bison-Interface.html
You can use it go generate Java code.
There is also jacc.
Jacc is about as close to yacc as you can get, but it is implemented in pure java and generates a java parser.
It interfaces well with jFlex
http://web.cecs.pdx.edu/~mpj/jacc/
Another option would be the GOLD Parser.
Unlike many of the alternatives, the GOLD parser generates the parsing tables from the grammar and places them in a binary, non-executable file. Each supported language then has an engine which reads the binary tables and parses your source file.
I've not used the Java implementation specifically, but have used the Delphi engine with fairly good results.
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.
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.
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.