Skip to content

Commit

Permalink
removed constants from lslmini.l, added constants to builtins_txt.cc,…
Browse files Browse the repository at this point in the history
… added constant parsing to builtins.cc, added two constant related errors (use as variable name, use as lvalue)
  • Loading branch information
awozniak committed May 31, 2011
1 parent 3467b0e commit 24127a6
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 495 deletions.
121 changes: 75 additions & 46 deletions builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,83 @@ LLScriptType *str_to_type(char *str) {
}

void LLScriptScript::define_builtins() {
LLScriptFunctionDec *dec = NULL;
FILE *fp = NULL;
char buf[1024];
char *ret_type = NULL;
char *name = NULL;
char *ptype = NULL, *pname = NULL;
int line = 0;

if(builtins_file != NULL) {
fp = fopen(builtins_file, "r");

if (fp==NULL) {
snprintf(buf, 1024, "couldn't open %s", builtins_file);
perror(buf);
exit(EXIT_FAILURE);
}
}
LLScriptFunctionDec *dec = NULL;
FILE *fp = NULL;
char buf[1024];
char original[1024];
char *ret_type = NULL;
char *name = NULL;
char *ptype = NULL, *pname = NULL;
int line = 0;

if(builtins_file != NULL) {
fp = fopen(builtins_file, "r");

while (1) {
if (fp) {
if (fgets(buf, 1024, fp)==NULL)
break;
} else {
if (builtins_txt[line]==NULL)
break;
strncpy(buf, builtins_txt[line], 1024);
++line;
}

ret_type = strtok(buf, " (),");
name = strtok(NULL, " (),");

if ( ret_type == NULL || name == NULL ) {
fprintf(stderr, "error parsing %s\n", builtins_file);
exit(EXIT_FAILURE);
return;
}

dec = new LLScriptFunctionDec();
while ( (ptype = strtok(NULL, " (),")) != NULL ) {
if ( (pname = strtok(NULL, " (),")) != NULL ) {
dec->push_child(new LLScriptIdentifier( str_to_type(ptype), strdup(pname)));
if (fp==NULL) {
snprintf(buf, 1024, "couldn't open %s", builtins_file);
perror(buf);
exit(EXIT_FAILURE);
}
}
}

define_symbol( new LLScriptSymbol(
strdup(name), str_to_type(ret_type), SYM_FUNCTION, SYM_BUILTIN, dec
));
}
while (1) {
if (fp) {
if (fgets(buf, 1024, fp)==NULL)
break;
} else {
if (builtins_txt[line]==NULL)
break;
strncpy(buf, builtins_txt[line], 1024);
++line;
}

strcpy(original, buf);

ret_type = strtok(buf, " (),");

if ( ret_type == NULL ) {
fprintf(stderr, "error parsing %s: %s\n", builtins_file, original);
exit(EXIT_FAILURE);
return;
}

if (!strcmp(ret_type, "const")) {
ret_type = strtok(NULL, " (),");
name = strtok(NULL, " (),");

if ( ret_type == NULL || name == NULL ) {
fprintf(stderr, "error parsing %s: %s\n", builtins_file, original);
exit(EXIT_FAILURE);
return;
}

define_symbol( new LLScriptSymbol(
strdup(name), str_to_type(ret_type), SYM_VARIABLE, SYM_BUILTIN
));
}
else if (!strcmp(ret_type, "event")) {
printf("ignoring event\n");
}
else {
name = strtok(NULL, " (),");

if ( ret_type == NULL || name == NULL ) {
fprintf(stderr, "error parsing %s: %s\n", builtins_file, original);
exit(EXIT_FAILURE);
return;
}

dec = new LLScriptFunctionDec();
while ( (ptype = strtok(NULL, " (),")) != NULL ) {
if ( (pname = strtok(NULL, " (),")) != NULL ) {
dec->push_child(new LLScriptIdentifier( str_to_type(ptype), strdup(pname)));
}
}

define_symbol( new LLScriptSymbol(
strdup(name), str_to_type(ret_type), SYM_FUNCTION, SYM_BUILTIN, dec
));
}
}
}

Loading

0 comments on commit 24127a6

Please sign in to comment.