comp.lang.ada
 help / color / mirror / Atom feed
* Ada type (yacc)YYSTYPE is ?
@ 1999-01-16  0:00 tmoran
  1999-01-17  0:00 ` Steven Hovater
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: tmoran @ 1999-01-16  0:00 UTC (permalink / raw)


YACC is designed with a C 'union' type as a typeless, semantic
token information holder variable.  What's a good way in Ada to
handle that, hopefully with some help from Ada type checking?
One obvious one is a variant record.  Any better ideas?




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-16  0:00 Ada type (yacc)YYSTYPE is ? tmoran
@ 1999-01-17  0:00 ` Steven Hovater
  1999-01-18  0:00 ` Tucker Taft
  1999-01-18  0:00 ` dennison
  2 siblings, 0 replies; 11+ messages in thread
From: Steven Hovater @ 1999-01-17  0:00 UTC (permalink / raw)


Hi Tom

Do a web search for ayacc - there's an Ada version of yacc (and lex,
too, I think).
It's likely you'll find something useful therein.

Cheers,
Steve

tmoran@bix.com wrote:

> YACC is designed with a C 'union' type as a typeless, semantic
> token information holder variable.  What's a good way in Ada to
> handle that, hopefully with some help from Ada type checking?
> One obvious one is a variant record.  Any better ideas?

--
Steven
Hovater
svh@rational.com
Software Engineering
Consultant
Phone/fax:781-676-2565/2500
Rational
Software
Pager: 888-906-2209
83 Hartwell Ave, Lexington,
MA                                             Amateur radio: AA1YH






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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-16  0:00 Ada type (yacc)YYSTYPE is ? tmoran
  1999-01-17  0:00 ` Steven Hovater
  1999-01-18  0:00 ` Tucker Taft
@ 1999-01-18  0:00 ` dennison
  1999-01-18  0:00   ` Tom Moran
  2 siblings, 1 reply; 11+ messages in thread
From: dennison @ 1999-01-18  0:00 UTC (permalink / raw)


In article <77qu4d$jt8@lotho.delphi.com>,
  tmoran@bix.com wrote:
> YACC is designed with a C 'union' type as a typeless, semantic
> token information holder variable.  What's a good way in Ada to
> handle that, hopefully with some help from Ada type checking?
> One obvious one is a variant record.  Any better ideas?
>

What I did for my token analysis packages is I created an abstract tagged
"token" type. That way the tag acts as the variant, and you can put whatever
you want in the child types. Plus this allows you to define routines that
will work on all tokens, individual tokens, or subsets of individual tokens.

BTW, For those of you interested in this: I have no response yet on "opening"
the token packages from my boss here. The prognisis doesn't look good.
However, it looks like I will be working on making open-source lexical
analysis and parsing packages for Ada for my master's thesis. Assuming
everyone at UCF signs off, I'd be officially starting work on it after this
semester ends. My plan is to get a (mostly) working set of lexical analysis
packages publicly available by the middle of June. The parsing packages would
probably follow during the fall semester.


T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-16  0:00 Ada type (yacc)YYSTYPE is ? tmoran
  1999-01-17  0:00 ` Steven Hovater
@ 1999-01-18  0:00 ` Tucker Taft
  1999-01-18  0:00   ` Tom Moran
  1999-01-18  0:00 ` dennison
  2 siblings, 1 reply; 11+ messages in thread
From: Tucker Taft @ 1999-01-18  0:00 UTC (permalink / raw)


tmoran@bix.com wrote:

: YACC is designed with a C 'union' type as a typeless, semantic
: token information holder variable.  What's a good way in Ada to
: handle that, hopefully with some help from Ada type checking?
: One obvious one is a variant record.  Any better ideas?

A variant record (with a default for the discriminant) is certainly the 
most obvious choice.  

For Ada 95, an access type to a classwide type is another possible solution, 
using type extension to accommodate the various types to be stored on 
the parse stack.  However, the downside of a access-to-classwide is 
that you have to worry about storage reclamation, whereas the variant
record can be used directly as the component on the array used to 
implement the parse stack.  

A simple reclamation scheme for the access-to-classwide solution is
to have each type extension maintain its own free list, and a dispatching
operation to add an object back onto its free list when no longer
needed (you will probably want to add a "next" link into the root type 
of the class for linking onto the free list).

