Google
 

Trailing-Edge - PDP-10 Archives - BB-JF18A-BM - sources/diu/diutok.bli
There are 4 other files named diutok.bli in the archive. Click here to see a list.
MODULE DIUTOK (ident = '253'
	%require ('DIUPATSWITCH')
		) =
BEGIN

!	COPYRIGHT (C) DIGITAL EQUIPMENT CORPORATION 1986.
!	ALL RIGHTS RESERVED.
!
!	THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY  BE  USED  AND
!	COPIED ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH
!	THE INCLUSION OF THE ABOVE COPYRIGHT NOTICE.   THIS  SOFTWARE  OR
!	ANY  OTHER  COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE
!	AVAILABLE TO ANY OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE
!	SOFTWARE IS HEREBY TRANSFERRED.
!
!	THE INFORMATION IN THIS SOFTWARE IS  SUBJECT  TO  CHANGE  WITHOUT
!	NOTICE  AND  SHOULD  NOT  BE CONSTRUED AS A COMMITMENT BY DIGITAL
!	EQUIPMENT CORPORATION.
!
!	DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF
!	ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY DIGITAL.
!
!++
! FACILITY:	PAT parser
!
! ABSTRACT:
!
!	PATTOKEN.BLI.  Routines and data structures to manage
!	the lexical token buffer.
!
!	This file is language independent.
!
! ENVIRONMENT:
!
! AUTHOR:  C. Mitchell, CREATION DATE:  9-Nov-1981
!
! MODIFIED BY:
! 002 - Remove VMS dependencies.  C. Richardson  29-May-84
!
!  253  Rename file to DIUTOK.
!       Gregory A. Scott 1-Jul-86
!
!--

!
! INCLUDE FILES:
!

require 'DIUPATPROLOG';

library 'BLI:XPORT';

library 'DIUPATTOKEN';

library 'DIUPATLANGSP';

library 'DIUDEB';
! TABLE OF CONTENTS FOR INTERNAL ROUTINES:
!
!	NONE
!
!
! MACROS:
!
!
! EQUATED SYMBOLS:
!

literal
    MAX_BUFFERED_TOKENS = 12,
    MAX_SAVED_BUF = 2;

!
! OWN STORAGE:
!

own
    SAVED_BUFFER : vector [MAX_SAVED_BUF*%upval],
    TOKEN_BUFFER : vector [MAX_BUFFERED_TOKENS*%upval],
    PAT$TOKEN_BUF_TEMP_HEAD;

global
    PAT$TOKEN_BUF_LOW,
    PAT$TOKEN_BUF_HIGH,
    PAT$TOKEN_BUF_HEAD,
    PAT$TOKEN_BUF_TAIL,
    PAT$TOKEN_CURRENT_PTR;
global routine PAT$TOKEN_INIT_BUFFER : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	This routine initializes the token buffer and should
!	be called at the start of a parse.
!
! FORMAL PARAMETERS:
!
!	None.
!
! IMPLICIT INPUTS:
!
!	None.
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_BUF_LOW	Set to point to TOKEN_BUFFER
!	PAT$TOKEN_BUF_HIGH	Set to point to end of TOKEN_BUFFER
!	PAT$TOKEN_BUF_HEAD	Set to point to TOKEN_BUFFER
!	PAT$TOKEN_BUF_TAIL	Set to point to TOKEN_BUFFER
!	PAT$TOKEN_BUF_TEMP_HEAD	Set to point to TOKEN_BUFFER
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin
    PAT$TOKEN_BUF_LOW = TOKEN_BUFFER;
    PAT$TOKEN_BUF_HIGH = TOKEN_BUFFER + (MAX_BUFFERED_TOKENS - 1)*%upval;
    PAT$TOKEN_BUF_HEAD = TOKEN_BUFFER;
    PAT$TOKEN_BUF_TAIL = TOKEN_BUFFER;
    PAT$TOKEN_BUF_TEMP_HEAD = TOKEN_BUFFER;
    end;
global routine PAT$TOKEN_GET (CONSUME) =

!++
! FUNCTIONAL DESCRIPTION:
!
!	This routine gets the next token either by taking it from the
!	list of tokens which have been read but not consumed or, if
!	there are none, by calling the lexical analyzer.
!	A pointer to the then new token is assigned to PAT$TOKEN_CURRENT_PTR.
!
!	Macro PAT$TOKEN_GET_CONSUME is equivalent to PAT$TOKEN_GET (TRUE).
!
! FORMAL PARAMETERS:
!
!	CONSUME		If TRUE, then tokens are consumed; if FALSE
!			then they are saved for future use.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!	PAT$TOKEN_BUF_TAIL
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_CURRENT_PTR
!	PAT$TOKEN_BUF_TAIL
!	PAT$TOKEN_BUF_TEMP_HEAD
!
! ROUTINE VALUE:
!
!	Returns the value of the terminal symbol referred to by
!	PAT$TOKEN_CURRENT_PTR.
!
! SIDE EFFECTS:
!
!	None.
!
!--
    begin

    if .CONSUME
    then 					! Consume tokens
	PAT$TOKEN_GET_CONSUME
    else 					! Don't consume tokens
	if (.PAT$TOKEN_BUF_TEMP_HEAD eql .PAT$TOKEN_BUF_TAIL)
	then 					! End of buffer
	    begin
	    PAT$TOKEN_CURRENT_PTR = LS_GET_LEX_TOKEN;
	    PAT$TOKEN_ADVANCE (PAT$TOKEN_BUF_TAIL);
	    .PAT$TOKEN_BUF_TEMP_HEAD = .PAT$TOKEN_CURRENT_PTR;
	    PAT$TOKEN_ADVANCE (PAT$TOKEN_BUF_TEMP_HEAD);
	    end
	else 					! Unread tokens in buffer
	    begin
	    PAT$TOKEN_CURRENT_PTR = ..PAT$TOKEN_BUF_TEMP_HEAD;
	    PAT$TOKEN_ADVANCE (PAT$TOKEN_BUF_TEMP_HEAD);
	    end;

    return LS_LEX_TERM (PAT$TOKEN_CURRENT_PTR)
    end;					! Of routine PAT$TOKEN_GET
global routine PAT$TOKEN_SAVE (TOKEN_PTR, PERMANENT) : novalue =

!++
! FUNCTIONAL DESCRIPTION:
!
!	This routine saves TOKEN_PTR in the token buffer so that it
!	will be the next one returned by PAT$TOKEN_GET.  If PERMANENT
!	is FALSE, this change will only affect the current error
!	recovery attempt.
!
!	Macro PAT$TOKEN_SAVE_PERMANENT (TOKEN_PTR) is equivalent to
!	PAT$TOKEN_SAVE (PERMANENT).
!
! FORMAL PARAMETERS:
!
!	TOKEN_PTR	Token to be saved.
!	PERMANENT	TRUE if definite correction,
!			FALSE if temporary change for trial correction.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_TEMP_BUF_HEAD
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_TEMP_BUF_HEAD
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin

    if .PERMANENT
    then
	PAT$TOKEN_SAVE_PERMANENT (.TOKEN_PTR)
    else
	begin
	PAT$TOKEN_BACKUP (PAT$TOKEN_BUF_TEMP_HEAD);
	.PAT$TOKEN_BUF_TEMP_HEAD = .TOKEN_PTR;
	end;

    end;					! Of routine PAT$TOKEN_SAVE
global routine PAT$TOKEN_SAVE_BUF (SAVE_UPTO) =

!++
! FUNCTIONAL DESCRIPTION:
!
!	Save the first SAVE_UPTO tokens (or all if there are not that many)
!	from the token buffer into temporary storage so that they can be
!	restored even if they are clobbered by the error recovery routines.
!	The token can be restored by calling PAT$TOKEN_RESTORE_BUF.
!
! FORMAL PARAMETERS:
!
!	SAVE_UPTO	- Maximum number of tokens which must be saved.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!	PAT$TOKEN_BUF_TAIL
!	PAT$TOKEN_CURRENT_PTR
!
! IMPLICIT OUTPUTS:
!
!	None.
!
! ROUTINE VALUE:
!
!	NUM_SAVED, the number of tokens actually saved in SAVE_BUFFER
!
! SIDE EFFECTS:
!
!	None.
!!--

    begin

    local
	NUM_SAVED;

    DEB_ASSERT ((.SAVE_UPTO leq MAX_SAVED_BUF), 'SAVED_BUFFER overflowed');
    NUM_SAVED = 0;
    PAT$TOKEN_RESET_BUFFER ();

    while (.PAT$TOKEN_BUF_TEMP_HEAD neq .PAT$TOKEN_BUF_TAIL) and
	(.NUM_SAVED lss .SAVE_UPTO) do
	begin
	PAT$TOKEN_GET (FALSE);
	SAVED_BUFFER [.NUM_SAVED*%upval] = .PAT$TOKEN_CURRENT_PTR;
	NUM_SAVED = .NUM_SAVED + 1;
	end;

    PAT$TOKEN_RESET_BUFFER ();
    return .NUM_SAVED
    end;					! End of PAT$TOKEN_SAVE_BUF
global routine PAT$TOKEN_RESTORE_BUF (NUM_TOKENS) : novalue =

!++
! FUNCTIONAL DESCRIPTION:
!
!	Restore the token buffer to the state it was in before being saved
!	by call to PAT$TOKEN_SAVE_BUF.
!
! FORMAL PARAMETERS:
!
!	NUM_TOKENS	The number of tokens which were actually saved,
!			thus the number which must be restored.
!			This was returned by the prior call to
!			PAT$TOKEN_SAVE_BUF.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_HEAD
!
! IMPLICIT OUTPUTS:
!
!	None.
!
! ROUTINE VALUE:
!
!	NONE
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin

    incr INDEX1 from 0 to (.NUM_TOKENS - 1) do
	PAT$TOKEN_ADVANCE (PAT$TOKEN_BUF_HEAD);

    decr INDEX2 from (.NUM_TOKENS - 1) to 0 do
	PAT$TOKEN_SAVE (.SAVED_BUFFER [.INDEX2*%upval], TRUE);

    PAT$TOKEN_RESET_BUFFER ();
    end;					! End of PAT$TOKEN_RESTORE_BUF
global routine PAT$TOKEN_RESET_BUFFER : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	Resets PAT$TOKEN_BUF_TEMP_HEAD to PAT$TOKEN_BUF_HEAD.
!	This undoes the effect of non-consumed gets (via calls to
!	PAT$TOKEN_GET) and non-permanent saves (via calls to
!	PAT$TOKEN_SAVE) since the last consumed get or permanent save.
!
! FORMAL PARAMETERS:
!
!	None.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_HEAD
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin
    PAT$TOKEN_BUF_TEMP_HEAD = .PAT$TOKEN_BUF_HEAD;
    end;
global routine PAT$TOKEN_TEMP_HEAD =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	Returns PAT$TOKEN_BUF_TEMP_HEAD.
!	Routines PAT$TOKEN_TEMP_HEAD and PAT$TOKEN_SET_TEMP_HEAD
!	are used to save and restore the pointer to the "first"
!	token in the temporary token buffer.
!
!	Example of use:
!
!	begin
!	    local SAVED_TEMP_HEAD;
!	    SAVED_TEMP_HEAD = PAT$TOKEN_TEMP_HEAD ();
!	    ...
!	    PAT$TOKEN_SET_TEMP_HEAD (.SAVED_TEMP_HEAD)
!
!	PAT$TOKEN_SET_HEADER can be used to modify the actual buffer.
!
! FORMAL PARAMETERS:
!
!	None.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!
! IMPLICIT OUTPUTS:
!
!	None.
!
! ROUTINE VALUE:
!
!	Returns the contents of PAT$TOKEN_BUF_TEMP_HEAD,
!	the first token in the temporary token buffer.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin
    return .PAT$TOKEN_BUF_TEMP_HEAD
    end;
global routine PAT$TOKEN_SET_TEMP_HEAD (TEMP_HEAD) : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	Sets PAT$TOKEN_BUF_TEMP_HEAD to the required value.
!	See PAT$TOKEN_TEMP_HEAD, above.
!
! FORMAL PARAMETERS:
!
!	TEMP_HEAD	Value to use for PAT$TOKEN_BUF_TEMP_HEAD,
!			returned by previous call to PAT$TOKEN_TEMP_HEAD.
!
! IMPLICIT INPUTS:
!
!	None.
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin
    PAT$TOKEN_BUF_TEMP_HEAD = .TEMP_HEAD;
    end;
global routine PAT$TOKEN_SET_HEAD (HEAD) : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	Sets PAT$TOKEN_BUF_HEAD to the required value.
!	See PAT$TOKEN_TEMP_HEAD, above.
!
! FORMAL PARAMETERS:
!
!	HEAD		Value for PAT$TOKEN_BUF_HEAD,
!			returned by previous call to PAT$TOKEN_TEMP_HEAD.
!
! IMPLICIT INPUTS:
!
!	None.
!
! IMPLICIT OUTPUTS:
!
!	PAT$TOKEN_BUF_HEAD
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	None.
!
!--

    begin
    PAT$TOKEN_BUF_HEAD = .HEAD;
    end;
%if PATBLSEXT_DEBUGGING
%then

global routine PAT$DUMP_TKN_BUF : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	PAT$DUMP_TKN_BUF outputs the buffer of tokens read but not consumed
!	and the temporary buffer of tokens used in local error recovery.
!	When called other than during local error recovery the temporary
!	buffer may contain some "garbage".
!
! FORMAL PARAMETERS:
!
!	None.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_BUF_TEMP_HEAD
!	PAT$TOKEN_CURRENT_PTR
!	PAT$TOKEN_BUF_HEAD
!	PAT$TOKEN_BUF_TAIL
!
! IMPLICIT OUTPUTS:
!
!	None.
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	Prints contents of token buffer on the terminal.
!
!--

    begin

    local
	SAVE_TEMP_HEAD,
	SAVE_PAT$TOKEN_CURRENT_PTR;

    SAVE_TEMP_HEAD = .PAT$TOKEN_BUF_TEMP_HEAD;
    SAVE_PAT$TOKEN_CURRENT_PTR = .PAT$TOKEN_CURRENT_PTR;
    PUT_MSG_EOL ('PAT$DUMP_TKN_BUF:');
    PUT_EOL ();
    PAT$TOKEN_BUF_TEMP_HEAD = .PAT$TOKEN_BUF_HEAD;
    PUT_MSG_EOL ('TOKEN BUFFER :');
    PUT_EOL ();

    while (.PAT$TOKEN_BUF_TEMP_HEAD neq .PAT$TOKEN_BUF_TAIL) do
	begin
	PAT$TOKEN_GET (FALSE);
	LS_DUMP_TOK (.PAT$TOKEN_CURRENT_PTR);
	PUT_EOL ();
	end;

    PUT_MSG_EOL ('END OF TOKEN BUFFER');
    PUT_EOL ();
    PUT_EOL ();
    PAT$TOKEN_BUF_TEMP_HEAD = .SAVE_TEMP_HEAD;
    PUT_MSG_EOL ('TEMPORARY TOKEN BUFFER :');
    PUT_EOL ();

    while (.PAT$TOKEN_BUF_TEMP_HEAD neq .PAT$TOKEN_BUF_TAIL) do
	begin
	PAT$TOKEN_GET (FALSE);
	LS_DUMP_TOK (.PAT$TOKEN_CURRENT_PTR);
	PUT_EOL ();
	end;

    PUT_MSG_EOL ('END OF TEMPORARY TOKEN BUFFER');
    PUT_EOL ();
    PAT$TOKEN_BUF_TEMP_HEAD = .SAVE_TEMP_HEAD;
    PAT$TOKEN_CURRENT_PTR = .SAVE_PAT$TOKEN_CURRENT_PTR;
    end;					! Of PAT$DUMP_TKN_BUF

%fi
%if PATBLSEXT_DEBUGGING
%then

global routine PAT$DUMP_TOKEN : novalue =

!++
!
! FUNCTIONAL DESCRIPTION:
!
!	Debugging routine to dump the lexical token pointed to by
!	PAT$TOKEN_CURRENT_PTR to the terminal.
!
! FORMAL PARAMETERS:
!
!	None.
!
! IMPLICIT INPUTS:
!
!	PAT$TOKEN_CURRENT_PTR
!
! IMPLICIT OUTPUTS:
!
!	None.
!
! ROUTINE VALUE:
!
!	None.
!
! SIDE EFFECTS:
!
!	One token is dumped to the terminal.
!
!--

    begin
    PUT_MSG_EOL ('PAT$DUMP_TOKEN		PAT$TOKEN_CURRENT_PTR points to:');
    PUT_EOL ();
    LS_DUMP_TOK (.PAT$TOKEN_CURRENT_PTR);
    end;					! Of PAT$DUMP_TOKEN

%fi

end						!End of module

eludom