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

Re: gnubol: Re: Magic tokens



>>>>> "Tim" == Tim Josling <TIMJOSLING@prodigy.net>
>>>>> wrote the following on Sun, 05 Dec 1999 10:46:48 +1000

      <snip>

  Tim> The correct parsing for the following statement is IMO as
  Tim> follows:

add a to b
     size error
           add c to d << ERROR illega; nested conditional statement
                not size error
                      display "assert(0)"
.
  Tim> Now if I just define add something like this:

  Tim> add: stuff a_size_error ;

a_size_error:
size error imperatives
|not size error imperatives
| size error imperatives not size error imperatives
| not size error imperatives size error imperatives
;

  Tim> It will happily parse the test case above as: 

add a to b
     size error
           add c to d
     not size error
           display "assert(0)"
.

  Tim> is wrong IMO and difficult to fix.

  Tim> So I am parsing the nested conditionals and then flagging them
  Tim> YYERRORs. OK so on this train of logic, I need to parse nested
  Tim> conditionals.

Tim, I don't know if this translates to bison very well, but I am
thinking along these lines.  

add_imperative
	: add_common { size_err end_add | end_add }
	;
add_stmt
	: add_common { size_err } { end_add }
	;
add_common
	: ADD 
	  ( CORR identifier TO identifier { ROUNDED }
	  |  ( identifier | NUMERIC_LITERAL )+
	     ( giving_phrase   	
	     ! TO ( identifier | NUMERIC_LITERAL ) giving_phrase
	     | TO ( identifier { ROUNDED } )+
	     )
	  )
	;

A greedy parser will grab the size error for the appropriate verb.
(You'll remember that {} means optional.)




--
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.