• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is this possible with regex?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following is a line of code in ALGOL 60



In Java I could write it as


Is there a way to do this programmatically using regex or something else? If so could you tell me how?

-Thanks
Ravi
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also note that regex doesn't help in converting between uppercase and lowercase.
 
Ravi Shankarappa
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

-Ravi
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic