* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)lalr.c 5.3 (Berkeley) %G%";
reductions
**reduction_table
;
static shorts
**lookback
;
tokensetsize
= WORDSIZE(ntokens
);
state_table
= NEW2(nstates
, core
*);
for (sp
= first_state
; sp
; sp
= sp
->next
)
state_table
[sp
->number
] = sp
;
accessing_symbol
= NEW2(nstates
, short);
for (sp
= first_state
; sp
; sp
= sp
->next
)
accessing_symbol
[sp
->number
] = sp
->accessing_symbol
;
shift_table
= NEW2(nstates
, shifts
*);
for (sp
= first_shift
; sp
; sp
= sp
->next
)
shift_table
[sp
->number
] = sp
;
reduction_table
= NEW2(nstates
, reductions
*);
for (rp
= first_reduction
; rp
; rp
= rp
->next
)
reduction_table
[rp
->number
] = rp
;
register short *item_end
;
item_end
= ritem
+ nitems
;
for (itemp
= ritem
; itemp
< item_end
; itemp
++)
if (length
> max
) max
= length
;
lookaheads
= NEW2(nstates
+ 1, short);
for (i
= 0; i
< nstates
; i
++)
LA
= NEW2(k
* tokensetsize
, unsigned);
LAruleno
= NEW2(k
, short);
lookback
= NEW2(k
, shorts
*);
for (i
= 0; i
< nstates
; i
++)
for (j
= 0; j
< rp
->nreds
; j
++)
LAruleno
[k
] = rp
->rules
[j
];
register short *temp_map
;
goto_map
= NEW2(nvars
+ 1, short) - ntokens
;
temp_map
= NEW2(nvars
+ 1, short) - ntokens
;
for (sp
= first_shift
; sp
; sp
= sp
->next
)
for (i
= sp
->nshifts
- 1; i
>= 0; i
--)
symbol
= accessing_symbol
[sp
->shift
[i
]];
if (ISTOKEN(symbol
)) break;
for (i
= ntokens
; i
< nsyms
; i
++)
for (i
= ntokens
; i
< nsyms
; i
++)
goto_map
[i
] = temp_map
[i
];
goto_map
[nsyms
] = ngotos
;
temp_map
[nsyms
] = ngotos
;
from_state
= NEW2(ngotos
, short);
to_state
= NEW2(ngotos
, short);
for (sp
= first_shift
; sp
; sp
= sp
->next
)
for (i
= sp
->nshifts
- 1; i
>= 0; i
--)
symbol
= accessing_symbol
[state2
];
if (ISTOKEN(symbol
)) break;
FREE(temp_map
+ ntokens
);
/* Map_goto maps a state/symbol pair into its numeric representation. */
high
= goto_map
[symbol
+ 1];
middle
= (low
+ high
) >> 1;
nwords
= ngotos
* tokensetsize
;
F
= NEW2(nwords
, unsigned);
reads
= NEW2(ngotos
, short *);
edge
= NEW2(ngotos
+ 1, short);
for (i
= 0; i
< ngotos
; i
++)
sp
= shift_table
[stateno
];
symbol
= accessing_symbol
[sp
->shift
[j
]];
symbol
= accessing_symbol
[sp
->shift
[j
]];
edge
[nedges
++] = map_goto(stateno
, symbol
);
reads
[i
] = rp
= NEW2(nedges
+ 1, short);
for (j
= 0; j
< nedges
; j
++)
for (i
= 0; i
< ngotos
; i
++)
register short **new_includes
;
includes
= NEW2(ngotos
, short *);
edge
= NEW2(ngotos
+ 1, short);
states
= NEW2(maxrhs
+ 1, short);
for (i
= 0; i
< ngotos
; i
++)
symbol1
= accessing_symbol
[to_state
[i
]];
for (rulep
= derives
[symbol1
]; *rulep
>= 0; rulep
++)
for (rp
= ritem
+ rrhs
[*rulep
]; *rp
>= 0; rp
++)
sp
= shift_table
[stateno
];
if (accessing_symbol
[stateno
] == symbol2
) break;
states
[length
++] = stateno
;
add_lookback_edge(stateno
, *rulep
, i
);
stateno
= states
[--length
];
edge
[nedges
++] = map_goto(stateno
, *rp
);
if (nullable
[*rp
] && length
> 0) done
= 0;
includes
[i
] = shortp
= NEW2(nedges
+ 1, short);
for (j
= 0; j
< nedges
; j
++)
new_includes
= transpose(includes
, ngotos
);
for (i
= 0; i
< ngotos
; i
++)
add_lookback_edge(stateno
, ruleno
, gotono
)
int stateno
, ruleno
, gotono
;
k
= lookaheads
[stateno
+ 1];
if (LAruleno
[i
] == ruleno
)
new_R
= NEW2(n
, short *);
temp_R
= NEW2(n
, short *);
register unsigned *fp1
, *fp2
, *fp3
;
register shorts
*sp
, *next
;
fp3
= rowp
+ tokensetsize
;
for (sp
= lookback
[i
]; sp
; sp
= sp
->next
)
fp2
= F
+ tokensetsize
* sp
->value
;
for (sp
= lookback
[i
]; sp
; sp
= next
)
INDEX
= NEW2(ngotos
+ 1, short);
VERTICES
= NEW2(ngotos
+ 1, short);
for (i
= 0; i
< ngotos
; i
++)
for (i
= 0; i
< ngotos
; i
++)
if (INDEX
[i
] == 0 && R
[i
])
base
= F
+ i
* tokensetsize
;
fp3
= base
+ tokensetsize
;
fp2
= F
+ j
* tokensetsize
;
fp2
= F
+ j
* tokensetsize
;