comp.lang.ada
 help / color / mirror / Atom feed
* Ada95 Ayacc / Aflex specifications
@ 1999-09-06  0:00 mark_doherty
  1999-09-07  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mark_doherty @ 1999-09-06  0:00 UTC (permalink / raw)


I am looking for the source specifications for ayacc / aflex for Ada95.

I want these so that I can extract the ayacc / aflex specification
associated with a calculator (i.e expression. basics functions of +,
-,*, /, () , power, unarray + and - for both integer and floating point
arithmatic).

An example of a calculator would be great.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Ada95 Ayacc / Aflex specifications
  1999-09-06  0:00 Ada95 Ayacc / Aflex specifications mark_doherty
  1999-09-07  0:00 ` Ted Dennison
@ 1999-09-07  0:00 ` Shawn Barber
  1999-09-08  0:00 ` cts
  2 siblings, 0 replies; 4+ messages in thread
From: Shawn Barber @ 1999-09-07  0:00 UTC (permalink / raw)


Here is some math support I wrote for a compiler we wrote, 
it only supports Add, Subtract, Multiply and Divide but 
might provide you with a basis for your work.

Ayacc spec file.

   
------------------------------------------------------------
------
   -- Simple Math Processing 
----------------------------------------
   
------------------------------------------------------------
------
   
Numeric_Expression : Term
                     {
                       if $1.Value_Type = Integer_Type then
                       
                          $$.Int_Value   := $1.Int_Value   ;
                          $$.Value_Type  := Integer_Type   ;
                       
                       elsif $1.Value_Type = Float_Type then
                          
                          $$.Float_Value := $1.Float_Value ;
                          $$.Value_Type  := Float_Type     ;
                       
                       end if ;
                     }
                   | Numeric_Expression '+' Term
                     {
                       if $1.Value_Type = Integer_Type
                          and $3.Value_Type = Integer_Type 
then
                          
                          $$.Int_Value   := $1.Int_Value + 
$3.Int_Value     ;
                          $$.Value_Type  := Integer_Type                    
;
                       
                       elsif $1.Value_Type = Float_Type
                          and $3.Value_Type = Float_Type 
then
                          
                          $$.Float_Value := $1.Float_Value + 
$3.Float_Value ;
                          $$.Value_Type  := Float_Type                      
;
                       
                       else
                          
                          raise Type_Mismatch_Error ;
                       
                       end if ;
                     }
                   | Numeric_Expression '-' Term
                     {
                       if $1.Value_Type = Integer_Type
                          and $3.Value_Type = Integer_Type 
then
                       
                          $$.Int_Value   := $1.Int_Value - 
$3.Int_Value     ;
                          $$.Value_Type  := Integer_Type                    
;
                       
                       elsif $1.Value_Type = Float_Type
                          and $3.Value_Type = Float_Type 
then
                          
                          $$.Float_Value := $1.Float_Value - 
$3.Float_Value ;
                          $$.Value_Type  := Float_Type                      
;
                       
                       else
                          
                          raise Type_Mismatch_Error ;
                       
                       end if ;
                     }
                   ;
        
Term               : Factor
                     {
                       if $1.Value_Type = Integer_Type then
                       
                          $$.Int_Value   := $1.Int_Value   ;
                          $$.Value_Type  := Integer_Type   ;
                       
                       elsif $1.Value_Type = Float_Type then
                       
                          $$.Float_Value := $1.Float_Value ;
                          $$.Value_Type  := Float_Type     ;
                          
                       end if ;
                     }
                   | Term '*' Factor
                     {
                       if $1.Value_Type = Integer_Type
                          and $3.Value_Type = Integer_Type 
then
                       
                          $$.Int_Value   := $1.Int_Value * 
$3.Int_Value     ;
                          $$.Value_Type  := Integer_Type                    
;
                          
                       elsif $1.Value_Type = Float_Type
                          and $3.Value_Type = Float_Type 
then
                       
                          $$.Float_Value := $1.Float_Value * 
$3.Float_Value ;
                          $$.Value_Type  := Float_Type                      
;
                       
                       else
                          
                          raise Type_Mismatch_Error ;
                       
                       end if ;
                     }
                   | Term '/' Factor
                     {
                       if $1.Value_Type = Integer_Type
                          and $3.Value_Type = Integer_Type 
then
                          
                          $$.Int_Value   := $1.Int_Value / 
$3.Int_Value     ;
                          $$.Value_Type  := Integer_Type                    
;
                          
                       elsif $1.Value_Type = Float_Type
                          and $3.Value_Type = Float_Type 
then
                          
                          $$.Float_Value := $1.Float_Value / 
$3.Float_Value ;
                          $$.Value_Type  := Float_Type                      
;
                       
                       else
                          
                          raise Type_Mismatch_Error ;
                       
                       end if ;
                     }
                   ;
         
Factor             : INTEGER_LITERAL
                     {
                       $$.Int_Value  := YYInt_Value   ;
                       $$.Value_Type := Integer_Type  ;
                     }
                   | FLOAT_LITERAL
                     {
                       $$.Float_Value := YYFloat_Value ;
                       $$.Value_Type  := Float_Type    ;
                     }
                   | IDENTIFIER
                     { Get_Constant_Value_and_Type
                        ( Identifier => YYIdentifier )                
;
                       
                       if YY_Const_Val.Value_Type = 
Integer_Type then
                       
                          $$.Int_Value   := 
YY_Const_Val.Int_Value    ;
                          $$.Value_Type  := Integer_Type              
;
                       
                       elsif YY_Const_Val.Value_Type = 
Float_Type then
                       
                          $$.Float_Value := 
YY_Const_Val.Float_Value  ;
                          $$.Value_Type  := Float_Type                
;
                       
                       end if ;
                     }
                   | '-'IDENTIFIER
                     { Get_Constant_Value_and_Type
                        ( Identifier => YYIdentifier )                
;
                       
                       if YY_Const_Val.Value_Type = 
Integer_Type then
                       
                          $$.Int_Value   := 
YY_Const_Val.Int_Value    ;
                          $$.Value_Type  := Integer_Type              
;
                       
                       elsif YY_Const_Val.Value_Type = 
Float_Type then
                       
                          $$.Float_Value := 
YY_Const_Val.Float_Value  ;
                          $$.Value_Type  := Float_Type                
;
                       
                       end if ;
                     }
                   | '(' Numeric_Expression ')'
                     {
                       if $2.Value_Type = Integer_Type then
                       
                          $$.Int_Value   := $2.Int_Value   ;
                          $$.Value_Type  := Integer_Type   ;
                       
                       elsif $2.Value_Type = Float_Type then
                          
                          $$.Float_Value := $2.Float_Value ;
                          $$.Value_Type  := Float_Type     ;
                       
                       end if ;
                     }
                   ;

and the Aflex spec file.
   -- Math Operators
"+"                               { return '+' ;
                                  }

"-"                               { return '-' ;
                                  }

"/"                               { return '/' ;
                                  }

"*"                               { return '*' ;
                                  }

"("                               { return '(' ;
                                  }

")"                               { return ')' ;
                                  }

Note that the reference to $$ is a record type with two 
fields, Float_Value and Integer_Value. In my usage of this I 
needed to separate Float and Integer which led to the 
semantic checking I used. You may not need or want this. 
Hope this helps.

Shawn

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!





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

* Re: Ada95 Ayacc / Aflex specifications
  1999-09-06  0:00 Ada95 Ayacc / Aflex specifications mark_doherty
@ 1999-09-07  0:00 ` Ted Dennison
  1999-09-07  0:00 ` Shawn Barber
  1999-09-08  0:00 ` cts
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 1999-09-07  0:00 UTC (permalink / raw)


