Google
 

Trailing-Edge - PDP-10 Archives - CFS_TSU04_19910205_1of1 - update/t20src/diupatdata.req
There are 4 other files named diupatdata.req in the archive. Click here to see a list.
!	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.
!
! PATDATA.REQ
! IDENT('253')
!++
! FACILITY:	PAT Parser
!
! ABSTRACT:
!
!	PATDATA.REQ is the specification for the PAT/BLISS interface.
!	It defines literals for grammar symbols (such as terminals)
!	and defines the interface to the parse tables and text
!	tables.  (The tables are allocated in PATDATA.BLI.)
!
!	This file is language independent for most applications
!	that use the PAT parser.  (See notes on language independence
!	that follow.)
!
!	This file should be libraried by the lexical analyzer, the
!	semantic action processor, and other modules that need to refer
!	to symbols in the grammar.
!
!	Note that all access to the parse tables and symbol text
!	tables should only be made via macros and routines defined
!	in this module.
!
! ENVIRONMENT:	VAX/VMS user mode
!
! AUTHOR:  C. Mitchell, CREATION DATE:  18-Feb-80
!
! MODIFIED BY:
!
! 	Charlie Mitchell, 02-Sep-81 : VERSION X2.001
! 001 -	Define the parse tables as an abstract data type to
!	facilitate future optimizations of the table organization.
!	Modify to use the new LALRPAT external names for terminal
!	symbols.
! 002 - Remove VMS dependencies.  C. Richardson.
!
!  253  Rename to DIUPATDATA.REQ
!       Gregory A. Scott 1-Jul-86
!--

require 'DIUPATREQPRO';				! 002

library 'BLI:XPORT';				! 002
! To define the literal definitions for grammar symbols, this file
! requires logical name 'PAT_REQUIRE_FILE' which should be defined
! as the require file output by PAT.
!
! The expansion of the macros called in PAT_REQUIRE_FILE results
! in literal definitions for terminals, non-terminals, and semantics
! actions.
!
! Example.  For the grammar
!
!	terminal
!
!	    loop,	t_loop,		= 1;	! t_loop is the external name
!	    ',',	t_comma,	= 2;
!	    goalsy,	t_goalsy,	= 3;
!
!	end;
!
!	begin
!
!	    SENTENCE	= NONSENSE goalsy /;
!
!	    NONSENSE	= loop ',' /CRAZY ;
!
!	end.
!
! the following literals are defined:
!
!	literal			! for terminals and non-terminals
!	    T_LOOP	= 1,	! external name
!	    T_COMMA	= 2,
!	    T_GOALSY	= 3,
!	    NT_SENTENCE	= 4,	! Note NT_ prefix for non-terminals
!	    NT_NONSENSE	= 5;
!
!	literal			! for semantics actions
!	    PAT$DATA_NULL_SEMACT = 0,	! no action specified
! 	    SENTENCE01	= 1,
!	    CRAZY	= 2;
!
!
! PAT_REQUIRE_FILE is required again in PATDATA.BLI to define
! (allocate and initialize) the parse tables.
!		Notes on Language Independence of PATDATA
!
! This file is generally language independent.  Modifications will
! be required for the following reasons:
!
!   1.	To obtain grammar symbol text from "foreign tables" that
!	are already defined somewhere in your code (e.g., tables
!	that are defined for your lexical analyzer so that it can
!	recognize reserved words).
!
!   2.	To change the allocation units for the parse tables.
!
!   3.	To permit multiple grammars to be parsed.  This can be
!	done by modifying references to the parse tables to be
!	done indirectly though a pointer.  This can also
!	be accomplished by combining the multiple grammars in
!	one PAT intput file and defining a special lexical token that
!	is passed to the parser as the first token.  Example:
!
!	    TERMINAL
!		parse_grammar_1	= 0;
!		parse_grammar_2 = 1;
!		goalsy		= 2;
!		...
!	    END;
!	    BEGIN
!
!		SENTENCE 	= WHOLETHING goalsy;
!
!		WHOLETHING	= parse_grammar_1 GRAMMAR_1
!				| parse_grammar_2 GRAMMAR_2;
!
!		GRAMMAR_1	= {definition of one grammar} ...
!
!		GRAMMAR_2	= {definition of another grammar} ...
!
!	    END.
! This file is divided into 6 sections:
!
!   1.	Macros for obtaining text associated with grammar symbols.
!
!   2.	Allocation units for the parse tables.
!
!   3.	Routines and macros for accessing and interpreting the parse
!	tables.
!
!   4.	Literal definitions for grammar symbols.
!
!   5.	Other literal definitions.
!
!   6.	Clean up.
!			Section 1
!
! Macros for obtaining text of terminal, non-terminal, and
! semantics action symbols.


