* from: llparse.c,v 2.2 88/09/19 12:54:59 nhall Exp
* ************************* NOTICE *******************************
* This code is in the public domain. It cannot be copyrighted.
* This ll parser was originally written by Keith Thompson for the
* University of Wisconsin Crystal project.
* It was based on an FMQ lr parser written by Jon Mauney at the
* University of Wisconsin.
* It was subsequently modified very slightly by Nancy Hall at the
* University of Wisconsin for the Crystal project.
* ****************************************************************
#define LLMINACTION -LLINF
short llparsestack
[STACKSIZE
];
register havetoken
= FALSE
;
register LLtoken
*t
= &lltoken
;
register accepted
= FALSE
;
llpushprod(llnprods
-1); /* $$$ ::= <start symbol> */
sym
= llparsestack
[llstackptr
];
printf("llparse() top of loop, llstackptr=%d, sym=%d\n",
for(;sym
<=LLMINACTION
;sym
++) {
llaction(1, t
); /* calls llfinprod */
} else { llaction(-sym
, t
);
/* it's a terminal symbol */
llstackptr
--; /* pop terminal */
if(t
->llterm
== llnterms
-1) { /* end symbol $$$ */
llparsererror(t
); /* wrong terminal on input */
/* consult parse table for new production */
parseaction
= llfindaction(sym
, t
->llterm
);
if(llepsilon
[parseaction
]) {
if(llepsilonok(t
->llterm
)) {
llstackptr
--; /* pop nonterminal */
llpushprod(parseaction
); /* push rhs of production */
llstackptr
--; /* pop nonterminal */
llpushprod(parseaction
); /* push rhs of production */
llpushprod(prod
) /* recognize production prod - push rhs on stack */
start
= llprodindex
[prod
].llprodstart
;
length
= llprodindex
[prod
].llprodlength
;
printf("llpushprod(%d) llstackptr=0x%x(%d), length = 0x%x(%d)\n",
prod
, llstackptr
, llstackptr
, length
, length
);
if(llstackptr
+length
>= STACKSIZE
) {
fprintf(stderr
,"Parse stack overflow. llstackptr=0x%x, length=0x%x\n",
llsetattr(llprodindex
[prod
].llprodtlen
);
/* put a marker on the stack to mark beginning of production */
if(llparsestack
[llstackptr
] <= LLMINACTION
) {
(llparsestack
[llstackptr
]) --; /* if there's already one there, don't
put another on; just let it represent all of
llparsestack
[llstackptr
] = LLMINACTION
;
for(count
=0; count
<length
; count
++) {
llparsestack
[llstackptr
] = llproductions
[start
++];
if(llstackptr
> STACKSIZE
) {
fprintf(stderr
, "PARSE STACK OVERFLOW! \n"); Exit(-1);
printf("llepsilonok() enter\n");
pact
= llfindaction(sym
, term
);
if(llepsilon
[pact
] == TRUE
) {
short llfindaction(sym
, term
)
printf("llfindaction(sym=%d, term=%d) enter \n", sym
, term
);
index
= llparseindex
[sym
];
while(llparsetable
[index
].llterm
!= 0) {
if(llparsetable
[index
].llterm
== term
) {
return(llparsetable
[index
].llprod
);
fprintf(stderr
,"llparsererror() enter\n");
fprintf(stderr
, "Syntax error: ");
printf("llgettoken(): ");
/******************************************************************************
Attribute support routines
******************************************************************************/
** AttrStack = stack of record
** values : array of values;
LLattrib llattributes
[LLMAXATTR
];
struct llattr llattrdesc
[LLMAXDESC
];
register struct llattr
*ptr
;
printf("llsetattr(%d) enter\n",n
);
if(lldescindex
>= LLMAXDESC
) {
fprintf(stdout
, "llattribute stack overflow: desc\n");
"lldescindex=0x%x, llattrtop=0x%x\n",lldescindex
, llattrtop
);
ptr
= &llattrdesc
[lldescindex
];
ptr
->llabase
= &llattributes
[llattrtop
];
ptr
->lloldtop
= ++llattrtop
;
ptr
->llacnt
= n
+1; /* the lhs ALWAYS uses an attr; it remains on the
stack when the production is recognized */
printf("llpushattr() enter\n");
if(llattrtop
+ 1 > LLMAXATTR
) {
fprintf(stderr
, "ATTRIBUTE STACK OVERFLOW!\n");
a
= &llattrdesc
[lldescindex
-1];
llattributes
[llattrtop
++] = attr
;
a
->llaindex
++; /* inc count of attrs on the stack for this prod */
printf("llfinprod() enter\n");
llattrtop
= llattrdesc
[lldescindex
].lloldtop
;
llattrdesc
[lldescindex
-1].llaindex
++; /* lhs-of-prod.attr stays on
the stack; it is now one of the rhs attrs of the now-top production
printf("PARSE STACK:\n");
for(ind
=llstackptr
; ind
>=0; ind
--) {
llparsestack
[ind
]<0? "Action symbol" : llstrings
[llparsestack
[ind
]]);
fprintf(stdout
, "t at 0x%x\n", t
);
fprintf(stdout
, "t->llterm=0x%x\n", t
->llterm
); (void) fflush(stdout
);
fprintf(stdout
, "TOK: %s\n", llstrings
[t
->llterm
]);
/* to make lint shut up */
fprintf(stdout
, "", llnterms
, llnsyms
, llnprods
, llinfinite
);