Question

How can Prolog be used to parse this arbitrary string? S → DZ D → dD...

How can Prolog be used to parse this arbitrary string?

S → DZ

D → dD

D → d

Z → zZ

Z → z

So far I have this code, but it has proven ineffective.

A represents the input and B represents the resulting string.

s(A,B):- d(A,C), z(C,B).

d([d,d|A],A).

z(z,z|A],A).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

We can use prologue to parse this arbitrary string in d following way

The string is

S → DZ

D → dD

D → d

Z → zZ

Z → z

Here A represents the input and b represents d resulting string

s(A,B):- d(A,C), z(C,B).

d([d,d|A],A).

z(z,z|A],A)

Here we get a parse d string.

Add a comment
Know the answer?
Add Answer to:
How can Prolog be used to parse this arbitrary string? S → DZ D → dD...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Task In this challenge you parse RGB colors represented by strings. The formats are primarily used...

    Task In this challenge you parse RGB colors represented by strings. The formats are primarily used in HTML and CSS. Your task is to implement a function which takes a color as a string and returns the parsed color as a map (see Examples). Input represents one of the following: color The input string 1.6-digit hexadecimal "#RRGGBB" - Each pair of digits represents a value of the channel in hexadecimal: 00 to FF 2.3-digit hexadecimal "#RGB" - Each digit represents...

  • Write a program that can remove spaces from an input string, find the indexes of a...

    Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...

  • using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...

  • As mentioned in Assignment 5. Prolog can be used to solve problems that are quite difficult with other programming languages.This is mainly because of the declarative nature of the languages....

    As mentioned in Assignment 5. Prolog can be used to solve problems that are quite difficult with other programming languages.This is mainly because of the declarative nature of the languages. What kind of difficulties do you think there will be if you are asked to write a program in another language fe.g. Python) to solve the puzzle in Assignment 5 L Introduction Prolog Is a language that Is sultable for solvins problems in the fleld of artifical Intelligence. That is,...

  • package week_3; /** Write a method called countUppercase that takes a String array argument. You can...

    package week_3; /** Write a method called countUppercase that takes a String array argument. You can assume that every element in the array is a one-letter String, for example String[] test = { "a", "B", "c", "D", "e"}; This method will count the number of uppercase letters from the set A through Z in the array, and return that number. So for the example array above, your method will return 2. You will need to use some Java library methods....

  • def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or...

    def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...

  • edef extract_num(s, begin, end): Given string s, and "begin" is the index of the first of...

    edef extract_num(s, begin, end): Given string s, and "begin" is the index of the first of one or more digits, and "end" is the index one beyond the last digit. Parse out and return the int value of the number, accounting for possible 's' and 'a', Return -1 if the number should be skipped. >>> extract_nun('xx123$, 2, 5) 321 >>> # add Doctests here 29 def. parse line(s): Given a string s, parse the ints out of it and return...

  • 4. Consider the block diagram shown below where D(s) is a step disturbance input. D(s) Controller...

    4. Consider the block diagram shown below where D(s) is a step disturbance input. D(s) Controller Plant R(s) + E(s) C(s) G2(s) Ideally you want your controller design to reject a step disturbance input at D(s). This means that in the steady state for D(s)-1, the value of Y(s) is unchanged (a) Ignoring the input R(s), what is the transfer function器in terms of Gi(s) and G2(s)? (b) For G1(s)Ks 2) and G2(s)0419 what is the steady state error resulting from...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • I need to update this code: #include <iostream> #include <string> #include <cctype> using namespace std; int...

    I need to update this code: #include <iostream> #include <string> #include <cctype> using namespace std; int main() { string s; cout<< "Enter a string" <<endl; getline (cin,s); cout<< s <<endl; int vowels=0,consonants=0,digits=0,specialChar=0; for (int i=0; i<s.length(); i++) { char ch=s[i]; if (isalpha(s[i])!= 0){ s[i]= toupper(s[i]);    if (ch == 'a'|| ch == 'e'|| ch == 'i'|| ch == 'o' || ch == 'u') vowels++; else consonants++; } else if (isdigit(s[i])!= 0) digits++; else specialChar++; } cout<<"Vowels="<<vowels<<endl; cout<<"Consonants="<<consonants<<endl; cout<<"Digits="<<digits<<endl; cout<<"Special Characters="<<specialChar<<endl;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT