#include #include #include #include #include #include #include #include "lemon-lexer.h" #include "lemon-conf.h" void *ParseAlloc(void *(*mallocProc)(size_t)); void ParseTrace(FILE *, char *); void Parse(void *yyp,int yymajor,char *tokenvalue); char *memorymap_file(char *file) { struct stat buf; int ret = stat(file,&buf); if(ret == -1) { fprintf(stderr,"Error stating file '%s'\n",file); exit(2); } if(!S_ISREG(buf.st_mode)) { fprintf(stderr,"'%s' is not a regular file\n",file); exit(3); } int fd = open(file,O_RDONLY); if(fd < 0) { fprintf(stderr,"Error opening file '%s'\n",file); exit(4); } char *map = (char *)mmap(NULL,buf.st_size+1,PROT_READ|PROT_WRITE,MAP_PRIVATE, fd,0); if(map == MAP_FAILED) { fprintf(stderr,"Error mapping file '%s'\n",file); exit(5); } return(map); } void parse(char *file) { char *starts = memorymap_file(file); void *Parser = ParseAlloc(malloc); // ParseTrace(stdout, "PARSER SAYS: "); char *token = NULL; int token_type = 0; lexer_init(starts); while(lexer_token(&token,&token_type)) { // printf("Token is '%s', token_type = %d\n",token,token_type); Parse(Parser,token_type,token); // free(token); ---> not when you are passing tokens up... } Parse(Parser,0,NULL); } int main(int argc, char **argv) { parse(argv[1]); }