! PATTOKEN.REQ ! ! ! ! COPYRIGHT (c) 1982 BY ! DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. ! ! 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 WHICH IS NOT SUPPLIED BY DIGITAL. ! !++ ! FACILITY: PAT Parser ! ! ABSTRACT: ! ! PATTOKEN.REQ is the external specification for the parser ! parser token buffer management routines. ! ! ENVIRONMENT: VAX/VMS user mode ! ! AUTHOR: Charlie Mitchell, CREATION DATE: 9-Nov-1981 ! ! MODIFIED BY: ! !-- require 'PATREQPRO_REQ'; library 'PAT_LANGSP_LIBRARY'; ! !+ ! PAT$TOKEN_CURRENT_PTR is the current token pointer. It is set everytime ! that PAT$TOKEN_GET is called. Thus, it contains a pointer to ! a "future" lexical token when parse ahead is being done. ! !- external PAT$TOKEN_CURRENT_PTR, sdl$shr_data; !pointer to the sdl shared data structure ! sdl$_shr_data ! external 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 ! !-- ! external routine PAT$TOKEN_GET; !++ ! 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 then new token is assigned to PAT$TOKEN_CURRENT_PTR. ! ! FORMAL PARAMETERS: ! ! CONSUME - Boolean variable. If TRUE then tokens are consumed, ! if FALSE then they are saved for future use. ! ! IMPLICIT OUTPUTS: ! ! PAT$TOKEN_CURRENT_PTR ! ! ROUTINE VALUE: ! ! Terminal symbol number of token that was fetched ! !-- macro PAT$TOKEN_GET_CONSUME = !+ ! This macro is equivilant to a call to PAT$TOKEN_GET (TRUE) !- begin external PAT$TOKEN_BUF_HEAD, PAT$TOKEN_BUF_TAIL; if (.PAT$TOKEN_BUF_HEAD eql .PAT$TOKEN_BUF_TAIL) then ! Empty buffer PAT$TOKEN_CURRENT_PTR = LS_GET_LEX_TOKEN else ! Unread tokens in buffer begin PAT$TOKEN_CURRENT_PTR = ..PAT$TOKEN_BUF_HEAD; PAT$TOKEN_ADVANCE (PAT$TOKEN_BUF_HEAD); end; LS_LEX_TERM (PAT$TOKEN_CURRENT_PTR) end %; ! external routine PAT$TOKEN_SAVE : 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. ! ! FORMAL PARAMETERS: ! ! TOKEN_PTR Token to be saved ! ! PERMANENT TRUE if definite correction, ! FALSE if temporary change for trial correction ! !-- macro PAT$TOKEN_SAVE_PERMANENT (TOKEN_PTR) = !+ ! This macro is equivilant to a call to PAT$TOKEN_SAVE (XXX, TRUE) !- begin external PAT$TOKEN_BUF_HEAD; PAT$TOKEN_BACKUP (PAT$TOKEN_BUF_HEAD); .PAT$TOKEN_BUF_HEAD = (TOKEN_PTR); end %; ! external routine PAT$TOKEN_SAVE_BUF; !++ ! FUNCTIONAL DESCRIPTION: ! ! This routine saves the first n tokens (or all tokens) in the ! token buffer in temporary storage so that they can be ! restored after an error recovery attempt. The tokens can ! be restored by calling PAT$TOKEN_RESTORE_BUF. ! ! FORMAL PARAMETERS: ! ! SAVE_UPTO - number of tokens to be saved ! ! RETURN VALUE: ! ! Number of tokens saved !-- ! external routine PAT$TOKEN_RESTORE_BUF : novalue; !++ ! FUNCTIONAL DESCRIPTION ! ! This routine restores tokens saved by the previous call ! to PAT$TOKEN_SAVE_BUF. ! ! FORMAL PARAMTERS: ! ! NUM_TOKENS - Value returned on prior call to ! PAT$TOKEN_SAVE_BUF. ! !-- ! external routine PAT$TOKEN_RESET_BUFFER : novalue; !++ ! FUNCTIONAL DESCRIPTION ! ! This routine 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 PARAMTERS: ! ! NONE ! !-- ! external routine PAT$TOKEN_TEMP_HEAD; !++ ! FUNCTIONAL DESCRIPTION ! ! 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 usage: ! ! begin ! local SAVED_TEMP_HEAD; ! SAVED_TEMP_HEAD = PAT$TOKEN_TEMP_HEAD (); ! ... ! PAT$TOKEN_SET_TEMP_HEAD (.SAVED_TEMP_HEAD) ! ! PAT$TOKEN_SET_HEAD can be used to modify the actual buffer. ! ! FORMAL PARAMTERS: ! ! NONE ! ! RETURN VALUE: ! ! Pointer to the first token in the temporary token buffer. !-- ! external routine PAT$TOKEN_SET_TEMP_HEAD : novalue; !++ ! FUNCTIONAL DESCRIPTION ! ! See PAT$TOKEN_TEMP_HEAD. ! ! FORMAL PARAMTERS: ! ! TEMP_HEAD Value returned on previous call to ! PAT$TOKEN_TEMP_HEAD ! !-- ! external routine PAT$TOKEN_SET_HEAD : novalue; !++ ! FUNCTIONAL DESCRIPTION ! ! See PAT$TOKEN_TEMP_HEAD. ! ! FORMAL PARAMTERS: ! ! HEAD Value returned on previous call to ! PAT$TOKEN_TEMP_HEAD ! !-- ! !+ ! The macros that follow are not intended for direct use outside of ! PATTOKEN. !- macro PAT$TOKEN_ADVANCE (BUF_PTR) = begin external PAT$TOKEN_BUF_HIGH, PAT$TOKEN_BUF_LOW; if .BUF_PTR eql .PAT$TOKEN_BUF_HIGH ! then ! BUF_PTR = .PAT$TOKEN_BUF_LOW ! else ! BUF_PTR = .BUF_PTR + %upval end %; macro PAT$TOKEN_BACKUP (BUF_PTR) = begin external PAT$TOKEN_BUF_HIGH, PAT$TOKEN_BUF_LOW; if .BUF_PTR eql .PAT$TOKEN_BUF_LOW ! then ! BUF_PTR = .PAT$TOKEN_BUF_HIGH ! else ! BUF_PTR = .BUF_PTR - %upval end %; ! %if PATBLSEXT_DEBUGGING %then external routine PAT$DUMP_TOKEN : novalue; !++ ! FUNCTIONAL DESCRIPTION: ! ! PAT$DUMP_TOKEN outputs the lexical token pointed to by PAT$TOKEN_CURRENT_PTR. ! ! FORMAL PARAMETERS: ! ! NONE ! ! IMPLICIT INPUTS: ! ! PAT$TOKEN_CURRENT_PTR ! ! IMPLICIT OUTPUTS: ! ! NONE ! ! ROUTINE VALUE: ! ! NONE ! ! SIDE EFFECTS: ! ! NONE ! !-- ! external 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: ! ! TKN_BUF_HEAD ! ! TKN_BUF_TEMP_HEAD ! ! TKN_BUF_TAIL ! ! IMPLICIT OUTPUTS: ! ! NONE ! ! ROUTINE VALUE: ! ! NONE ! ! SIDE EFFECTS: ! ! NONE ! !-- %fi ! End of PATTOKEN.REQ