Reputation: 43590
I'd like to parse REXX source so that I can analyse the structure of the program from Java.
I need to do things like normalise equivalent logic structures in the source that are syntactically different, find duplicate variable declarations, etc. and I already have a Java background.
Any easier ways to do this than writing a load of code?
Upvotes: 5
Views: 1159
Reputation: 9569
REXX is not an easy language to parse with common tools, especially those that expect a BNF grammar. Unlike most languages designed by people exposed to C, REXX doesn't have any reserved words, making the task somewhat complicated. Every term that looks like a reserved word is actually only resolved in its specific context (e.g., "PULL" is only reserved as the first word of a PULL
instruction or the second word of a PARSE PULL
instruction - you can also have a variable called PULL ("PULL = 1 + 2
")). Plus there are some very surprising effects of comments. But the ANSI REXX standard has the full syntax and all the rules.
Upvotes: 8
Reputation: 7501
Have a look at ANTLR, it really does a nice work of building an AST, transforming it etc... It has a nice editor (ANTLRWorks), is built on Java, and can debug your parser / tree walkers while they run in your application. Really worth investigating for any kind of parsing job.
Upvotes: 2
Reputation: 1328192
If you have BNF Rexx grammar, then javacc can help you build an AST (Abstract Syntax Tree) representation of that Rexx code.
More accurately, javacc will build the Java classes which will :
There would still be "load of code", but you would not to be the one doing the writing of the classes for that Rexx code parser. Only its generation.
Upvotes: 5