! This macro returns the address of a string descriptor
! for the terminal or non-terminal symbol represented
! by SYMBOL_NUMBER.

%IF %BLISS (BLISS36)				! 002
%THEN						! 002
macro						! 002
PAT$DATA_SYMBOL_TEXT_TABLE	= SYTXTB %;	! 002
%FI						! 002

macro
    PAT$DATA_SYMBOL_TEXT (SYMBOL_NUMBER) =

	begin

	external
	    PAT$DATA_SYMBOL_TEXT_TABLE : blockvector	! 002 of string descriptors
		[, STR$K_F_BLN] field (					! 002
		    STR$B_CLASS,					! 002
		    STR$B_DTYPE,					! 002
		    STR$H_LENGTH,					! 002
		    STR$A_POINTER );					! 002

	PAT$DATA_SYMBOL_TEXT_TABLE [SYMBOL_NUMBER,0,0,0,0]		! 002
	end
    %;
! This macro returns the address of a string descriptor
! for the semantic action represented by ACTION_NUMBER.

%if PATBLSEXT_DEBUGGING
%then

%IF %BLISS (BLISS36)					! 002
%THEN							! 002
macro							! 002
PAT$DATA_SEMACT_TEXT_TABLE	=	SMTXTB %;	! 002
%FI							! 002

macro
    PAT$DATA_SEMACT_TEXT (ACTION_NUMBER) =

	begin

	external
	    PAT$DATA_SEMACT_TEXT_TABLE : vector [];	! 002 to string descriptors

	.PAT$DATA_SEMACT_TEXT_TABLE [ACTION_NUMBER]			! 002
	end
    %;

%fi
!			Section 2
!
! Define allocation units for parsing tables.  Note that these
! definitions are not intended for direct use outside PATDATA.

%BLISS32 (					! 002
macro
    PAT_STATE_SYMBOL_TABLE_ALLOC = 		! for state symbol table
	word %,
    PAT_STATE_ACTION_TABLE_ALLOC = 		! for state action table
	word %,
    PAT_RHS_COUNT_TABLE_ALLOC = 		! for rhs count table
	byte %,
    PAT_LHS_TABLE_ALLOC = 			! for lhs table
	word %,
    PAT_SEMACT_TABLE_ALLOC = 			! for semantics action table
	word %;
)						! 002
!			Section 3
!
! Routines and macros for accessing and interpreting the parse tables.


! Macro PAT$DATA_MOVE_ACTION
!
! FUNCTIONAL DESCRIPTION:
!
!	When called with STATE indicating the parse state and
!	SYMBOL containing an input symbol to that state, this routine
!	returns the action code for the move action that will be performed.
!	(See PAT$DATA_ACTION_IS)
!
! FORMAL PARAMETERS:
!
!	STATE		- Parse state.  Use PAT$DATA_INITIAL_STATE
!			  to start parsing.
!
!	SYMBOL		- Terminal or non-terminal symbol
!
! VALUE:
!
!	ACTION_CODE	- Action code of the action that will be performed

literal
    PAT$DATA_INITIAL_STATE = 0;			! Initial parse state

%IF %BLISS (BLISS36)					! 002
%THEN							! 002
macro							! 002
PAT$DATA_STATE_SYMBOL_TABLE	=	STSYTB %,	! 002
PAT$DATA_STATE_ACTION_TABLE	=	STACTB %;	! 002
%FI							! 002

macro
    PAT$DATA_MOVE_ACTION (STATE, SYMBOL) =
	begin

	external
	    PAT$DATA_STATE_SYMBOL_TABLE : vector [ %BLISS32 (, PAT_STATE_SYMBOL_TABLE_ALLOC)],		! 002
	    PAT$DATA_STATE_ACTION_TABLE : vector [%BLISS32 (, PAT_STATE_ACTION_TABLE_ALLOC, signed)];	! 002

	local
	    STATE_INDEX;

	STATE_INDEX = (STATE);

	while ((.PAT$DATA_STATE_SYMBOL_TABLE [.STATE_INDEX] neq (SYMBOL)) and 	!
	    (.PAT$DATA_STATE_SYMBOL_TABLE [.STATE_INDEX] neq PAT$DATA_ELSE_CODE)) do

	    if .PAT$DATA_STATE_SYMBOL_TABLE [.STATE_INDEX] eql PAT$DATA_CONT_CODE
	    then
		STATE_INDEX = .PAT$DATA_STATE_ACTION_TABLE [.STATE_INDEX]
	    else
		STATE_INDEX = .STATE_INDEX + 1;

	.PAT$DATA_STATE_ACTION_TABLE [.STATE_INDEX]
	end
    %;
