1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
-------------------------------------------------------------------------------
--
-- Copyright (C) 1999 Ted Dennison
--
-- This file is part of the OpenToken package.
--
-- The OpenToken package is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as published
-- by the Free Software Foundation; either version 2, or (at your option)
-- any later version. The OpenToken package is distributed in the hope that
-- it will be useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details. You should have received
-- a copy of the GNU General Public License distributed with the OpenToken
-- package; see file GPL.txt. If not, write to the Free Software Foundation,
-- 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--
-- As a special exception, if other files instantiate generics from this
-- unit, or you link this unit with other files to produce an executable,
-- this unit does not by itself cause the resulting executable to be
-- covered by the GNU General Public License. This exception does not
-- however invalidate any other reasons why the executable file might be
-- covered by the GNU Public License.
--
-- Maintainer: Ted Dennison (dennison@telepath.com)
--
-- Update History:
-- $Log: simple_integer_token.ads,v $
-- Revision 1.2 2000/08/07 00:10:49 Ted
-- Change to work w/ new package hierarchy
--
-- Revision 1.1 2000/01/27 21:05:01 Ted
-- An implementation of a simple nonterminal interger token.
--
-- Revision 1.1 1999/12/27 21:30:44 Ted
-- Initial Version
--
--
-------------------------------------------------------------------------------
with OpenToken.Recognizer;
with OpenToken.Token.Enumerated;
with OpenToken.Token.Enumerated.Nonterminal;
with OpenToken.Token.Enumerated.Integer_Literal;
with OpenToken.Token.Enumerated.List;
-------------------------------------------------------------------------------
-- This package declares a type for designating an integer literal.
-------------------------------------------------------------------------------
generic
with package Token is new OpenToken.Token.Enumerated(<>);
with package Token_List is new Token.List;
with package Nonterminal is new Token.Nonterminal (Token_List);
with package Integer_Literal is new Token.Integer_Literal;
package Simple_Integer_Token is
type Instance is new Nonterminal.Instance with private;
subtype Class is Instance'Class;
type Handle is access all Class;
----------------------------------------------------------------------------
-- Get an integer literal token with the given ID and value.
----------------------------------------------------------------------------
function Get (ID : in Token.Token_ID;
Value : in Integer := 0
) return Instance'Class;
----------------------------------------------------------------------------
-- Return the value of the given integer token.
----------------------------------------------------------------------------
function Value (Subject : in Instance) return Integer;
----------------------------------------------------------------------------
-- Overriding of the default copy synthesization rouine. This routine
-- accepts all token lists whose first element is in Instance'Class, or in
-- Integer_Literal.Instance'Class.
----------------------------------------------------------------------------
procedure Synthesize_By_Copying (New_Token : out Instance;
Source : in Token.Instance'Class;
To_ID : in Token.Token_ID);
----------------------------------------------------------------------------
-- Routines to synthesize tokens by performing integer ops on the list they
-- reduce from.
--
-- They are valid for any token list whose first and third members are in
-- Instance'Class.
----------------------------------------------------------------------------
Add_Integers : constant Nonterminal.Synthesize;
Multiply_Integers : constant Nonterminal.Synthesize;
----------------------------------------------------------------------------
-- Routine to synthesize a simple integer token from the second token on the
-- production's right hand side.
----------------------------------------------------------------------------
Synthesize_Second : constant Nonterminal.Synthesize;
private
type Instance is new Nonterminal.Instance with record
Value : Integer;
end record;
----------------------------------------------------------------------------
-- Implementations of routines to synthesize tokens by performing integer
-- ops on the list they reduce from.
--
-- They are valid for any token list whose first and third members are in
-- Instance'Class.
----------------------------------------------------------------------------
procedure Synthesize_Add (New_Token : out Nonterminal.Class;
Source : in Token_List.Instance'Class;
To_ID : in Token.Token_ID);
procedure Synthesize_Multiply (New_Token : out Nonterminal.Class;
Source : in Token_List.Instance'Class;
To_ID : in Token.Token_ID);
----------------------------------------------------------------------------
-- Routine to synthesize a simple integer token from the second token on the
-- production's right hand side.
----------------------------------------------------------------------------
procedure Synthesize_From_Second_Argument (New_Token : out Nonterminal.Class;
Source : in Token_List.Instance'Class;
To_ID : in Token.Token_ID);
Add_Integers : constant Nonterminal.Synthesize := Synthesize_Add'Access;
Multiply_Integers : constant Nonterminal.Synthesize := Synthesize_Multiply'Access;
Synthesize_Second : constant Nonterminal.Synthesize := Synthesize_From_Second_Argument'Access;
end Simple_Integer_Token;
|