Of course it can be done - but the answer is always "it depends". You need to define better what you need.
for example, it could be done in a java program quite simply. Assuming the String s holds
"FOR" K:=N-1 "STEP" -1 "UNTIL" 1 "DO"
you could write this:
but I'm guessing that won't actually solve your problem.
My point is that you have to decide what situations you will and won't handle. Only once you have ALL those conditions clearly thought out and defined should you consider writing a single line of java/regex/perl/whatever to solve your problem.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Also note that regex doesn't help in converting between uppercase and lowercase.
There are no new questions, but there may be new answers.
Joined: Jan 09, 2010
I was looking for a more general solution via substitution. I only need to take care of 174 routines in ALGOL 60, so its not a big effort. I understand regex isn't much use in converting upper case to lower case, then again it is easily done via built in tolowercase functionality of String class.
There are sections of code that are not easily convertible via parser, anyway. Also I need to take into consideration the machine precision. So except for some obvious substitutions, I'll have to look at each line of code. Writing a parser might take a longer time than diving into converting by hand.
The reason converting by hand is faster than a parser is that you already have a parser written, and you can find it in the back of your head which is a smart place to keep it. It is by no means difficult to write a parser, eg with lex and yacc (JFlex and CUP are more modern counterparts) or ANTLR or similar, if the grammar is context-free. You will find lex, flex, JFlex etc, use regular expressions frequently to identify numbers, keywords, etc.