tags:

views:

321

answers:

3

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?

+4  A: 

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 :

  • parse Rexx code and
  • actually builds the AST.

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.

VonC
+1  A: 

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.

Denis Troller
+5  A: 

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.

Ross Patterson