INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SOME PROLOG EXERCISES I NEED HELP WITH

SOME PROLOG EXERCISES I NEED HELP WITH

(OP)
I am stumped on this for past few weeks.
I am still learning Prolog and a beginner.

I do not wish to use cut or any non-logical Prolog built-ins as of now :)

So maybe someone could explain me the solution.


?- regularexpr_parse("([a-z][a-z0-9_]*)", S).
S = concat(class(97, 122),
Kclosure(alt(class(48, 57),
alternate(class(95, 95),
classRegularExpr(97, 122)))))
.

Kclosure -> kleene closure of regular expressions
alernate -> alternation of regular expressions
concat -> concatenation of regular expressions
classRegularExpr(low, high)
low & high if are non-negative integers < 256, this term represents a character class representing the characters between low & high inclusive.

In this problem, the term regularexpr_match is used to denote a
regular expression matching a (regex)string with RestExpr unifying with the remaining suffix of the string.
regularexpr_find represents a regular expression which matches a substring of (regex)string with RestExpr unifying with the remaining suffix of the string.


?- regularexpr_parse("([a-z])*", S), regularexpr_match(S, "abc2bc3", RestExpr).
S = Kclosure(classRegularExpr(97, 122)),
RestExpr = [50, 98, 99, 51] ;
S = Kclosure(classRegularExpr(97, 122)),
RestExpr = [99, 50, 98, 99, 51] ;
S = Kclosure(classRegularExpr(97, 122)),
RestExpr = [98, 99, 50, 98, 99, 51] ;
S = Kclosure(classRegularExpr(97, 122)),
RestExpr = [97, 98, 99, 50, 98, 99, 51] ;
false.

?- regularexpr_parse("[0-9][0-9]*", S), regularexpr_find(S, "abc123c", RestExpr).
S = concat(classRegularExpr(48, 57), Kclosure(classRegularExpr(48, 57))),
RestExprconc(classRegularExpr(48, 57), Kclosure(classRegularExpr(48, 57))),
RestExpr = [51, 99] ;
S = concat(classRegularExpr(48, 57), Kclosure(class(48, 57))),
RestExpr = [50, 51, 99] ;
S = concat(classRegularExpr(48, 57), Kclosure(class(48, 57))),
RestExpr = [99] ;
S = concat(classRegularExpr(48, 57), Kclosure(classRegularExpr(48, 57))),
RestExpr = [51, 99] ;
S = concat(classRegularExpr(48, 57), Kclosure(class(48, 57))),
RestExpr = [99] ;
false.

I will post other problems later :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close