Project Inquiry

I have this school project to work on, but i have no idea on how to start it, any input or help would be great.

translate Rules for legal English sentences can be represented as grammar rules. For the purposes of this project, we will only have the following rules:

<sentence> ::= <noun><verb><noun>

<sentence> ::= <noun><verb><adjective><noun>

<sentence> ::= <pronoun><verb><noun>

<sentence> ::= <pronoun><verb><adjective><noun>

<sentence> ::= <pronoun><verb><pronoun>

For example, the first rule says that a noun followed by a verb followed by a noun (and nothing else) is one way to make a legal sentence.

Of course the actual English language contains many more such rules. Also note that we are concerned purely with syntax, and can thus construct sentences that are semantic nonsense (e.g., "I perform depression") or do not take into account other grammatical rules such as those about subject-verb agreement (e.g., "I are large bird").

Input:

You have available to you 4 input files1, named nouns, verbs, adjectives, and pronouns. These files have been filtered to exclude words that can be multiple parts of speech (e.g., dance). Each file contains one word per line, all lowercase.

The input files are supplied in tar form. To extract them, type "tar -xvf words.tar" without the quotes - you will learn about tar later in 136.

Part A:

Prompt the user for a sentence. Depending on whether or not the sentence is a legal English sentence according to the above rules, output one of the following 6 messages (exactly as stated) to the screen, and terminate:

Your sentence is a legal sentence by rule {1,2,3,4,5}.

Your sentence is not a legal sentence.

You may assume that the input sentence contains only letters and spaces, though letters may be either upper or lower case. Words in the sentence are separated by at least one space.

Part B:

Elbonian is similar to English, but has 2 differences:

Verbs always occur at the beginning of the sentence (rumor has it that Elbonians like to start doing things before understanding the problem). Other words are still in the same order as in English. For example, rule 1 above would be as follows in Elbonian:

<sentence> ::= <verb><noun><noun>

There are no adjective words, and the modified noun is changed instead. More specifically, the modified noun is changed to have the first letter of the adjective as a prefix and the remaining letters as a suffix.

For example, the English sentence "I avoid large thing" would be "avoid I lthingarge" in Elbonian.

Given a file of sentences named "engsents", produce a second file named "elbsents" containing the equivalent Elbonian sentences. Both files contain one sentence per line. If an input is not a legal sentence, you should output "Illegal sentence found" on its own line in the output file and proceed to the next sentence. Your translation should preserve cases, though the output should have exactly one space between words.

For this program you may only use those concepts covered through strings in lecture. This includes file I/O, functions, and all control structures, but EXCLUDES any libraries (e.g., string library functions not covered in class) or data structures (e.g., arrays, vectors, structs, pointers) coming later this semester. This means that you will need to read the input files many times.


I can provide the words in the text files if needed!

The language is strictly regular.... there is no recursion at all. That makes this easier.

Write methods to identify the type of a given token -- pronoun, noun, verb, or adjective.
Then, examine each line of the input file.

Examine each word ("token") in the line and determine it's types. You will be able to progressively narrow down the possible candidates, allowing you to classify each line into one of the five sentence types (or an illegal sentence).

With that information, you'll be able to perform the conversion to Elbonian.
could you possibly just start me off?
an enum might help: enum partsOfSpeech{noun = 1, verb, adjective, pronoun};
so the valid sentence patterns are (121, 1231, ... etc)
now parse the sentence - if the first word is not noun or pronoun it's not a legal sentence (go straight to message 6), if it is noun or pronoun move on to the next word which must be verb else not legal sentence (again straight to message 6) - after that check the 3rd and 4th words outright rather than with further sub-branches and check the number pattern of the resulting sentence against the valid patterns based on the enum - 121, 1231, etc ...
You may only use those concepts covered through strings in lecture.

I'm afraid I didn't attend the lecture(s) you did, which makes that a little difficult.
Topic archived. No new replies allowed.