Return to Volume I Explanations

 Problem 134 - Loglan-A Logical Language, Explanations 

Algorithm

It's a grammar problem, but there's an easy way to do it:

  • First, process the given string until the point and transform it into A, MOD, BA, DA, LA, PREDNAME or PRED. Transform NAM on-the-fly into PREDNAME so you don't have to do it afterwards. If a word doesn't enter any categories, return 'Bad!'.
  • Compress all successive PREDA into one predstring.
  • transform the LA predstring patterns into predname.
  • transform the MOD predstring patterns into verbpred.
  • transform the A predstring patterns into nonamepattern.
  • Compress all successive nonamepattern preceded by a preds into one single preds.
  • transform all the remaining predstring into preds.
  • transform the DA preds patterns into predclaim.
  • transform the predname BA preds patterns into predclaim.
  • transform the predname verbpred predname patterns into statement.
  • transform the predname verbpred patterns into statement.
  • transform the statement into sentence.
  • transform the predclaim into sentence.

    If the reminder is only sentence, this is 'Good', else this is 'Bad!'.

    Trick

    A, GA, MOD and PREDA aren't NAM altough they finish by vowels.

    Tabulations are whitespaces. This one is SO perverse.

    Beware to multi-point entries like 'la mutce bunbo mrenu bi ditca..' ! They are not correct sentences.

    Beware to upper-case letters, they should be downcased.

    Don't forget to add a space for each end line.

    Beware to names like CCVCVjunk or LAjunk.

    Beware to single point.

    As always, input after the end is not to be considered.

    Extra lines and extra spaces can be extra dangerous.

    If you are in trouble with the multi-entry input, read my how to read input.

    Additional Input

    134.in

    Additional Output

    134.out

    Problem

    Loglan is a synthetic speakable language designed to test some of the fundamental problems of linguistics, such as the Sapir Whorf hypothesis. It is syntactically unambiguous, culturally neutral and metaphysically parsimonious. What follows is a gross over-simplification of an already very small grammar of some 200 rules.

    Loglan sentences consist of a series of words and names, separated by spaces, and are terminated by a period (.). Loglan words all end with a vowel; names, which are derived extra-linguistically, end with a consonant. Loglan words are divided into two classes--little words which specify the structure of a sentence, and predicates which have the form CCVCV or CVCCV where C represents a consonant and V represents a vowel (see examples later).

    The subset of Loglan that we are considering uses the following grammar:

    tabular21

    Write a program that will read a succession of strings and determine whether or not they are correctly formed Loglan sentences.

    Input and Output

    Each Loglan sentence will start on a new line and will be terminated by a period (.). The sentence may occupy more than one line and words may be separated by more than one whitespace character. The input will be terminated by a line containing a single `#'. You can assume that all words will be correctly formed.

    Output will consist of one line for each sentence containing either `Good' or `Bad!'.

    Sample input

    la mutce bunbo mrenu bi ditca.
    la fumna bi le mrenu.
    djan ga vedma le negro ketpi.
    #

    Sample output

    Good
    Bad!
    Good

    Return to Volume I Explanations