如何修复此错误:无法识别的规则 [英] How can I fix this error: unrecognized rule
本文介绍了如何修复此错误:无法识别的规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用flex中的列表编写一个简单的程序,但它在第22行显示错误,我无法理解它。你能帮帮我吗?
这里代码
Im writing a simple progamm using the lists in flex but it shows an error in line 22 and i cant understand it.Can you pls help me ?
Here the code
%{
#include<stdio.h>
%}
%%
typedef struct liste{
char * cle;
int data;
struct liste * svt;
} noeud, *liste;
liste inserer( char * k )
{
liste aux;
aux = ts;
while ( aux ){
if ( strcmp( aux->cle, k ) == 0 )
return aux;
aux = aux -> svt;
}
printf("\nInsertion...");
aux = ( liste ) malloc( sizeof(noeud) );
aux->cle = (char *) malloc( strlen(k) + 1 );
strcpy( aux->cle, k ); //LIGNE 22
aux->data = 0;
aux->svt = ts;
ts = aux;
return ts;
}
我的尝试:
我试着删除这些空格,这就是
What I have tried:
I tried deleting the spaces and that is all
推荐答案
第一个问题是你的代码在一个它不应该的地方,因为错位%
。
您对指针与指针指向的数据之间的区别感到非常困惑。
我在代码中看到至少6个错误。
[法语]
D'aprèsceque je vois,tu brulelesétapes,et c'est pas bon。
Conseil:
- laissedecotéflexpour l'instant。
- apprend correctement le langage C en lisant la documentation et en suivant les exemples et les tutoriels(il vaut mieux trop que pas assez)。
- quand tu maitrisera,tu pourrareveniràflex。
pour flex :
- prend aussi le temps d'apprendre,开始avec des sujets que tu maitrise。
- pour ton projet,essayededébugg er ton code avant de l'intégrerdanston projet Flex。
The first problem is that your code is at a place it should not be, because of misplaced%
.
You are very confused about the difference between a pointer and the data pointed by a pointer.
I see at least 6 errors in the code.
[French]
D'après ce que je vois, tu brule les étapes, et c'est pas bon.
Conseil:
- laisse de coté flex pour l'instant.
- apprend correctement le langage C en lisant la documentation et en suivant les exemples et les tutoriels (il vaut mieux trop que pas assez).
- quand tu maitrisera, tu pourra revenir à flex.
pour flex:
- prend aussi le temps d'apprendre, commence avec des sujets que tu maitrise.
- pour ton projet, essaye de débugger ton code avant de l'intégrer dans ton projet Flex.
您对类型和一个对象使用相同的名称(liste
)但是对象是指针而类型不是。因此,您应该为指针使用不同的名称,并将其用于您的变量:
You are using the same name for the type and one object (liste
) but the object is a pointer while the type is not. So you should use a different name for the pointer and use that for your variable:
typedef struct liste{
char * cle;
int data;
struct liste * svt;
} noeud, *pliste;
pliste inserer( char * k )
{
pliste aux;
/* ... */
aux = ( pliste ) malloc( sizeof(noeud) );
文件格式不是有效的 flex 文件,因为缺少规则和用户代码之间的分隔符。如果没有规则,只需插入一行:
The file format is not a valid flex file because the separator between rules and user code is missing. If there are no rules just insert the line:
%{
#include<stdio.h>
#include<string.h>
%}
%%
/* Rules */
%%
/* User code*/
typedef struct liste{
/* ... */
[/ EDIT]
添加了上面的 string.h 以使编译器满意/>
[/ EDIT]
[/EDIT]
Added inclusion of string.h above to make the compiler happy.
[/EDIT]
这篇关于如何修复此错误:无法识别的规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文