• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regular Expression Analyser  RSS feed

 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make a program in java which will identify whether a language has a regular expression
Can anyone suggest me how shoould I start and are there any resources which can help me out
Thanks in advance
Gaurav
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are the languages described? Context free grammers?
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I have both options but I wanted to start with regular languages because they have smaller domain.For Context Free Languages complexity will arise thats why I want to start with regular expressions first
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I have both options but I wanted to start with regular languages because they have smaller domain.
I failed to parse this sentence. What options? And since all regular languages have a regular expression, there's not a lot of checking to do for them.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you creating a new language in java? Or are you just want to have a program that does something like this:
>java RegExpId Perl
>Yes, Perl supports regular expression
>java RegExpId Java
>Yes, Java supports regular expression
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a program which can tell whether input is a regular expression or not
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see. Usually the term "language" is used in computer science to refer to a class of strings. If you want to check if something is a Java regex, just call java.util.Pattern.compile(String) and if there aren't any PatternSyntaxExceptions it worked.
If you're dealing with another kind of regular expression (for there are a few different syntaxes in the world) then you may have to write a custom parser.
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David
Is it that simple I thought I have to write a huge code for it but the way you are telling it seems it is only a oneline program
Is it really so simple?
:roll:
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find the Jakarta Oro package can be used to manipulate and evaluate regexps in Perl 5, Awk and glob formats. http://jakarta.apache.org/oro/
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allow me to repost in correct English:
"You may find the Jakarta Oro package useful. It can be used to manipulate and evaluate regexps in Perl 5, Awk and glob formats. http://jakarta.apache.org/oro/"
Actually, I think my original post was pretty close to grammatically correct, it just didn't convey quite what I intended
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it really so simple?
For Perl/Java regular expression syntax, yes. Another major syntax out there is used in academia and has some notable differences. For example, the Java regular expression "[ab]+" might look like "(a+b)(a+b)*" in that syntax. Checking those in many cases would be as simple as replacing a few control characters and converting it to a Java regular expression. It'll depend on the specific syntax variant, though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!