1

So we have defined a set of API's that end users (functional folks precisely) would be using to perform their data transformations. Ex, for input as Name = "XyZ", the functional folks can define a transformation rule like @Text.UpperCase(Name) to convert every value they get for name to uppercase. The way it works is that every word defined after @ is the data type and every word defined after a . is a method followed by parenthesis and a value. While this is what we have planned, I am trying to figure out if:

1> We really need a grammar that would be used to parse such inputs?
2> How can I arrange the nested calls like @Text.UpperCase(@Text.trim("XyZ "))?

name_masked
  • 9,544
  • 41
  • 118
  • 172
  • Is the grammar fixed? If not, take a look at one of the many scripting languages available in Java. You might be able to use Expression Language or JavaScript (Mozilla Rhino) to meet your goals – Royce Mar 08 '12 at 20:58
  • JFlex might be an option: http://jflex.de/manual.html#SECTION00040000000000000000 – Royce Mar 08 '12 at 21:05

1 Answers1

1

You should define a grammer just to make sure you know what you will allow users to type.

You might not need a parser generator, if your grammar is simple enough (e.g., the only thing your users can type are in effect function calls over named variables). In this case, ad hoc parsing may be enough. That would be good enough for your simple example.

If your grammar has modest complexity (e.g., nested calls), you can code a recursive descent parser pretty easily that will do the job.

If you grammar gets complicated (the users will surely ask for more features), you might want a parser generator.

If it were me, with the requirements you stated, I'd build the recursive descent version, after writing a grammer that I got a parser generator to accept. That would also be useful documentation in the, ahem, user manual.

Community
  • 1
  • 1
Ira Baxter
  • 93,541
  • 22
  • 172
  • 341