! The macros that follow test and interpret the action code returned by
! PAT$DATA_MOVE_ACTION.
!
! The action to be taken (shift to state n, reduce to rule m)
! is encoded in one value.  PAT$DATA_ACTION_IS can be used
! to test if the action code represents a shift, reduction, etc,
! and then PAT$DATA_AC_TO_SHIFT_STATE, PAT$DATA_AC_TO_PRODUCTION_NO, or
! PAT$DATA_AC_TO_LA_PRODUCTION_NO can be used to obtain the shift
! state or the production number in the case of reductions.


! This macro is used to test the action code returned
! by routine PAT$DATA_MOVE_ACTION.  Note that the macros
! assume that the tests are made in a specific order:
! 'ERROR', 'SHIFT', 'LOOK_AHEAD'.
!
! CLASS is specified  by one of the following quoted strings:  
!
!	 CLASS	      meaning		assumption
!
!	'ERROR'		error
!
!	'SHIFT'		shift 		Not an ERROR
!
!	'LOOK_AHEAD'	lookahead 
!			reduction

macro
    PAT$DATA_ACTION_IS (ACTION_CODE, CLASS) =

	%if %identical (CLASS,'ERROR')
	%then					! Error
	    ((ACTION_CODE) eql PAT$DATA_ERROR_CODE)
	%else %if %identical (CLASS,'SHIFT')
	%then					! Shift
	    ((ACTION_CODE) geq 0) 
	%else %if %identical (CLASS,'LOOK_AHEAD')
	%then					! Look-ahead reduction
	    ((ACTION_CODE) leq -PAT$DATA_SCAN_CODE)
	%fi %fi %fi %;

! Return the goto state for a shift.  ACTION_CODE is
! the value returned by PAT$DATA_MOVE_ACTION.

macro
    PAT$DATA_AC_TO_SHIFT_STATE (ACTION_CODE) =

	(ACTION_CODE)
    %;

! Return the production number for a non-lookahead
! reduction.  ACTION_CODE is the value returned by
! PAT$DATA_MOVE_ACTION.

macro
    PAT$DATA_AC_TO_PRODUCTION_NO (ACTION_CODE) =

	(-(ACTION_CODE))
    %;

! Return the production number for a lookahead
! reduction.  ACTION_CODE is the value returned by
! PAT$DATA_MOVE_ACTION.

macro
    PAT$DATA_AC_TO_LA_PRODUCTION_NO (ACTION_CODE) =

	(-((ACTION_CODE) + PAT$DATA_SCAN_CODE))
    %;
external routine
    PAT$DATA_NEXT_TRANSITION : novalue;

!++
! FUNCTIONAL DESCRIPTION:
!
! This routine is called to fetch the next symbol which is
! the next legal transition from a state.  If ONLY_TERMINALS is TRUE
! the routine will only return terminals, otherwise it will return
! terminals and non-terminals.
!
! FORMAL PARAMETERS:
!
!	STATE			Parse state
!
!	ONLY_TERMINALS		Boolean--if TRUE, only terminals are
!				returned
!
!	REF_LAST_TRANSITION	Pointer to the last transition.
!				To find the first transition in
!				a state, pass PAT$DATA_FIND_FIRST_TRANSITION.
!				This is an output parameter that is
!				updated to indicate the last transition
!				returned.
!
!	REF_ACTION_CODE		Pointer to an action code.  This is
!				an output parameter that is set only
!				when this routine returns
!				PAT$DATA_NO_MORE_TRANSITIONS
!
!	REF_SYMBOL		Pointer to a location to receive a
!				symbol which is a legal transition or
!				or PAT$DATA_NO_MORE_TRANSITIONS if all
!				have been returned.
!
!--

! Define constants for PAT$DATA_NEXT_TRANSITION.

literal
    PAT$DATA_NO_MORE_TRANSITIONS = -1,		! Used as symbol to indicate
    						! no more transition in a state
    PAT$DATA_FIND_FIRST_TRANSITION = -1;	! Used to indicate desire to find
						! the first transition in a
						! state.
