[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnubol: IS/ARE revisited
You had a brief discussion recently about lexing out IS as noise. I wanted to
add a note that might be worth considering as an alternative to all the ideas
discussed there.
Rildo Pragana of TINY COBOL fame, has generously posted much of early work on
a COBOL complier he put together in the early 90's. The portions quoted here
to not reflect their current work, but there is an interesting idea built
into the first attempts.
The lexer had a look up table for reserved words. Which is incidental, but he
actually globbed a number of things including IS and ARE under a single token
CONNECTIVE. You can see basically what this is all about by looking at some
of the snips below. The first portion of this
is from the lexer, which you can just kind of glance at. The grammer rules
some dealing with
required (req_) tokens, some with optional (opt_) are actually very
interesting.
The fact that he globbed all that with THAN and TO is pretty inspired. In a
way this is interesting just as a way to make the grammar tables tight (that
can actually be a performance enhancement, although here in gnubol that
concept is not known). For a number of these like TO vis-a-vis THRU, the
globbing would not be too likely to create ambiguities in the grammar (this
is just an accident of the interior occurence of the tokens in rules,
ambiguities tend to come on the outer edges of rules)
I know that your objective was to get rid of IS. So this technique is not
responsive to that. But the discussion led to optional/required and not
interchangable explanations. So some of the techniques here could relate to
simply globbing IS and ARE. And sometime having a subrule of req_are_not_is,
and that kind of thing.
His technique is definitely interesting.
/*
** Code Generator for Cobol Compiler
**
** by Rildo Pragana -- 1991
** P.O. Box 7440 - Recife PE Brazil 50000
**
** Revision history:
** 27-oct-91 Code implementation
**
*/
from SCAN.LEX
struct {
char *name;
int token;
unsigned minor;
} reserved_symbols[] = {
...
{"TO",CONNECTIVE,TO},
{"OF",CONNECTIVE,OF},
{"ON",CONNECTIVE,ON},
{"WHEN",CONNECTIVE,WHEN},
{"FOR",CONNECTIVE,FOR},
***
{"IS",CONNECTIVE,IS},
{"ARE",CONNECTIVE,ARE},
***
{"THROUGH",CONNECTIVE,THRU},
{"THRU",CONNECTIVE,THRU},
{"BY",CONNECTIVE,BY},
{"TO",CONNECTIVE,TO},
{"THAN",CONNECTIVE,THAN},
{"NO",CONNECTIVE,NO},
{"WITH",CONNECTIVE,WITH},
...
};
int reserved( char *s ) {
struct reserved_sym *r;
if ((r=lookup_reserved(s))!=NULL) {
yylval.ival=reserved_symbols[r->i].minor;
return reserved_symbols[r->i].token;
}
return 0;
}
from HTCOBOL.Y
...
%token <ival> CONNECTIVE
...
opt_is:
CONNECTIVE { if ($1!=IS) yyerror("IS expected"); }
| /* nothing */
;
opt_is_are:
/* nothing */
| CONNECTIVE { if ($1!=IS && $1!=ARE) {
yyerror("IS/ARE expected"); YYERROR; } }
;
opt_than_to:
/* nothing */
| CONNECTIVE { if ($1!=TO && $1!=THAN)
yyerror("THAN or TO expected");
}
;
opt_with:
/* nothing */
| CONNECTIVE { if ($1!=WITH) yyerror("WITH expected"); }
;
opt_to: /* nothing */
| CONNECTIVE { if ($1!=TO) yyerror("TO expected"); }
;
but also !!!!!
req_on: CONNECTIVE { if ($1!=ON) yyerror("ON required"); }
;
req_by: CONNECTIVE { if ($1!=BY) yyerror("BY required"); }
;
req_to: CONNECTIVE { if ($1!=TO) yyerror("TO required"); }
;
Then the usage of these might be
-----------------------------
use of req_to
statement:
MOVE { line_info(0); }
gname req_to { $<ival>$=MOVE; }
var_list
| ADD { line_info(0); }
gname req_to { $<ival>$=ADD; }
var_list
-----------------------------
use of opt_is_are
file_attrib:
/* nothing */
| file_attrib opt_is GLOBAL { $<sval>0->type = 'J'; }
| file_attrib opt_is EXTERNAL { $<sval>0->type = 'K'; }
| file_attrib LABEL rec_or_recs opt_is_are std_or_omitt
| file_attrib VALUE CONNECTIVE
FILE_NAME opt_is
literal { if ($3!=OF) yyerror("OF expected");
$<lval>$=$6; }
;
Please note that these are artifacts from earlier work. The tiny cobol
project has moved on to other approaches.
You can see that it would be easy to check a parm switch;
if (enforced_standard) {
/* check that IS IS IS and ARE IS ARE */
};
Hope that helps create more options for you.
Bob Rayhawk
--
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.