[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Language with multiple statements on one line



On Wed, Jan 07, 2004 at 12:27:07PM -0500, Patrick LAM wrote:
> On Wed, 7 Jan 2004 paul-rene.jorgensen@telenor.com wrote:
> 
> > ### BEGIN
> > <nl>
> > A=4 : B=5<nl>
> > <nl>
> > <nl>
> > A=A+B<nl>
> > <nl>
> > B=1 : C=1<nl>
> > <nl>
> > ### END
> 
> I think that there are probably many ways to do this; one way you could do
> this is with:
> 
> file = nl* line* statement_list? // to take care of files without trailing CRs
> 
> line = statement_list nl+
> 
> statement_list = {single} statement
>                | {multi} statement colon+ statement_list
> 
> Tell me if that works.

After a little thought, I'd do the following, to allow lines containing only
colons, leading colons and trailing colons.

       file = [new_lines]:new_line* [lines]:line* statement_list?;

       line = statement_list [new_lines]:new_line+;
       	
       statement_list = { empty }     [colons]:colon+
       	   	     | { non_empty } [colons]:colon*
	       		       	     [statements]:leading_statement*
			   	     [statement]:trailing_statement
		     ;
		
       leading_statement  = statement [colons]:colon+;
       trailing_statement = statement [colons]:colon*;

A depth first adapter will still only need a method implemented for each
type of statement. I've found the leading/trailing idom very handy for this
purpose in the past, especially when you want a grammar to be able to right
branch recursively on the last item in a list.

-- 
Jon Shapcott <eden@xibalba.demon.co.uk>
"This is the Space Age, and we are Here To Go" - Wlliam S. Burroughs