2016-03-30 11 views
-2

Ich baue eine rekursive Sprache, aber ich habe Schwierigkeiten mit einem undefinierten Referenzfehler. (Dieses Programm ist noch weitgehend unfertig)C: undefinierter Referenzfehler

Wie kann ich meine Header-Datei so strukturieren, dass dieser Fehler behoben ist?

Fehler

/tmp/cc4CBg4R.o: In function `morestmts': 
main.c:(.text+0x197): undefined reference to `stmtlist' 
collect2: error: ld returned 1 exit status 

head.h

#include "stdio.h" 
#include "string.h" 
#include "stdbool.h" 

char file[4096][20]; 
int cur = 0; 
int lines = 0; 
bool test = true; 

void digit(); 
void variable(); 
void expr(); 
void testexpr(); 
void whilestmt(); 
void ifstmt(); 
void assign(); 
void morestmts(); 
void stmt(); 
void stmlist(); 
void block(); 
void program(); 
int singleCharCheck(char check); 
void trim(char * s); 

main.c

#include "head.h" 

int main(){ 
int x=0; 
while(fgets(file[x], 20, stdin) && x < 4096){ 
    trim(file[x]); 
    x++; 
    if(test){printf("%d = %s\n",x,file[x-1]);} 
} 
lines = x; 

program(); 

return 0; 
} 

void digit(){ //1 | 2 | 3 
} 

void variable(){ //a | b | c 
} 

void expr(){ //+ [expr] [expr] | * [expr] [expr] 
//operator 
expr(); 
expr(); 
} 

void testexpr(){ //[variable] <= [expr] 
variable(); 
// <= 
expr(); 
} 



void whilestmt(){ //while [testexpr] do [stmt] 
//while 
testexpr(); 
//do 
stmt(); 
} 

void ifstmt(){ //if [testexpr] then [stmt] else [stmt] 
// if 
testexpr(); 
// then 
stmt(); 
//else 
stmt(); 
} 

void assign(){ //[variable] = [expr] 
variable(); 
// = 
expr(); 
} 

void stmt(){ //[assign] | [ifstmt] | [whilestmt] 
assign(); 
ifstmt(); 
whilestmt(); 
} 

void morestmts(){ //; [stmtlist] | 
// ; 
stmtlist(); 
// | 
} 

void stmlist(){ //[stmt] [morestmts] 
stmt(); 
morestmts(); 
} 

void block(){ //begin [stmlist] end 
if(strcmp(file[cur],"begin") == 0){ 
    cur++; 
    stmlist(); 
    if(strcmp(file[cur],"end") == 0){ 
    } else { 
    printf("%d ERROR: no \"end\" on your block\n",cur); 
    } 
} else { 
    printf("%d ERROR: no \"begin\" where there should be\n",cur); 
} 
} 

void program(){ // program : program [block] . 
if(strcmp(file[cur],"program") == 0){ 
    cur++; 
    block(); 
    if(singleCharCheck('.') == 1){ 
    } else { 
    printf("%d ERROR: symbol \".\" missing at end of program\n"); 
    } 
} else { 
    printf("\n%d ERROR: keyword \"program\" not located\n",cur); 
} 
} 

int singleCharCheck(char check){ 
int i; 
for(i = 0; i < strlen(file[cur]); i++){ 
    if(file[cur][i] == check){ 
    return 1; 
    } 
} 
return 0; 
} 

void trim(char * s) { 
    char * p = s; 
    int l = strlen(p); 

    while(isspace(p[l - 1])) p[--l] = 0; 
    while(* p && isspace(* p)) ++p, --l; 

    memmove(s, p, l + 1); 
} 

Antwort

0

Sie haben stmtlist()-mis eingegeben haben. Es sollte stmlist() sein.

Verwandte Themen