! Macro for accessing the parse reduction table

%IF %BLISS (BLISS36)					! 002
%THEN							! 002
macro							! 002
PAT$DATA_LHS_TABLE		=	LHSTAB %,	! 002
PAT$DATA_RHS_COUNT_TABLE	=	RHSCTB %,	! 002
PAT$DATA_SEMACT_TABLE		=	SEMTAB %;	! 002
%FI							! 002

! This macro accesses the parse reduction table for
! production PRODUCTION_NUMBER and assigns values
! to
!
!    REF_LHS		address of location to be assigned
!			the symbol number of the symbol
!			(non-terminal) on the right hand side
!			of the production.
!
!    REF_RHS_COUNT	address of location to be assigned the
!			number of symbols (terminal and non-
!			terminal) on the right hand side of
!			the production.
!
!    REF_SEMACT		address of location to be assigned the
! 			semantic action number for the
!			production.

macro
    PAT$DATA_GET_REDUCTION_INFO 		!
    (PRODUCTION_NUMBER, REF_LHS, REF_RHS_COUNT, REF_SEMACT) =

	begin

	external
	    PAT$DATA_LHS_TABLE : vector [%BLISS32 (, PAT_LHS_TABLE_ALLOC)],	! 002
	    PAT$DATA_RHS_COUNT_TABLE : vector [%BLISS32 (, PAT_RHS_COUNT_TABLE_ALLOC)],	! 002
	    PAT$DATA_SEMACT_TABLE : vector [%BLISS32 (, PAT_SEMACT_TABLE_ALLOC)];	! 002

	(REF_LHS) = .PAT$DATA_LHS_TABLE [PRODUCTION_NUMBER];
	(REF_RHS_COUNT) = .PAT$DATA_RHS_COUNT_TABLE [PRODUCTION_NUMBER];
	(REF_SEMACT) = .PAT$DATA_SEMACT_TABLE [PRODUCTION_NUMBER]
	end
    %;
!			Section 4
!
! Literal definitions for grammar symbols.
!
! This section requires PAT_REQUIRE_FILE which is the require file output
! by PAT and which contains:
!
!   1.	Symbolic definitions (using macro calls) for all terminals,
!	non-terminals, and semantics actions.
!
!   2.	Symbolic definitions of the parsing tables.
!
! Definitions in the require file PAT_REQUIRE_FILE have the form:
!
!	PAT_DECTRMDEF('ABORT', T_ABORT, 0)
!	PAT_DECTRMDEF('ACCEPT', T_ACCEPT, 1)
!		... for terminals
!
!	PAT_NONTRMDEF('PROGRAM',106)
!		... for non-terminals
!
!	PAT_SEMACTDEF('XXX',7)
!		... for semantics actions
!
! The expansion of these macros results in literal definitions for
! each terminal and non-terminal symbol and each semantics action.


! Define general macros


! Expand an argument list with comma separators

macro
    EXPAND_ARG_LIST (A) =
	A
	%if not %null (%remaining)
	%then
	    , EXPAND_WORKER (%remaining)
	%fi
    %;

macro
    EXPAND_WORKER [ARG] =
	ARG %;

! Define macros to define literals for terminal and
! non-terminal symbols and semantics actions

macro
    PAT_SYMBOL_DEFINITIONS (A) =
	literal
	    EXPAND_ARG_LIST (A, %remaining);
    %;

macro
    PAT_SEMACT_DEFINITIONS (A) =
	literal
	    EXPAND_ARG_LIST (A, %remaining);
    %;

macro
    PAT_INTERNAL_DEFINITIONS (A) =
	literal
	    EXPAND_ARG_LIST (A, %remaining);
    %;

! Declared terminal definition

macro
    PAT_DECTRMDEF (SYMBOL_NAME, EXT_NAME, VALUE) =
	%name (EXT_NAME) = VALUE %;

! Undeclared terminal definition

macro
    PAT_UNDTRMDEF (SYMBOL_NAME, VALUE) =
	%warn ('Undefined terminal symbol:  (It never appears on the left hand side of a production).')%name(
	EXT_NAME) = VALUE %;

! Non-terminal definition

macro
    PAT_NONTRMDEF (NAME, VALUE) =
	%name ('NT_', NAME) = VALUE %;

! Non-terminal reference

macro
    PAT_NONTRMREF (NAME) =
	%name ('NT_', NAME) %;

! Semantics action definition

macro
    PAT_SEMACTDEF (NAME, VALUE) =
	%name (NAME) = VALUE %;

