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

Re: [GNU-COBOL] GNU-COBOL list reborn



> Michael,
	...

> Here is an example:
> 
> move a to b (2 * c + d) (1:2).
> move a to b (2:3).
> .............^
> 
> At the point of the "^" there is an ambiguity whether you are
> looking at a reference modification or an array reference.
> 
> As far as I can tell, no finite amount of lookahead can get past
> this problem, just based on syntactic processing (of course there
> is the standard 'typedef' hack that can help with this (see the
> Bison manual for details) - but this gets ugly fast.	
> 
> Tim Josling
> 

As you suspected, Tim, it takes a little work to get this one to
parse, but nothing too onerous.  I had to look ahead two additional
tokens to see if we had a refmod without a subscript.  Failing that,
if we're still looking at an open paren, we must have a subscript,
which may still, optionally, be followed by a refmod.  Otherwise, we
have neither, and the null rule succeeds.  Parenthesized things
followed by question marks are syntactic predicates.  Pccts parses
these without affecting the current position in the token stream and
suppresses any actions that might be associated with the parse.  Both
terminals and non-terminals may be used.  Better than a lexer hack,
don't you think?

identifier
	: ident (qualifier)*
		( (OPAREN integer COLON)? refmod	
		| 	( (OPAREN)? subscripts { refmod }
			|
			)
		)
	;

ident   
	: PROG_NAME <<  CheckIdentLen(zzlextext);
			strcpy(Ident, zzlextext); >> 
	;

qualifier
	: ( OF | IN ) ident 
	;

subscripts
	: OPAREN (subscript)* CPAREN
	;

refmod
	: OPAREN integer COLON integer CPAREN
	;

subscript
	: (ident ( qualifier )* { (PLUS|MINUS) integer } | integer) 
	;




--
This message was sent through the gnu-cobol mailing list.  To remove yourself
from this mailing list, send a message to majordomo@lusars.net with the
words "unsubscribe gnu-cobol" in the message body.  For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@lusars.net.