Java Forum / General / August 2006
PHP Parser for Java..?
pek - 23 Aug 2006 13:00 GMT OK, I believe I looked enough on the web (google.com, irc.freenode.net, google groups etc. etc.). I can't seem to find a single PHP Parser that I can use in Java. I have downloaded Apache Xerces but I believe it is not relevant (or I'm missing something).
Anyway, to make it easier, this is what I want *exactly*:
I'm developing a small program that parsers HTML files, gets only the PHP code and tries to recognize all PHP functions that use a PHP library.
Example: <html> <?php mysql_connect("localhost","pek","peker"); ?> </html>
The program will parse the PHP code, recognize that "mysql_connect(*)" is a function, tries to find in which library the function belongs from an XML file which has a list of libraries and associated functions (this is where Xerces comes) and outputs an array of Strings with these informations: CodeLine, Function, Library etc.
I simply need a PHP Parser. Any help/ideas/tips/suggestions/etc..? Thank you for your time.
Matt Rose - 23 Aug 2006 16:11 GMT > OK, I believe I looked enough on the web (google.com, irc.freenode.net, > google groups etc. etc.). [quoted text clipped - 24 lines] > Any help/ideas/tips/suggestions/etc..? > Thank you for your time. Have a look at antlr http://www.antlr.org/ and javacc https://javacc.dev.java.net/ then either toss a coin, take your pick, or try them both.
Matt
Moiristo - 23 Aug 2006 17:18 GMT >> OK, I believe I looked enough on the web (google.com, irc.freenode.net, >> google groups etc. etc.). [quoted text clipped - 28 lines] > https://javacc.dev.java.net/ then either toss a coin, take your pick, > or try them both. I think it is unnecessary to create a complete php parser in java just to filter out the functions it contains. A simple ad-hoc algorithm would suffice. Just get all the php blocks from the page, and then use Pattern/Matcher to find all functions it contains by creating a regex.
Dražen Gemić - 23 Aug 2006 23:54 GMT >>> OK, I believe I looked enough on the web (google.com, irc.freenode.net, >>> google groups etc. etc.). >>> I can't seem to find a single PHP Parser that I can use in Java. >>> I have downloaded Apache Xerces but I believe it is not relevant (or >>> I'm missing something). This is not strictly on topic, but there is a php interpreter in Resin. I think it is in open source part, so it might help.
DG
Dave Glasser - 23 Aug 2006 19:01 GMT "Matt Rose" <matt.rose.at@gmail.com> wrote on 23 Aug 2006 08:11:40 -0700 in comp.lang.java.programmer:
>Have a look at antlr http://www.antlr.org/ and javacc >https://javacc.dev.java.net/ then either toss a coin, take your pick, >or try them both. In an upcoming project, I'm going to have to use one of these tools for parsing mathematical expressions, and I have no experience with either of them. I'd be interested in feedback from someone who's used both. Is one significantly better than the other, or is a coin toss in fact as good a way as any for choosing one over the other?
 Signature Check out QueryForm, a free, open source, Java/Swing-based front end for relational databases.