! Semantics action reference

macro
    PAT_SEMACTREF (NAME, VALUE) =
	%name (NAME) %;

! Internal definition

macro
    PAT_INTRNLDEF (NAME, VALUE) =
	%name (NAME) = VALUE %;

! Unused number

macro
    PAT_UNUSEDNUM (NUM) =
	%name ('__unused_', NUM) = NUM %;
! Define macros in PAT_REQUIRE_FILE that must be defined for correct
! compilation but that aren't needed here.

macro
    PAT_DECTRMREF (EXT_NAME) =
    %,						! null
    PAT_UNDTRMREF (EXT_NAME) =
    %,
    PAT_INTRNLREF (NAME) =
    %,
    PAT_STATE_SYMBOL_TABLE (ARG_LIST) =
    %,
    PAT_STATE_ACTION_TABLE (ARG_LIST) =
    %,
    PAT_RHS_COUNT_TABLE (ARG_LIST) =
    %,
    PAT_LHS_TABLE (ARG_LIST) =
    %,
    PAT_SEMACT_TABLE (ARG_LIST) =
    %;

! Require PAT_REQUIRE_FILE to define the literals.  Don't define the parsing tables
! here though.

literal
    PAT_DFS = 1;				! Declare PAT_DFS so that see definitions

literal
    PAT_NO_TABLES = 1;			! Declare PAT_NO_TABLES so that don't define the parsing tables

require 'DIUDDL';
!			Section 5
!
! Define misc. literals


! Define exported literals.

literal
    ! null action code
    PAT$DATA_NULL_SEMACT = PAT_SEMACTREF ('PAT_NULL'),
    ! first terminal symbol
    PAT$DATA_FIRST_TERM = PAT_FIRST_TERM,
    ! last terminal symbol
    PAT$DATA_LAST_TERM = PAT_LAST_TERM,
    ! number of terminals
    PAT$DATA_NUM_TERM = (PAT_LAST_TERM - PAT_FIRST_TERM) + 1,
    ! number of terminal and non-terminal symbols
    PAT$DATA_MAX_TOKEN = PAT_MAX_TOKEN,
    ! number of semantics actions
    PAT$DATA_MAX_SEMACT = PAT_MAX_SEMACT,
    ! top most production (non-terminal on lhs)
    PAT$DATA_SENTENCE_CODE = PAT_SENTENCE_CD;

! Define private literals (those that should only be used by
! routines and macros defined in PATDATA).

literal
    PAT$DATA_CONT_CODE = PAT_CONT_CODE,
    PAT$DATA_ELSE_CODE = PAT_ELSE_CODE,
    PAT$DATA_SCAN_CODE = PAT_SCAN_CODE,
    PAT$DATA_ERROR_CODE = PAT_ERROR_CODE;
!			Section 6
!
! Clean up.
!
! Undeclare the macros and names that aren't used outside of PATDATA.

undeclare
    PAT_DFS,
    PAT_NO_TABLES,
    PAT_CONT_CODE,
    PAT_ELSE_CODE,
    PAT_SCAN_CODE,
    PAT_ERROR_CODE,
    PAT_MAX_TOKEN,
    PAT_MAX_POP,
    PAT_MAX_REDUCT,
    PAT_MAX_TRANS,
    PAT_MAX_SEMACT,
    PAT_FIRST_TERM,
    PAT_LAST_TERM,
    PAT_SENTENCE_CD,
    %quote PAT_DECTRMDEF,
    %quote PAT_UNDTRMDEF,
    %quote PAT_NONTRMDEF,
    %quote PAT_SEMACTDEF,
    %quote PAT_INTRNLDEF,
    %quote PAT_DECTRMREF,
    %quote PAT_UNDTRMREF,
    %quote PAT_NONTRMREF,
    %quote PAT_SEMACTREF,
    %quote PAT_INTRNLREF,
    %quote PAT_UNUSEDNUM,
    %quote PAT_SYMBOL_DEFINITIONS,
    %quote PAT_SEMACT_DEFINITIONS,
    %quote PAT_INTERNAL_DEFINITIONS,
    %quote PAT_STATE_SYMBOL_TABLE,
    %quote PAT_STATE_ACTION_TABLE,
    %quote PAT_RHS_COUNT_TABLE,
    %quote PAT_LHS_TABLE,
    %quote PAT_SEMACT_TABLE,
    %quote EXPAND_ARG_LIST,
    %quote EXPAND_WORKER;

! End of PATDATA.REQ