Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parse REXX code in Java?

Tags:

java

parsing

rexx

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?

like image 560
brabster Avatar asked Mar 28 '09 22:03

brabster


People also ask

What is ARG in Rexx?

Defining a Function PARSE ARG − These are keywords in Rexx which are used to mention that parameters are being passed onto the function. arguement1, arguement2… arguementN − These are the arguments passed to the function. Return value − This is the value returned by the function.


2 Answers

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.

like image 40
VonC Avatar answered Sep 27 '22 21:09

VonC


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.

like image 145
Ross Patterson Avatar answered Sep 27 '22 23:09

Ross Patterson