From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,fae38b9316611100 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.230 with SMTP id sd6mr2535239pbc.8.1335355390884; Wed, 25 Apr 2012 05:03:10 -0700 (PDT) Path: r9ni96752pbh.0!nntp.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: question about the usage of opentoken-4.0b References: <10328658.73.1335294078629.JavaMail.geo-discussion-forums@vber6> Date: Wed, 25 Apr 2012 08:03:59 -0400 Message-ID: <82r4vcf26o.fsf@stephe-leake.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (windows-nt) Cancel-Lock: sha1:YSdj++VVo72j2oKA53mQX4fFsCQ= MIME-Version: 1.0 X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: b099b4f97e7fee029e66132333 X-Received-Bytes: 2977 Content-Type: text/plain; charset=us-ascii Date: 2012-04-25T08:03:59-04:00 List-Id: Charly writes: > Hi, > > I have a question about the usage of opentoken-4.0b, a scanner/parser-library written in Ada. > So my question isn't about the language Ada itself but only about this library. > > I define a Grammar starting with > > Grammar : constant Production_List.Instance := > Prog <= Def_List & EOF + Program_Token.Create and > Def_List <= Def_List & Ent + Element_List.Concat and > Def_List <= Ent + Element_List.Create and > Ent <= Entity_Key & Ident & Colon & El_List & End_Key & > Semicolon + Entity_Token.Create and > ... > > and I create and call the parser with > > Text_Parser := LALR_Parser.Generate (Grammar, Analyzer, False); > > LALR_Parser.Parse (Text_Parser); > > It works fine, but to use the result of the parsing, which happens to > be the start element 'Prog' of the above Grammar, I had to store it in > a global variable, as one of the actions of the procedure > 'Program_Token.Create'. But I would like to avoid this, because I > don't like global variables; > > The variable 'Prog' in the Grammar definition has the right type, but > does not contain any data, as I expected. > > Any help would be appreciated. I think I understand; you want the side-effect output of Program_Token.Create for Prog to be stored in some non-global variable. I'll assume that by 'global' here you mean 'declared in some package, and thus allocated statically' as opposed to 'declared in some subroutine, and thus allocated dynamically'. You want dynamic allocation (either stack or heap, but with the heap root reference on the stack) for the side-effect output. I've never tried to do that; I always have a few root global variables in my most complex code (_something_ has to store the symbol table :), so it has not come up. The examples in OpenToken essentially do all processing inside the various action subroutines, so they don't help here. If you could post a small compilable example, I'd be able to think about it more concretely. You might get somewhere with access discriminants, but I don't see how immediately. -- -- Stephe