http://qform.sourceforge.net
If you're a musician, check out RPitch Relative Pitch Ear Training Software.
http://rpitch.sourceforge.net
Moiristo - 23 Aug 2006 19:47 GMT > "Matt Rose" <matt.rose.at@gmail.com> wrote on 23 Aug 2006 08:11:40 > -0700 in comp.lang.java.programmer: [quoted text clipped - 8 lines] > both. Is one significantly better than the other, or is a coin toss in > fact as good a way as any for choosing one over the other? There is a course here at the university to learn how to build a compiler using Antlr. I don't know about javaCC, but Antlr was quite easy to understand and you could very easily create a compiler for a custom language; you only need basic java and (E)BNF knowledge.
Paul Cager - 24 Aug 2006 00:18 GMT >> "Matt Rose" <matt.rose.at@gmail.com> wrote on 23 Aug 2006 08:11:40 >> -0700 in comp.lang.java.programmer: [quoted text clipped - 13 lines] > easy to understand and you could very easily create a compiler for a > custom language; you only need basic java and (E)BNF knowledge. I've always found JavaCC easy to use (well, as easy as a compiler generator can be...). JavaCC is a top-down recursive descent tool which feels similar to a hand-crafted parser. I believe the best introduction to JavaCC is:
http://www.engr.mun.ca/~theo/JavaCC-FAQ/
I've never used ANTLR, but it seems very similar to JavaCC. I must reluctantly concede that ANTLR seems to be better documented.
Oliver Wong - 24 Aug 2006 19:11 GMT > "Matt Rose" <matt.rose.at@gmail.com> wrote on 23 Aug 2006 08:11:40 > -0700 in comp.lang.java.programmer: [quoted text clipped - 8 lines] > both. Is one significantly better than the other, or is a coin toss in > fact as good a way as any for choosing one over the other? Go with ANTLR. AFAIK, the JavaCC community is dead, but ANTLR is still being actively developed, and the lead developer participates on the mailing list and is open to future design suggestions.
- Oliver
Paul Cager - 24 Aug 2006 21:39 GMT >> "Matt Rose" <matt.rose.at@gmail.com> wrote on 23 Aug 2006 08:11:40 >> -0700 in comp.lang.java.programmer: [quoted text clipped - 14 lines] > > - Oliver Well, JavaCC is still being developed (e.g. there is the Java 1.5 version). But I agree that it is less "active" than ANTLR.
EJP - 25 Aug 2006 08:58 GMT > In an upcoming project, I'm going to have to use one of these tools > for parsing mathematical expressions, and I have no experience with > either of them. I'd be interested in feedback from someone who's used > both. Is one significantly better than the other, or is a coin toss in > fact as good a way as any for choosing one over the other? If you're really just parsing mathematical expressions, either is considerable overkill. A tiny recursive-descent parser will be quite adequate.
Paul Cager - 25 Aug 2006 23:48 GMT >> In an upcoming project, I'm going to have to use one of these tools >> for parsing mathematical expressions, and I have no experience with [quoted text clipped - 5 lines] > considerable overkill. A tiny recursive-descent parser will be quite > adequate. Good point. In fact, do you need a parser at all; would a scripting engine like BeanShell work?
Dave Glasser - 26 Aug 2006 17:50 GMT Paul Cager <news8573@paulcager.org> wrote on Fri, 25 Aug 2006 22:48:45 GMT in comp.lang.java.programmer:
>>> In an upcoming project, I'm going to have to use one of these tools >>> for parsing mathematical expressions, and I have no experience with [quoted text clipped - 8 lines] >Good point. In fact, do you need a parser at all; would a scripting >engine like BeanShell work? I think it would be difficult to adapt BeanShell to this particular problem.
 Signature Check out QueryForm, a free, open source, Java/Swing-based front end for relational databases.
http://qform.sourceforge.net
If you're a musician, check out RPitch Relative Pitch Ear Training Software.
http://rpitch.sourceforge.net
Dave Glasser - 26 Aug 2006 17:47 GMT EJP <esmond.not.pitt@not.bigpond.com> wrote on Fri, 25 Aug 2006 08:01:07 GMT in comp.lang.java.programmer:
>> In an upcoming project, I'm going to have to use one of these tools >> for parsing mathematical expressions, and I have no experience with [quoted text clipped - 5 lines] >considerable overkill. A tiny recursive-descent parser will be quite >adequate. Which one do you recommend?
Oliver Wong - 28 Aug 2006 15:08 GMT > EJP <esmond.not.pitt@not.bigpond.com> wrote on Fri, 25 Aug 2006 > 08:01:07 GMT in comp.lang.java.programmer: [quoted text clipped - 10 lines] > > Which one do you recommend? I think the OP is telling you to write one from scratch.
- Oliver
maaxiim - 24 Aug 2006 13:01 GMT <snip>
> Anyway, to make it easier, this is what I want *exactly*: > > I'm developing a small program that parsers HTML files, gets only the > PHP code and tries to recognize all PHP functions that use a PHP > library. <snip>
> I simply need a PHP Parser. > Any help/ideas/tips/suggestions/etc..? > Thank you for your time. Try searching on krugle.com, enter 'php parser' in the search box and select Java as the language. the very first hit I got was 'jhp' which after a superficial scan, appears to do something along the lines of what you require.
regards
maaxiim
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|