still editing grammar
This commit is contained in:
@ -46,7 +46,7 @@
|
|||||||
%token <words> T_BOOLEAN 203
|
%token <words> T_BOOLEAN 203
|
||||||
%token <words> T_CHARACTER 204
|
%token <words> T_CHARACTER 204
|
||||||
%token <words> T_STRING 205
|
%token <words> T_STRING 205
|
||||||
%token <words> C_INTEGER 301
|
%token <integ> C_INTEGER 301
|
||||||
%token <words> C_NULL 302
|
%token <words> C_NULL 302
|
||||||
%token <words> C_CHARACTER 303
|
%token <words> C_CHARACTER 303
|
||||||
%token <words> C_STRING 304
|
%token <words> C_STRING 304
|
||||||
@ -120,7 +120,7 @@ prototype:
|
|||||||
|
|
||||||
definition:
|
definition:
|
||||||
TYPE ID COLON dblock
|
TYPE ID COLON dblock
|
||||||
| TYPE ID COLON constant ARROW ID
|
| TYPE ID COLON C_INTEGER ARROW ID
|
||||||
| function_declaration
|
| function_declaration
|
||||||
| TYPE ID COLON id_or_types ARROW id_or_types {
|
| TYPE ID COLON id_or_types ARROW id_or_types {
|
||||||
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6)));
|
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6)));
|
||||||
@ -160,63 +160,8 @@ declaration:
|
|||||||
id_or_types COLON ID {
|
id_or_types COLON ID {
|
||||||
TableNode* type = table_lookup(getAncestor(cur), $<words>1);
|
TableNode* type = table_lookup(getAncestor(cur), $<words>1);
|
||||||
AdInfo* info = NULL;
|
AdInfo* info = NULL;
|
||||||
|
id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
||||||
// Check for NULL type
|
|
||||||
if (type == NULL) {
|
|
||||||
printf("Error: Type '%s' not found\n", $<words>1);
|
|
||||||
} else {
|
|
||||||
// Create appropriate AdInfo based on the type
|
|
||||||
if (type == integ) {
|
|
||||||
// Integer type
|
|
||||||
info = CreatePrimitiveInfo(4); // 4 bytes for integer
|
|
||||||
}
|
|
||||||
else if (type == addr) {
|
|
||||||
// Address type
|
|
||||||
info = CreatePrimitiveInfo(8); // 8 bytes for address
|
|
||||||
}
|
|
||||||
else if (type == chara) {
|
|
||||||
// Character type
|
|
||||||
info = CreatePrimitiveInfo(1); // 1 byte for character
|
|
||||||
}
|
|
||||||
else if (type == boo) {
|
|
||||||
// Boolean type
|
|
||||||
info = CreatePrimitiveInfo(1); // 1 byte for boolean
|
|
||||||
}
|
|
||||||
else if (type == stri) {
|
|
||||||
// String type (array of characters)
|
|
||||||
info = CreateArrayInfo(1, chara); // 1-dimensional array of characters
|
|
||||||
}
|
|
||||||
else if (type == arrayprim) {
|
|
||||||
// Array type
|
|
||||||
// Need to determine dimensions and element type from context
|
|
||||||
// This is a placeholder - you'll need to adjust based on your grammar
|
|
||||||
info = CreateArrayInfo(1, NULL); // Default to 1D array of unknown type
|
|
||||||
}
|
|
||||||
else if (type == recprime) {
|
|
||||||
// Record type
|
|
||||||
// Need to determine elements from context
|
|
||||||
// This is a placeholder - you'll need to adjust based on your grammar
|
|
||||||
info = CreateRecordInfo(0, NULL); // Default to empty record
|
|
||||||
}
|
|
||||||
else if (type == funprime) {
|
|
||||||
// Function declaration
|
|
||||||
info = CreateFunctionDeclarationInfo(0, false); // Start at line 0, regular function
|
|
||||||
}
|
|
||||||
else if (type == funtypeprime) {
|
|
||||||
// Function type
|
|
||||||
// Need parameter and return types from context
|
|
||||||
// This is a placeholder - you'll need to adjust based on your grammar
|
|
||||||
info = CreateFunctionTypeInfo(NULL, NULL); // Default to no parameter/return type
|
|
||||||
}
|
|
||||||
// Add additional type cases as needed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the entry with the appropriate AdInfo
|
|
||||||
CreateEntry(cur, type, $<words>3, info);
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
// id_or_types COLON ID {CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
|
|
||||||
// ;
|
|
||||||
|
|
||||||
id_or_types:
|
id_or_types:
|
||||||
ID {printf("string of id in id_or_type is %s\n",$<words>1);} {$$ = $<words>1;}
|
ID {printf("string of id in id_or_type is %s\n",$<words>1);} {$$ = $<words>1;}
|
||||||
@ -258,23 +203,30 @@ expression:
|
|||||||
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
|
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
|
||||||
printf("mismatch at line %d and column %d\n",@1.first_line,@1.first_column);}}
|
printf("mismatch at line %d and column %d\n",@1.first_line,@1.first_column);}}
|
||||||
| expression ADD expression {printf("add expression\n");}
|
| expression ADD expression {printf("add expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");
|
||||||
|
if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
|
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression MUL expression {printf("multiply expression\n");}
|
| expression MUL expression {printf("multiply expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression DIV expression {printf("division expression\n");}
|
| expression DIV expression {printf("division expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
| expression REM expression {printf("remainder expression\n");}
|
| expression REM expression {printf("remainder expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression AND expression {printf("and expression\n");}
|
| expression AND expression {printf("and expression\n");}
|
||||||
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean"); else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
{printf("less than expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("Boolean");
|
||||||
|
else{printf("mismatch at line %d and column %d\n",@2.first_line,@2.first_column);
|
||||||
$$=strdup("Boolean");$$=strdup("undefined");}}
|
$$=strdup("Boolean");$$=strdup("undefined");}}
|
||||||
|
|
||||||
| expression OR expression {printf("or expression\n");}
|
| expression OR expression {printf("or expression\n");}
|
||||||
@ -316,7 +268,7 @@ memOp:
|
|||||||
|
|
||||||
constant:
|
constant:
|
||||||
C_STRING {$$ = $<words>1;}
|
C_STRING {$$ = $<words>1;}
|
||||||
| C_INTEGER {$$ = $<words>1;}
|
| C_INTEGER {$$ = "integer";}
|
||||||
| C_NULL {$$ = $<words>1;}
|
| C_NULL {$$ = $<words>1;}
|
||||||
| C_CHARACTER {$$ = $<words>1;}
|
| C_CHARACTER {$$ = $<words>1;}
|
||||||
| C_TRUE {$$ = $<words>1;}
|
| C_TRUE {$$ = $<words>1;}
|
||||||
|
@ -72,7 +72,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
||||||
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
||||||
|
|
||||||
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.words = strdup("integer");return C_INTEGER;}}
|
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.integ = atoi(yytex)/*words = strdup("integer")*/;return C_INTEGER;}}
|
||||||
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);yylval.words = strdup("character");return C_CHARACTER;}}
|
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);yylval.words = strdup("character");return C_CHARACTER;}}
|
||||||
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);yylval.words = strdup("string");return C_STRING;}}
|
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);yylval.words = strdup("string");return C_STRING;}}
|
||||||
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
||||||
|
@ -199,7 +199,7 @@ TableNode* setRecSize(TableNode* tn, int n){
|
|||||||
printf("passed in NULL entry for setRecSize. Invalid\n");
|
printf("passed in NULL entry for setRecSize. Invalid\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tn->AdInfo->RecAdInfo->numofelements = n;
|
tn->additionalinfo->RecAdInfo->numofelements = n;
|
||||||
return tn;
|
return tn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user