I’m currently trying to create a software component that would be able to interprete dynamic strings such as:
%TO_LOWER%(%DELETE_WHITESPACES%("A SAMPLE TEXT"))
Which would result in this string:
asampletext
I would like to be able to define a set of available functions, with semantical parameters, etc.
I already know (more or less) how to do it using regular expressions.
My questions are:
- Is lexing/parsing way better than regexp for such a purpose, or should I just go with regexp and forget about that?
- Does such a library already exist in Java?
- Do you know any tutorial showing some sample parsing/lexing algorithms?
Thanks!
Regexes cannot express a recursive grammar, and your syntax would appear to require a recursive grammar. If this is the case, then regexes simply won’t solve the problem.
This is not a problem that a library would solve. You either need to use a parser generator system (such as Antlr or Javacc) to generate the lexer and parser, or write it / them virtually from scratch. The former approach is probably better … unless you’ve taken a Uni-level subject that covers this field, or are prepared to do extensive reading.
Both Antlr and Javacc have extensive tutorial material and examples.