comp.lang.ada
 help / color / mirror / Atom feed
* question about the usage of opentoken-4.0b
@ 2012-04-24 19:01 Charly
  2012-04-25 12:03 ` Stephen Leake
  2012-04-25 12:58 ` Marc C
  0 siblings, 2 replies; 4+ messages in thread
From: Charly @ 2012-04-24 19:01 UTC (permalink / raw)


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 an 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.

Sincerely

Charly




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about the usage of opentoken-4.0b
  2012-04-24 19:01 question about the usage of opentoken-4.0b Charly
@ 2012-04-25 12:03 ` Stephen Leake
  2012-04-25 19:27   ` Charly
  2012-04-25 12:58 ` Marc C
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2012-04-25 12:03 UTC (permalink / raw)


Charly <carl.weierstrass@googlemail.com> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about the usage of opentoken-4.0b
  2012-04-24 19:01 question about the usage of opentoken-4.0b Charly
  2012-04-25 12:03 ` Stephen Leake
@ 2012-04-25 12:58 ` Marc C
  1 sibling, 0 replies; 4+ messages in thread
From: Marc C @ 2012-04-25 12:58 UTC (permalink / raw)


On Tuesday, April 24, 2012 2:01:18 PM UTC-5, Charly wrote:
> Hi,
> 
> I have a question about the usage of opentoken-4.0b, a scanner/parser-library written in Ada.

T.E.D, the original author of OpenToken, hangs out on StackOverflow, so you might post this question there. Tag it with 'ada' and it should show up in his RSS feed.

Marc A. Criley



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: question about the usage of opentoken-4.0b
  2012-04-25 12:03 ` Stephen Leake
@ 2012-04-25 19:27   ` Charly
  0 siblings, 0 replies; 4+ messages in thread
From: Charly @ 2012-04-25 19:27 UTC (permalink / raw)


Am Mittwoch, 25. April 2012 14:03:59 UTC+2 schrieb Stephen Leake:
> 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.
> 
Yes, thats right.

> 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'.
> 
Yes, right again. My working solution - that I don't like - stores it in the 
Program_Token package.

> 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.
> 
I could not find the answer in the docu. Of cource I could do all
processing in the final Program_Token.Create procedure, but I would
like to do it in the main program after the call of LALR_Parser.Parse(...),
something like
Result := LALR_Parser.Get_Result, 
that returns the Instance defined in Program_Token. This Instance contains
all the stuff collected while parsing the input file.

> 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.


My program consists of about 15 packages, so I will try do create a trivial
working example and post it again.

> 
> -- 
> -- Stephe

Thanks for your answer.

Charly




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-25 19:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-24 19:01 question about the usage of opentoken-4.0b Charly
2012-04-25 12:03 ` Stephen Leake
2012-04-25 19:27   ` Charly
2012-04-25 12:58 ` Marc C

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox