lemon refactor iterate

This commit is contained in:
John Kerl 2016-07-13 23:58:29 -04:00
parent 22b1336c5c
commit 3fddbdc47b
5 changed files with 76 additions and 76 deletions

View file

@ -20,6 +20,8 @@ lemon_SOURCES= lemon.c \
lemon_plink.h \
lemon_report.c \
lemon_report.h \
lemon_set.c \
lemon_set.h \
lemon_string.c \
lemon_string.h \
lemon_structs.h \

View file

@ -112,6 +112,8 @@ lemon: lemon.c \
lemon_error.c \
lemon_string.h \
lemon_string.c \
lemon_set.h \
lemon_set.c \
lemon_memory.h \
lemon_memory.c \
lemon_option.h \
@ -127,7 +129,7 @@ lemon: lemon.c \
lemon_parse.c \
lemon_report.h \
lemon_report.c
$(DSLCC) -o lemon lemon.c lemon_assert.c lemon_error.c lemon_string.c lemon_memory.c lemon_option.c lemon_action.c lemon_symbol.c lemon_plink.c lemon_parse.c lemon_report.c
$(DSLCC) -o lemon lemon.c lemon_assert.c lemon_error.c lemon_string.c lemon_set.c lemon_memory.c lemon_option.c lemon_action.c lemon_symbol.c lemon_plink.c lemon_parse.c lemon_report.c
# ----------------------------------------------------------------
clean:

View file

@ -21,6 +21,7 @@
#include "lemon_structs.h"
#include "lemon_action.h"
#include "lemon_string.h"
#include "lemon_set.h"
#include "lemon_report.h"
#include "lemon_symbol.h"
#include "lemon_plink.h"
@ -48,21 +49,6 @@ struct config *Configlist_basis(/* void */);
void Configlist_eat(/* struct config * */);
void Configlist_reset(/* void */);
/********** From the file "set.h" ****************************************/
void SetSize(/* int N */); /* All sets will be of size N */
char *SetNew(/* void */); /* A new set for element 0..N */
void SetFree(/* char* */); /* Deallocate a set */
int SetAdd(/* char*,int */); /* Add element to a set */
int SetUnion(/* char *A,char *B */); /* A <- A U B, thru element N */
#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */
/********** From the file "struct.h" *************************************/
/*
** Principal data structures for the LEMON parser generator.
*/
/**************** From the file "table.h" *********************************/
/*
** All code in this file has been automatically generated
@ -1041,66 +1027,6 @@ char *msort(char *list, char **next, int (*cmp)())
return ep;
}
/***************** From the file "set.c" ************************************/
/*
** Set manipulation routines for the LEMON parser generator.
*/
static int size = 0;
/* Set the set size */
void SetSize(n)
int n;
{
size = n+1;
}
/* Allocate a new set */
char *SetNew(){
char *s;
int i;
s = (char*)malloc (size) ;
if (s==0) {
extern void memory_error();
memory_error();
}
for(i=0; i<size; i++) s[i] = 0;
return s;
}
/* Deallocate a set */
void SetFree(s)
char *s;
{
free(s);
}
/* Add a new element to the set. Return TRUE if the element was added
** and FALSE if it was already there. */
int SetAdd(char *s, int e)
{
int rv;
rv = s[e];
s[e] = 1;
return !rv;
}
/* Add every element of s2 to s1. Return TRUE if s1 changes. */
int SetUnion(char *s1, char *s2)
{
int i, progress;
progress = 0;
for(i=0; i<size; i++){
if (s2[i]==0) continue;
if (s1[i]==0) {
progress = 1;
s1[i] = 1;
}
}
return progress;
}
/********************** From the file "table.c" ****************************/
/*
** All code in this file has been automatically generated

57
c/dsls/lemon_set.c Normal file
View file

@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lemon_set.h"
/*
** Set manipulation routines for the LEMON parser generator.
*/
static int size = 0;
/* Set the set size */
void SetSize(int n) {
size = n+1;
}
/* Allocate a new set */
char *SetNew() {
char *s;
int i;
s = (char*)malloc (size) ;
if (s==0) {
extern void memory_error();
memory_error();
}
for(i=0; i<size; i++) s[i] = 0;
return s;
}
/* Deallocate a set */
void SetFree(char *s) {
free(s);
}
/* Add a new element to the set. Return TRUE if the element was added
** and FALSE if it was already there. */
int SetAdd(char *s, int e) {
int rv;
rv = s[e];
s[e] = 1;
return !rv;
}
/* Add every element of s2 to s1. Return TRUE if s1 changes. */
int SetUnion(char *s1, char *s2) {
int i, progress;
progress = 0;
for(i=0; i<size; i++){
if (s2[i]==0) continue;
if (s1[i]==0) {
progress = 1;
s1[i] = 1;
}
}
return progress;
}

13
c/dsls/lemon_set.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef LEMON_SET_H
#define LEMON_SET_H
void SetSize(int N); /* All sets will be of size N */
char *SetNew(void); /* A new set for element 0..N */
void SetFree(char*); /* Deallocate a set */
int SetAdd(char*,int); /* Add element to a set */
int SetUnion(char *A,char *B); /* A <- A U B, thru element N */
#define SetFind(X,Y) (X[Y]) /* True if Y is in set X */
#endif // LEMON_SET_H