[Top][All Lists]

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

Re: [open-cobol-list] New to the Compiler

From: Keisuke Nishida
Subject: Re: [open-cobol-list] New to the Compiler
Date: Thu Apr 21 13:10:47 2005
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Robert Sherry wrote:
     If I was writing the parser for a COBOL compiler I would use the power
of YACC to parse the expressions. I feel this approach is easiest to
implement (YACC does the work) and the grammar reflects the language being
parsed. Below is a YACC file that shows a simple expression parser for

Aha.  I get what you mean now.

The reason I wrote the expression parser like this was because
I was not able to figure out how to write it using yacc.

For example, consider the following expression:

  (X = 1 OR 2) OR < 3 OR Y = 4

This must be read as "(X = 1) OR (X = 2) OR (X < 3) OR (Y = 3)".
You need several look-ahead tokens to parse this expression,
and it is not straitforward to write it in yacc.

After spending a few days (or weeks) fighting with the COBOL
grammer, I finally realized that it is much easier to write
a custom parser for expressions.

I am not familier with all features of Bison, and there might
be a better way of writing an expression parser using Bison.
A patch is always welcome if you would like to rewrite the
current parser.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]