aboutsummaryrefslogtreecommitdiff
path: root/tool/lemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'tool/lemon.c')
-rw-r--r--tool/lemon.c57
1 files changed, 32 insertions, 25 deletions
diff --git a/tool/lemon.c b/tool/lemon.c
index edf17cae7..d4e157a1c 100644
--- a/tool/lemon.c
+++ b/tool/lemon.c
@@ -917,8 +917,11 @@ void FindStates(struct lemon *lemp)
lemp->errorcnt++;
sp = lemp->startRule->lhs;
}
- }else{
+ }else if( lemp->startRule ){
sp = lemp->startRule->lhs;
+ }else{
+ ErrorMsg(lemp->filename,0,"Internal error - no start rule\n");
+ exit(1);
}
/* Make sure the start symbol doesn't occur on the right-hand side of
@@ -1083,7 +1086,7 @@ void FindLinks(struct lemon *lemp)
** which the link is attached. */
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
- for(cfp=stp->cfp; cfp; cfp=cfp->next){
+ for(cfp=stp?stp->cfp:0; cfp; cfp=cfp->next){
cfp->stp = stp;
}
}
@@ -1092,7 +1095,7 @@ void FindLinks(struct lemon *lemp)
** links are used in the follow-set computation. */
for(i=0; i<lemp->nstate; i++){
stp = lemp->sorted[i];
- for(cfp=stp->cfp; cfp; cfp=cfp->next){
+ for(cfp=stp?stp->cfp:0; cfp; cfp=cfp->next){
for(plp=cfp->bplp; plp; plp=plp->next){
other = plp->cfp;
Plink_add(&other->fplp,cfp);
@@ -1115,6 +1118,7 @@ void FindFollowSets(struct lemon *lemp)
int change;
for(i=0; i<lemp->nstate; i++){
+ assert( lemp->sorted[i]!=0 );
for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
cfp->status = INCOMPLETE;
}
@@ -1123,6 +1127,7 @@ void FindFollowSets(struct lemon *lemp)
do{
progress = 0;
for(i=0; i<lemp->nstate; i++){
+ assert( lemp->sorted[i]!=0 );
for(cfp=lemp->sorted[i]->cfp; cfp; cfp=cfp->next){
if( cfp->status==COMPLETE ) continue;
for(plp=cfp->fplp; plp; plp=plp->next){
@@ -1172,7 +1177,14 @@ void FindActions(struct lemon *lemp)
/* Add the accepting token */
if( lemp->start ){
sp = Symbol_find(lemp->start);
- if( sp==0 ) sp = lemp->startRule->lhs;
+ if( sp==0 ){
+ if( lemp->startRule==0 ){
+ fprintf(stderr, "internal error on source line %d: no start rule\n",
+ __LINE__);
+ exit(1);
+ }
+ sp = lemp->startRule->lhs;
+ }
}else{
sp = lemp->startRule->lhs;
}
@@ -1299,21 +1311,7 @@ static struct config **basisend = 0; /* End of list of basis configs */
/* Return a pointer to a new configuration */
PRIVATE struct config *newconfig(void){
- struct config *newcfg;
- if( freelist==0 ){
- int i;
- int amt = 3;
- freelist = (struct config *)calloc( amt, sizeof(struct config) );
- if( freelist==0 ){
- fprintf(stderr,"Unable to allocate memory for a new configuration.");
- exit(1);
- }
- for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
- freelist[amt-1].next = 0;
- }
- newcfg = freelist;
- freelist = freelist->next;
- return newcfg;
+ return (struct config*)calloc(1, sizeof(struct config));
}
/* The configuration "old" is no longer used */
@@ -1932,8 +1930,12 @@ static FILE *errstream;
static void errline(int n, int k, FILE *err)
{
int spcnt, i;
- if( g_argv[0] ) fprintf(err,"%s",g_argv[0]);
- spcnt = lemonStrlen(g_argv[0]) + 1;
+ if( g_argv[0] ){
+ fprintf(err,"%s",g_argv[0]);
+ spcnt = lemonStrlen(g_argv[0]) + 1;
+ }else{
+ spcnt = 0;
+ }
for(i=1; i<n && g_argv[i]; i++){
fprintf(err," %s",g_argv[i]);
spcnt += lemonStrlen(g_argv[i])+1;
@@ -4092,7 +4094,7 @@ void print_stack_union(
int *plineno, /* Pointer to the line number */
int mhflag /* True if generating makeheaders output */
){
- int lineno = *plineno; /* The line number of the output */
+ int lineno; /* The line number of the output */
char **types; /* A hash table of datatypes */
int arraysize; /* Size of the "types" array */
int maxdtlength; /* Maximum length of any ".datatype" field. */
@@ -5339,7 +5341,8 @@ int Strsafe_insert(const char *data)
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
- free(x1a->tbl);
+ /* free(x1a->tbl); // This program was originally for 16-bit machines.
+ ** Don't worry about freeing memory on modern platforms. */
*x1a = array;
}
/* Insert the new data */
@@ -5507,7 +5510,9 @@ int Symbol_insert(struct symbol *data, const char *key)
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
- free(x2a->tbl);
+ /* free(x2a->tbl); // This program was originally written for 16-bit
+ ** machines. Don't worry about freeing this trivial amount of memory
+ ** on modern platforms. Just leak it. */
*x2a = array;
}
/* Insert the new data */
@@ -5843,7 +5848,9 @@ int Configtable_insert(struct config *data)
newnp->from = &(array.ht[h]);
array.ht[h] = newnp;
}
- free(x4a->tbl);
+ /* free(x4a->tbl); // This code was originall written for 16-bit machines.
+ ** on modern machines, don't worry about freeing this trival amount of
+ ** memory. */
*x4a = array;
}
/* Insert the new data */