[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [jbovlaste] berbere, berberi
On Tue, Jan 29, 2013 at 9:10 PM, John Cowan <cowan@mercury.ccil.org> wrote:
> Jorge Llambías scripsit:
>
>> Since we don't need to detect LALR-n-ambiguity anyway, why would
>> this limitation of a PEG make it not good enough to parse the Lojban
>> morphology?
>
> Let me use a greatly oversimplified example. Suppose we are writing a
> morphology program to parse a word into a sequence of morphemes.
> We define a morpheme as having the form V, CV, or CVn, where V and C
> are any vowel and any consonant respectively. If C does not include n,
> this grammar is obviously unambiguous, as there is only one way to parse
> any valid word into a sequence of morphemes. If C does include n, this
> grammar is obviously ambiguous: we do not know if "jana" parses as "jan a"
> or "ja na".
>
> Now if we write a YACC grammar for the latter case, like this:
>
> C : 'j' | 'k' | 'l' | 'm' | 'n';
> V : 'a' | 'e' | 'i' | 'o' | 'u';
> morpheme: V | C V | C V 'n';
> word : morpheme | word morpheme;
>
> Yacc will tell us that there is a shift-reduce error. This reflects
> the fact that the grammar is ambiguous, and therefore unsuited for a
> Lojban-style language.
>
> But if we write a PEG grammar,
But we cannot do that for that language! It's simply impossible to
write an ambiguous PEG grammar.
> we will not get a complaint: it will be all
> about whether the morpheme rule is written as C V 'n' / C V / V (which
> will prefer the parse "jan a")
and therefore does not correspond to your ambiguous language.
> or C V / C V 'n' / V, (which will prefer
> the parse "ja na").
and therefore also does not match your ambiguous language. Either of
those two PEG grammars would be suitable for a language like Lojban,
unlike the third grammar flagged as ambiguous by Yacc. PEG will never
even find that unsuitable third grammar.
> It is in this sense that a PEG grammar is unsuitable
> for Lojban: precisely because the PEG grammar settles all ambiguities in
> advance, we cannot be sure that the text has only one possible analysis.
But the text does have one possible analysis for each of the two PEG
grammars: "jan a" for one of the grammars and "ja na" for the other
grammar. They are two different grammars, each unambiguous. One of
them could be a language like Lojban. The ambiguous third language
that PEG cannot handle could never be Lojban anyway, so why should we
care that PEG cannot represent it?
If the Lojban morphology is defined by a PEG grammar, it is
unambiguous. There's nothing unsuitable about that.
> The only way to be sure is to put each alternation rule in the PEG into
> every possible order, and make sure that all texts parse the same way
> with all the variants.
That's easy to do. You just replace every (A / B) by its equivalent
(A | !A B). It doesn't matter in which order you test A and !A B
because at most only one can ever succeed. The disadvantage of doing
this is that the parsing is more inefficient, but if you don't care
about efficiency it doesn't make a difference, and now the rules can
be applied in any order.
mu'o mi'e xorxes
_______________________________________________
jbovlaste mailing list
jbovlaste@lojban.org
http://mail.lojban.org/mailman/listinfo/jbovlaste
- References:
- [jbovlaste] berbere, berberi
- From: Gleki Arxokuna <gleki.is.my.name@gmail.com>
- Re: [jbovlaste] berbere, berberi
- From: John Cowan <cowan@mercury.ccil.org>
- Re: [jbovlaste] berbere, berberi
- From: selpa'i <m3o@plasmatix.com>
- Re: [jbovlaste] berbere, berberi
- From: John Cowan <cowan@mercury.ccil.org>
- Re: [jbovlaste] berbere, berberi
- From: Jorge Llambías <jjllambias@gmail.com>
- Re: [jbovlaste] berbere, berberi
- From: John Cowan <cowan@mercury.ccil.org>
- Re: [jbovlaste] berbere, berberi
- From: Jorge Llambías <jjllambias@gmail.com>
- Re: [jbovlaste] berbere, berberi
- From: John Cowan <cowan@mercury.ccil.org>
- Re: [jbovlaste] berbere, berberi
- From: Jorge Llambías <jjllambias@gmail.com>
- Re: [jbovlaste] berbere, berberi
- From: John Cowan <cowan@mercury.ccil.org>