Re: Grammar ambiguity

"Charles E. Bortle, Jr." <cbrtjr@ix.netcom.com>
13 Feb 2000 18:28:35 -0500

          From comp.compilers

Related articles
Grammar ambiguity joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-02-05)
Re: Grammar ambiguity idbaxter@semdesigns.com (Ira D. Baxter) (2000-02-10)
Re: Grammar ambiguity rsherry@home.com (Robert Sherry) (2000-02-10)
Re: Grammar ambiguity j.coulmance@itecor.com (Jocelyn Coulmance) (2000-02-12)
Re: grammar ambiguity world!cfc@uunet.uu.net (Chris F Clark) (2000-02-12)
Re: Grammar ambiguity joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-02-12)
Re: grammar ambiguity compres@world.std.com (Chris F Clark) (2000-02-12)
Re: Grammar ambiguity cbrtjr@ix.netcom.com (Charles E. Bortle, Jr.) (2000-02-13)
Re: Grammar ambiguity j.coulmance@itecor.com (Jocelyn Coulmance) (2000-02-19)
Re: grammar ambiguity wclodius@aol.com (2000-02-21)
Re: grammar ambiguity world!cfc@uunet.uu.net (Chris F Clark) (2000-02-27)
Re: Grammar ambiguity joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-02-27)
Re: grammar ambiguity joachim.durchholz@halstenbach.com.or.de (Joachim Durchholz) (2000-02-27)
Re: Grammar ambiguity j.coulmance@itecor.com (Jocelyn Coulmance) (2000-03-03)
[3 later articles]
| List of all articles for this month |

From: "Charles E. Bortle, Jr." <cbrtjr@ix.netcom.com>
Newsgroups: comp.compilers
Date: 13 Feb 2000 18:28:35 -0500
Organization: MindSpring Enterprises
References: 00-02-015 00-02-049
Keywords: parse

Hello,


I don't know if you will find this relevent, but the rule you have
stated sounds much like the Pascal semicolon rule. Below I
am presenting part of an LL(1) grammer I wrote for Turbo Pascal
3.0a:


<COMPOUND STATEMENT> ::= BEGIN <STATEMENTS> END
<STATEMENTS> ::= <STATEMENT> <STATEMENTS TAIL>
<STATEMENTS TAIL> ::= ; <STATEMENT> <STATEMENTS TAIL>
<STATEMENTS TAIL> ::= <EMPTY>
<STATEMENT> ::= <UNLABELED STATEMENT>
<STATEMENT> ::= <LABEL> : <UNLABELED STATEMENT>
<UNLABELED STATEMENT> ::= <SIMPLE STATEMENT>
<UNLABELED STATEMENT> ::= <STRUCTURED STATEMENT>
<UNLABELED STATEMENT> ::= <EMPTY STATEMENT>
<SIMPLE STATEMENT> ::= <ASSIGNMENT OR PROCEDURE STATEMENT>
<SIMPLE STATEMENT> ::= <GOTO STATEMENT>
<SIMPLE STATEMENT> ::= <INLINE STATEMENT>
<ASSIGNMENT OR PROCEDURE STATEMENT> ::= <ID> #COPY($1,$2) <ASSIGNMENT OR
PROCEDURE TAIL>
<ASSIGNMENT OR PROCEDURE STATEMENT> ::= <STANDARD PROCEDURES>
<ASSIGNMENT OR PROCEDURE TAIL> ::= #COPY($$,$1) <ASSIGNMENT STMT TAIL>
<ASSIGNMENT OR PROCEDURE TAIL> ::= <PROCEDURE STMT TAIL>
#PROCESS_PROCEDURE_CALL($$,$1)
<ASSIGNMENT STMT TAIL> ::= #COPY($$,$1) <VARIABLE TAIL> ASSIGN_OP
<EXPRESSION> #PROCESS_ASSIGNMENT_OPERATION($3,$1)


As this is top-down I don't know if it will be of help, but maybe?
Anyway, in Pascal a semicolon is a statement seperator rather than a
statement terminator, and somewhat fits your rule, at least lacking
precise info. The 2nd and 3rd rules above are the crucial ones, but I
have included the others so you can understand what this grammer is
doing.


--
Charles cbrtjr@ix.netcom.com
* http://pw2.netcom.com/~cbrtjr/wrdthing.html *
> Joachim Durchholz <joachim.durchholz@halstenbach.com.or.de> a écrit
>
> > Unfortunately, trying to rewrite a grammar for LALR is error-prone (at
> > least for me) and time-consuming; we're currently talking about
> > extending an existing language which is sort-of unambiguous (with a
> > rule that states "a semicolon between statements is optional unless it
> > is needed to disambiguate the program"). The language is easy to parse
> > with an Earley algorithm but a nightmare with yacc; unfortunately,
> > Accent or other Earley-based parsers will not tell me whether a CFG is
> > ambiguous or not.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.