In article <7r0gob$m31$1@nnrp1.deja.com>,
  mark_doherty@my-deja.com wrote:
> I am looking for the source specifications for ayacc / aflex for
Ada95.
>
> I want these so that I can extract the ayacc / aflex specification
> associated with a calculator (i.e expression. basics functions of +,
> -,*, /, () , power, unarray + and - for both integer and floating
point
> arithmatic).
>
> An example of a calculator would be great.

Hmmm. This sounds suspiciously like a homework assignment....

I believe ayacc and aflex are written to accept yacc and lex source
files. That would mean what you are looking for has nothing to do with
ayacc and aflex themselves (and nothing to do with Ada, for that
matter).

If you have a copy of the "Dragon Book", I'd be suprised if it didn't
have something very much like what you are asking for. I know there are
calculator examples in the O'Reilly "nutshell" lex & yacc book.

But if this is for a homework assignment, I highly suggest you follow
the exercise as intended rather than blindly copy source files someone
else wrote. It'd be a shame to spend all that money and time on the
course and not learn anything.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Ada95 Ayacc / Aflex specifications
  1999-09-06  0:00 Ada95 Ayacc / Aflex specifications mark_doherty
  1999-09-07  0:00 ` Ted Dennison
  1999-09-07  0:00 ` Shawn Barber
@ 1999-09-08  0:00 ` cts
  2 siblings, 0 replies; 4+ messages in thread
From: cts @ 1999-09-08  0:00 UTC (permalink / raw)



Is anyone still working on Ayacc/Aflex?  The copy I have is pre-Ada95.
Using subpackages and Ada.Streams would a nice addition to those 
tools.

(Hint-  Senior project for someone?)




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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-06  0:00 Ada95 Ayacc / Aflex specifications mark_doherty
1999-09-07  0:00 ` Ted Dennison
1999-09-07  0:00 ` Shawn Barber
1999-09-08  0:00 ` cts

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