On the other hand, if the parse actions are building up an abstract
syntax tree anyway, then you would be allocating the AST nodes 
on the heap, and these might as well be your parse stack items.

--
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-18  0:00 ` dennison
@ 1999-01-18  0:00   ` Tom Moran
  1999-01-19  0:00     ` dennison
  0 siblings, 1 reply; 11+ messages in thread
From: Tom Moran @ 1999-01-18  0:00 UTC (permalink / raw)


>What I did for my token analysis packages is I created an abstract tagged
>"token" type. That way the tag acts as the variant, and you can put whatever
A BNF production like
  name : simple_name
might have an action like 
  {$$ := $1;}
which would translate into something like
  yyval := yy.value_stack(yy.tos);
where yyval is a YYStype and yy.value_stack is an array of YYStype.
Would you define
  type YYStype is Root_Token'Class;   ?
I don't quite understand just how you are using the tagged type.

   What I think I'd like is compile time, rather than execution time,
type checking.  Instead of a single YYStype I'd rather have different
ones for different tokens.  Thus for intance
  subtype name_YYSType is -- a bounded string
  subtype param_YYStype is -- some appropriate record structure
and
  name : simple_name
would do an assignment where the types are both name_YYStype while
  param : formal_name COLON type_name
would have code
  {$$ := make_param($1,$3);}
where
  function make_param(formal_name, type_name : name_YYStype) return
param_YYStype;
   name :  simple_name TIC attribute_name
might be coded simply as
  {$$ := $1 & "'" $ $3;}
since the type would be bounded string and "&" is available.
Has anyone done that?  Does it work in practice?
    




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-18  0:00 ` Tucker Taft
@ 1999-01-18  0:00   ` Tom Moran
  1999-01-19  0:00     ` Andrew W. Reynolds
  0 siblings, 1 reply; 11+ messages in thread
From: Tom Moran @ 1999-01-18  0:00 UTC (permalink / raw)


>On the other hand, if the parse actions are building up an abstract
>syntax tree anyway, then you would be allocating the AST nodes 
>on the heap, and these might as well be your parse stack items.
  I'm just trying to make a parser to generate skeletons for
documentation, so there's really nothing more complex than strings,
and being able to see that two procedures differ in their parameter
profiles, etc.  And it's intended for running, correct, code with
convenient coding conventions.
  Perhaps I should ask that: is there software about that will
generate skeleton HTML or Windows help files for a set of packages,
doing things like showing where two procedures with overloaded names
differ, and displaying inherited, non-overridden, primitive
operations, etc?




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-18  0:00   ` Tom Moran
@ 1999-01-19  0:00     ` Andrew W. Reynolds
  1999-01-19  0:00       ` Tom Moran
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew W. Reynolds @ 1999-01-19  0:00 UTC (permalink / raw)


tmoran@bix.com (Tom Moran) writes:

> >On the other hand, if the parse actions are building up an abstract
> >syntax tree anyway, then you would be allocating the AST nodes 
> >on the heap, and these might as well be your parse stack items.
>   I'm just trying to make a parser to generate skeletons for
> documentation, so there's really nothing more complex than strings,
> and being able to see that two procedures differ in their parameter
> profiles, etc.  And it's intended for running, correct, code with
> convenient coding conventions.
>   Perhaps I should ask that: is there software about that will
> generate skeleton HTML or Windows help files for a set of packages,
> doing things like showing where two procedures with overloaded names
> differ, and displaying inherited, non-overridden, primitive
> operations, etc?

Having you considering using aflex? This is an Ada implementation of
the flex lexical analyzer generator. It has a companion parser
generator ayacc. Here is the link to the non-commercial software list
at the home of the brave Ada programmer.

http://www.adahome.com/Resources/Tools/Non-Commercial.html

Hope this helps ;^)

Drew Reynolds




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-19  0:00     ` Andrew W. Reynolds
@ 1999-01-19  0:00       ` Tom Moran
  1999-01-19  0:00         ` rdt
  0 siblings, 1 reply; 11+ messages in thread
From: Tom Moran @ 1999-01-19  0:00 UTC (permalink / raw)


>Having you considering using aflex? This is an Ada implementation of
>the flex lexical analyzer generator. It has a companion parser
>generator ayacc.
  I'm using them.  But their docs just suggest "subtype yystype is
