Re: Grammars for VB and PL-SQL

"Quinn Tyler Jackson" <qjackson@wave.home.com>
12 Jun 1999 21:06:47 -0400

          From comp.compilers

Related articles
Grammars for VB and PL-SQL gpeden3411@my-deja.com (1999-06-06)
Re: Grammars for VB and PL-SQL qjackson@wave.home.com (Quinn Tyler Jackson) (1999-06-12)
| List of all articles for this month |

From: "Quinn Tyler Jackson" <qjackson@wave.home.com>
Newsgroups: comp.compilers
Date: 12 Jun 1999 21:06:47 -0400
Organization: Compilers Central
References: 99-06-025
Keywords: parse, tools, Basic
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211

Graham Peden said:


> Also, I am thinking of using Sandstone's Visual Parse++. Has anybody
> got any opinions of this product that may be helpful.


VisualParse++ is a very powerful tool, and the benefits of visual
grammar development cannot be overstated, in my opinion. I have
nothing but praise for it as a productivity enhancing tool.


That said ... VB3 is probably a big and quirky enough language,
however, that the shallow parse that you want to do to do the cross
referencing may prove difficult to express formally. To give you an
idea of what I mean, here is a "simple" grammar I was working on a
while back for a C++ reformatter (that I may eventually get back to
working on one day) that attempts to do a retentive shallow parse of
comments... [It was pointed out to me by several of the experienced
parser people out there that parsing comments is better dealt with
with hacks that attach comment lexemes to other productions in parse,
rather than by dealing with them at the grammar level... but this
should give you an idea of how a formal grammar can get hard to follow
even when what we are trying to do at first seems fairly simple...]


So my comment about productivity enhancing tool apply mainly if what
you really want to do is a full, rather than shallow, parse of your
source.


// grammar begins


%expression main


        '.' %ignore;
        '\n' %ignore;


        '/\*' start_comment, '/*', %push in_comment;


        '[a-zA-Z_][a-zA-Z0-9_]*' id, 'ID';


        '[0-9]+' integer, 'INT';


        'begin' begin, 'begin';
        'end' end, 'end';
        'declare' declare, 'declare';
        'assign' assign, 'assign';
        'to' to, 'to';
        ';' semicolon, ';';


%expression in_comment


        '[^*]+' c_verbatim, '...';
        '\*' c_star;
        '\n' %ignore;
        '\*/' end_comment, '*/', %pop;


%production S


        S_1 S -> blocks;


        Bs_1 blocks -> block;
        Bs_2 blocks -> blocks ws block;


        B_1 block -> 'begin' ws statements ws 'end';


        STs_1 statements -> statements ws statement;
        STs_2 statements -> statement;


        ST_1 statement -> declaration;
        ST_2 statement -> assignment;
        ST_3 statement -> block;


        WS_0 ws -> ;
        WS_1 ws -> comment_block;


        CB_1 comment_block -> '/*' comment_lines '*/';


        CBd_0 comment_lines -> ;
        CBd_1 comment_lines -> comment_lines comment_atom;


        CL_1 comment_atom -> '...';
        CL_2 comment_atom -> c_star;


        D_1 declaration -> 'declare' ws 'ID' ws ';';


        A_1 assignment -> 'assign' ws 'INT' ws 'to' ws 'ID' ws ';';
        A_2 assignment -> 'assign' ws 'ID' ws 'to' ws 'ID' ws ';';


// grammar ends


--
Quinn Tyler Jackson
http://www.qtj.net/~quinn/


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.