From: Joel Reymont
Subject: Help with cl-yacc
Date: 
Message-ID: <1139184555.084472.141720@o13g2000cwo.googlegroups.com>
Folks,

I'm putting together a Pascal-like grammar and at the top level it's a
bunch of statements or declarations where statements _and_ declarations
are required to be terminated with a semicolon. The grammar below does
not work but I don't understand why as ultimately the semicolon is
present both in statements and in declarations.

(yacc:define-parser parser
  (:start-symbol sections)
  (:terminals (|;| :id1 :id2))

  (sections
   (sections section)
   section)

  (section statements
	   declarations)

  (statements (statement |;|)
	      (statements statement |;|))

  (statement ()
	     open-statement
	     closed-statement)

  (declarations (declaration |;|)
		(declarations declaration |;|))


  (open-statement :id1)
  (closed-statement :id2)
  )

     Thanks, Joel

From: Joel Reymont
Subject: Re: Help with cl-yacc
Date: 
Message-ID: <1139184981.294006.313210@z14g2000cwz.googlegroups.com>
Thanks Matt!

I think this should work.

(yacc:define-parser parser
  (:start-symbol sections)
  (:terminals (|;| :id1 :id2))

  (sections (sections section |;|)
	    (section |;|))

  (section ()
	   statement
	   declaration)

  (statement open-statement
	     closed-statement)

  (open-statement :id1)
  (closed-statement :id2)

  )
From: Joel Reymont
Subject: Re: Help with cl-yacc
Date: 
Message-ID: <1139185383.771617.322820@g43g2000cwa.googlegroups.com>
Well, it won't work for an empty file which I would like to cover. How
would I do that?
From: Joel Reymont
Subject: Re: Help with cl-yacc
Date: 
Message-ID: <1139185647.388895.92830@g44g2000cwa.googlegroups.com>
And finally, the sweet smell of victory:

(yacc:define-parser parser
  (:start-symbol sections)
  (:terminals (|;| :id1 :id2))

  (sections ()
	    sections-1)

  (sections-1 (sections-1 section |;|)
	      (section |;|))

  (section statement
	   declaration)

  (statement open-statement
	     closed-statement)

  (open-statement :id1)
  (closed-statement :id2)

  )
From: Matt
Subject: Re: Help with cl-yacc
Date: 
Message-ID: <SLwFf.11281$rH5.4083@newsread2.news.atl.earthlink.net>
I would do it like this:

> (yacc:define-parser parser
>   (:start-symbol sections)
>   (:terminals (|;| :id1 :id2))
> 
     (sections (sections section)
  	       section
                ())

     (section  statement |;|
               declaration |;|)
> 
>   (statement open-statement
> 	     closed-statement)
> 
>   (open-statement :id1)
>   (closed-statement :id2)
> 
>   )
> 
From: Matt
Subject: Re: Help with cl-yacc
Date: 
Message-ID: <7PwFf.11286$rH5.6847@newsread2.news.atl.earthlink.net>
Matt wrote:

>     (sections (sections section)
>             section
>                ())
> 
>     (section  statement |;|
>               declaration |;|)

Well, I guess that's a little different than what you were doing.
You want a semicolon after a section, but this puts it after
every statement and declaration.  Nevermind.

Matt