gpt4 book ai didi

C : Undefined reference error

转载 作者:行者123 更新时间:2023-11-30 19:39:36 25 4
gpt4 key购买 nike

我正在构建一种递归语言,但我遇到了 undefined reference 错误。 (这个程序基本上还没有完成)

如何构建我的头文件以修复此错误?

错误

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

头.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);
}

最佳答案

您输入了错误的 stmtlist()。它应该是 stmlist()

关于C : Undefined reference error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36299618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com