[antlr-interest] RES: RES: COBOL grammar

Parsiad Azimzadeh parsiad.azimzadeh at gmail.com
Mon Jul 11 16:35:52 PDT 2011


That does not make much sense to me (however, I should state that I am too
unfamiliar with COBOL). For example, suppose you have program text of the
form:

procedure division .
id1 section .
id2 .
A .
B .

How do you know whether the '.' token after 'A' is meant to signify the end
of a command and not the end of a block?

Perhaps a better question would be, is there any semantic value to a block?
Can we remove the block rule altogether to yield:

grammar COBOL;

options
{
language = Java;
}

program
: 'procedure' 'division' END
section *
;

section
: ID 'section' END
paragraph *
;

paragraph
: ID END
( command END ? ) * END
;

// TODO: Put real commands here
command
: 'A'
| 'B'
;

fragment LETTER: 'a'..'z' | 'A'..'Z';
END: '.';
ID: LETTER ( LETTER | '0'..'9' | '-' )*;

The above grammar is unambiguous.

-- 
Parsiad Azimzadeh
http://sfu.ca/~paa4

On Mon, Jul 11, 2011 at 3:39 PM, Nilo Roberto C Paim <nilopaim at gmail.com>wrote:

> Hi, Ron.
>
> Glad to say that I'm the maintainer of TinyCobol.
>
> What I'm trying to do here is write a new version of it, using Antlr. In
> this new version, I want to implement a lot of things that does not exists
> today, like native GUI and native access to RDBMS in general. Also, I'm
> going to generate 'executables' for Java JVM and for .Net CIL. Current
> TinyCobol generates assembly code for 32 bits only, and I think this is a
> big limitation for it now.
>
> But let's go to the real problem...
>
> A command in Cobol may or may be not terminated by '.'. All sequence of
> commands terminated by only one '.' are a block. A sample of this are the
> commands in the 'then' or the 'else' part of an 'IF' command. In this case,
> the first '.' found on the end of some command terminates not only the
> command, but the 'IF' command as a whole.
>
> Additionally, a '.' must be the last token between paragraphs. Alias, the
> command sequence on a paragraph needs only the final '.', if I want.
>
> There is no way I could say if a '.' belongs to the preceding command or if
> it enclosing the current paragraph, except by the fact that, if the
> following token is a section name or a new paragraph, it quits the current
> paragraph; else it quits a block.
>
> Maybe I'm just missing the way to say that to Antlr. As I've already said,
> I'm a newbie.
>
> Thanks for interest and sorry the poor English. I'm Portuguese native
> speaker.
>
> Nilo - Brazil
>
> -----Mensagem original-----
> De: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] Em nome de Ron Burk
> Enviada em: segunda-feira, 11 de julho de 2011 19:24
> Cc: antlr-interest at antlr.org
> Assunto: Re: [antlr-interest] RES: COBOL grammar
>
> > What else am I missing?
>
> Are you certain you mean the '.' at the end of the command
> to be optional? An initial scan seems to indicate only one
> optional '.' in the tinyCobol grammar, in procedure declarations.
>
> Likewise, an uneducated glance at another COBOL grammar:
>    http://www.cs.vu.nl/grammarware/browsable/cobol/#EBNF
> seemed to indicate the "." is rarely optional.
>
> Or put another way, at the end of a command, what are
> the precise rules for deciding whether a '.' belongs to
> the current command or to the enclosing paragraph?
> If you can state an unambiguous rule for making that decision,
> you can probably force ANTLR to do it.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list