parsing in prolog

Posted on 2008-11-08
Last Modified: 2013-11-18
I am having a difficult time to create a parser in prolog that will allow me to do this:

say I have a database of vowels:


I want to create a function called match([vowel], [.....]). The dotted lines means that it's a  list of characters that will be tested if they are vowels or not. The function will return true if the entire character list contains one or more vowels found in the database. An example of an complex expression:

match([vowel], [e,e,e])

will result in:


notice that it returns true three times as vowel can match one or more vowels.. it can match [e]. [e,e] and [e,e,e]. I am having a difficult time coding it... can someone please help me out?

another example to make it much clear:

match([vowel], [e,e,k])

results in:


one other thing to consider is that I will have another patttern as well besides vowel, one of them is called cons1, which matches exactly one consonant.. we can combine both patterns, vowel and cons1. As an example:

match([vowel, cons1], [a,e,e,k]), will return:


that's the part where I am confused at... so far my code is

which works if pattern is only vowel, but if you put vowel and cons1 (i.e. like the example above) it doesn't work.. that's where I need help I think..
prefix_match([vowel|T], [H|_] ) :- vowel(H).

prefix_match([vowel|T], [H|T1] ) :- vowel(H), prefix_match([vowel|T], T1).

Open in new window

Question by:kuntilanak
    1 Comment
    LVL 27

    Accepted Solution


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now