integer;" or variant records.




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-18  0:00   ` Tom Moran
@ 1999-01-19  0:00     ` dennison
  0 siblings, 0 replies; 11+ messages in thread
From: dennison @ 1999-01-19  0:00 UTC (permalink / raw)


In article <36a39cec.1456120@news.pacbell.net>,
  tmoran@bix.com (Tom Moran) wrote:
> >What I did for my token analysis packages is I created an abstract tagged
> >"token" type. That way the tag acts as the variant, and you can put whatever
> A BNF production like
>   name : simple_name
> might have an action like
>   {$$ := $1;}
> which would translate into something like
>   yyval := yy.value_stack(yy.tos);
> where yyval is a YYStype and yy.value_stack is an array of YYStype.
> Would you define
>   type YYStype is Root_Token'Class;   ?
> I don't quite understand just how you are using the tagged type.
>

Ahhh. I see have given a lex answer to what was really a yacc question (this
shouldn't have been a suprise to me given the Subject...)

The fact is I haven't taken it that far yet. My parsing needs when I
generated the token packages were so simple that it wouldn't have been worth
it to generate another set of packages to help with parsing (the "yacc"
side). My plan is eventually to do this for my master's work. I'm thinking
about using a set of constructions on token enumerations similar to what was
done for the Gnat Snobol packages to specify the rules, and taking in user
defined function pointers to specify the actions. But I suspect you would
prefer the voice of experience here rather than theories.

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-19  0:00       ` Tom Moran
@ 1999-01-19  0:00         ` rdt
  1999-01-19  0:00           ` Martin C. Carlisle
  0 siblings, 1 reply; 11+ messages in thread
From: rdt @ 1999-01-19  0:00 UTC (permalink / raw)


In article <36a43307.39889065@news.pacbell.net>,
  tmoran@bix.com (Tom Moran) wrote:
> >Having you considering using aflex? This is an Ada implementation of
> >the flex lexical analyzer generator. It has a companion parser
> >generator ayacc.
>   I'm using them.  But their docs just suggest "subtype yystype is
> integer;" or variant records.
>

I have used these tools and from what I can remember, you are free to use
whatever type you like.  If you are going to compile the resultant code with
and Ada95 compiler then I can see no reason why you can't use an Ada95
construct.

Regards
Richard Toy

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Ada type (yacc)YYSTYPE is ?
  1999-01-19  0:00         ` rdt
@ 1999-01-19  0:00           ` Martin C. Carlisle
  0 siblings, 0 replies; 11+ messages in thread
From: Martin C. Carlisle @ 1999-01-19  0:00 UTC (permalink / raw)


In article <7826ad$l3$1@nnrp1.dejanews.com>,  <rdt@liyorkrd.li.co.uk> wrote:
>In article <36a43307.39889065@news.pacbell.net>,
>  tmoran@bix.com (Tom Moran) wrote:
>> >Having you considering using aflex? This is an Ada implementation of
>> >the flex lexical analyzer generator. It has a companion parser
>> >generator ayacc.
>>   I'm using them.  But their docs just suggest "subtype yystype is
>> integer;" or variant records.
>
>I have used these tools and from what I can remember, you are free to use
>whatever type you like.  If you are going to compile the resultant code with
>and Ada95 compiler then I can see no reason why you can't use an Ada95
>construct.

I usually use "subtype YYSTYPE is access all Parseable'Class" -- you can do
some really neat OO style parsing this way.

--Martin

-- 
Martin C. Carlisle, Asst Prof of Computer Science, US Air Force Academy
mcc@cs.usafa.af.mil, http://www.usafa.af.mil/dfcs/bios/carlisle.html
DISCLAIMER:  This content in no way reflects the opinions, standards or 
policy of the US Air Force Academy or the United States Government.




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

end of thread, other threads:[~1999-01-19  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-16  0:00 Ada type (yacc)YYSTYPE is ? tmoran
1999-01-17  0:00 ` Steven Hovater
1999-01-18  0:00 ` Tucker Taft
1999-01-18  0:00   ` Tom Moran
1999-01-19  0:00     ` Andrew W. Reynolds
1999-01-19  0:00       ` Tom Moran
1999-01-19  0:00         ` rdt
1999-01-19  0:00           ` Martin C. Carlisle
1999-01-18  0:00 ` dennison
1999-01-18  0:00   ` Tom Moran
1999-01-19  0:00     ` dennison

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