编译器有问题C程序的时候提示yylex有问题

> 问题详情
将目标程序(.OBJ)转换成可执行文件(.EXE)的程序称为()。A.编辑程序B.编译程序C.链接程序D.汇编
悬赏:0&答案豆
提问人:匿名网友
发布时间:
将目标程序(.OBJ)转换成可执行文件(.EXE)的程序称为()。A.编辑程序B.编译程序C.链接程序D.汇编程序请帮忙给出正确答案和分析,谢谢!
为您推荐的考试题库
您可能感兴趣的试题
1十进制数60转换成二进制数是(  )。A.0111010B.0111110C.0111100D.01111012目前使用的硬磁盘,在其读/写寻址过程中(  )。A.盘片静止,磁头沿圆周方向旋转B.盘片旋转,磁头静止C.盘片旋转,磁头沿盘片径向运动D.盘片与磁头都静止不动3一般说来,数字化声音的质量越高,则要求(  )。A.量化位数越少、采样率越低B.量化位数越多、采样率越高C.量化位数越少、采样率越高D.量化位数越多、采样率越低4当电源关闭后,下列关于存储器的说法中,正确的是(  )。A.存储在RAM中的数据不会丢失B.存储在ROM中的数据不会丢失C.存储在软盘中的数据会全部丢失D.存储在硬盘中的数据会丢失
我有更好的答案
请先输入下方的验证码查看最佳答案
图形验证:
验证码提交中……
找答案会员
享三项特权
找答案会员
享三项特权
找答案会员
享三项特权
选择支付方式:
支付宝付款
郑重提醒:支付后,系统自动为您完成注册
请使用微信扫码支付(元)
支付后,系统自动为您完成注册
遇到问题请联系在线客服QQ:
请您不要关闭此页面,支付完成后点击支付完成按钮
遇到问题请联系在线客服QQ:
恭喜您!升级VIP会员成功
常用邮箱:
用于找回密码
确认密码:《编译原理》实验报告
实验题目:设计,实现一个简单的计算器程序
实验时间:
指导教师:
实验成绩: 1 2
实验目的 1.1 实现一个简单计算器 实验要求 2.1 单词的构词规则有明确的定义; 2.2 编写的分析程序能够正确识别源程序中的语法符号; 2.3 计算器源程序的以.c格式输出 2.4 对于源程序中的词法错误,能够做出简单的错误处理,给出简单的错误提示,保证顺利完成整个源程序的词法分析,语法分析; 2.5
计算器能够实现加,减,乘,除,混合运算,多项式运算。 3 实验环境 3.1 Windows XP 3.2 Flex词法分析工具 3.3 Visual Studio C++ 6.0 实验原理 4.1 多项式计算器的实现,采用后缀表达式来对输入的计算表达式进行计算 4.2 对后缀表达式进行符号识别,词法分析,语法分析 4.3 编写计算器的源程序,使用Flex工具生成计算器的C语言程序 4.4 对生成的程序进行相应的修改,再进行编译,连接,运行,测试得到可以用于进行多项式运算的源程序。 5 软件设计与编程 5.1 程序源代码: 5.2 新建文件夹 5.3 将Flex工具复制到该文件夹下 5.4 在DOS环境学生成目标源程序 5.5 在Visual Studio C++ 6.0环境下进行相应的修改,添加main方法和打开文件的方法 6 程序测试结果 6.1 编写源代码 6.2 使用Flex生成C代码:
6.3 在Visual Studio C++6.0上运行生成的”.c”文件
文件:y.ta.h (C|c)(O|o)(S|s) log
(L|l)(O|o)(G|g) #ifndef YYTOKENTYPE tan
# define YYTOKENTYPE (T|t)(A|a)(N|n)
enum yytokentype { abs
CLEAR = 258, (A|a)(B|b)(S|s)
EXIT = 259, sqrt
LIST = 260, (S|s)(Q|q)(R|r)(T|t)
ERASE = 261,
DEC = 262, %%
HEX = 263,
OCT = 264,
HELP = 265,
NUM = 266, [\
REG = 267, {decnum}
ADD = 268,
{sscanf(yytext,\
SUB = 269, val);return(NUM); }
MUL = 270, {octnum} {
DIV = 271,
i=1;val=0;
MOD = 272,
LSHIFT = 273,
while(i<yyleng)
RSHIFT = 274,
AND = 275,
val=(val<<3)+yytext[i]-'0';
NOT = 277,
LESS = 278,
MORE = 279,
BITAND = 280,
BITOR = 281,
return(NUM);
BITXOR = 282,
BITREV = 283,
SIN = 284, {hexnum} {
COS = 285,
i=2;val=0;
TAN = 286,
ABS = 287,
while(i<yyleng)
SQRT = 288,
LOG = 289,
RMINUS = 290
if(islower(yytext[i]))
}; val=(val<<4)+yytext[i]-'a'+10; //前面定义过,此处省略宏定义
else #if ! defined (YYSTYPE) && ! if(isupper(yytext[i])) defined val=(val<<4)+yytext[i]-'A'+10; (YYSTYPE_IS_DECLARED)
else typedef int YYSTYPE; val=(val<<4)+yytext[i]-'0'; # define yystype YYSTYPE /*
i++; will be withdrawn */
} # define
yylval= YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
return(NUM); #endif
} extern YYSTYPE
文件:calc.l {reg}
if(islower(yytext[0]))yylval核心程序 =yytext[0]-'a';
else yylval=yytext[0]-'A'; %{ #define YYSTYPE
BIGINT long
return(REG); #include
} #include \
%} {opt1} { digit
[0-9a-fA-F]
switch(yytext[0]) odigit
(0(\\.{digit}+)?)|([1-9]{digit}'+': *(\\.{digit}+)?)
octnum0{odigit}+
return ADD; hexnum 0(x|X){xdigit}+
[a-zA-Z] opt1
%\\ return SUB; opt2
(&&)|(\\|\\|)|(\\<\\\\>) exit
((E|e)(X|x)(I|i)(T|t))|((Q|q)('*': U|u)(I|i)(T|t))
return MUL;
(C|c)(L|l)(E|e)(A|a)(R|r)
(L|l)(I|i)(S|s)(T|t) erase
case (E|e)(R|r)(A|a)(S|s)(E|e) '/': hex
(H|h)(E|e)(X|x)
(O|o)(C|c)(T|t)
return DIV; dec
(D|d)(E|e)(C|c) help
(H|h)(E|e)(L|l)(P|p)
(S|s)(I|i)(N|n)
{hex} {return(HEX);}
return MOD; {oct}
{return(OCT);}
{dec} {return(DEC);} {help} {return(HELP);}
'^': .|\\n
{return(yytext[0]);}
return BITXOR;
文件:y.tab.
case '&': 部分代码:
return BITAND; #define YYBISON 1
/* Skeleton name.
#define YYSKELETON_NAME
case \'|': /* Pure parsers.
#define YYPURE 0
return BITOR;
/* Using locations.
#define YYLSP_NEEDED 0
case /* Tokens.
*/ '<': #ifndef YYTOKENTYPE
# define YYTOKENTYPE
return LESS;
/* Put the tokens into the symbol
table, so that GDB debuggers
know about them.
enum yytokentype {
前面定义过,此处省略
return MORE;
case /* Copy the first part of user '!': declarations.
#line 1 \y\ return NOT; //前面定义过,此处省略宏定义
case #include
'~': #include
return BITREV; #include \lex.yy.c\ //这是词法分
析器生成的文件,必须包含! YYSTYPE reg[26]={0};
} enum Display{DEC_ON, HEX_ON,
OCT_ON}; {opt2} { enum Display dflag=DEC_ON;
switch(yytext[0])
{ /* Enabling traces.
case #ifndef YYDEBUG '&': # define YYDEBUG 0
return AND;
/* Enabling verbose error messages. */
case #ifdef YYERROR_VERBOSE '|': # undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
return OR; #else
# define YYERROR_VERBOSE 0 #endif
'<': #if ! defined (YYSTYPE) && !
return LSHIFT; (YYSTYPE_IS_DECLARED)
typedef int YYSTYPE;
# define yystype YYSTYPE /*
will be withdrawn */ '>': # define
YYSTYPE_IS_DECLARED 1
return RSHIFT; # define YYSTYPE_IS_TRIVIAL 1
/* Copy the second part of user
} declarations.
/* Line 214 of yacc.c.
#line 173 \
} #if ! defined (yyoverflow) ||
YYERROR_VERBOSE {sin}
{return (SIN);}
{return (COS);} /* The parser invokes alloca or {tan}
{return (TAN);} define the necessary {log}
{return (LOG);} symbols.
{return (ABS);}
{return (SQRT);}# if YYSTACK_USE_ALLOCA
define YYSTACK_ALLOC {clear} {return(CLEAR);}
alloca {exit} {return(EXIT);} # else {list}
{return(LIST);} #
ifndef {erase} {return(ERASE);} YYSTACK_USE_ALLOCA #
if defined (alloca) || defined (_ALLOCA_H) #
define YYSTACK_ALLOC alloca #
ifdef __GNUC__ #
define YYSTACK_ALLOC __builtin_alloca #
endif # endif
# ifdef YYSTACK_ALLOC
/* Pacify GCC's `empty if-body' warning. */ #
define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # else #
if defined (__STDC__) || defined (__cplusplus) #
/* INFRINGES ON USER NAME SPACE */ #
define YYSIZE_T size_t #
define YYSTACK_ALLOC malloc #
define YYSTACK_FREE free # endif #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
#if (! defined (yyoverflow) \\
&& (! defined (__cplusplus) \\
|| (YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member.
*/ union yyalloc {
/* The size of the maximum gap between one aligned stack and the next.
*/ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements.
*/ # define YYSTACK_BYTES(N) \\
((N) * (sizeof (short) + sizeof (YYSTYPE))
+ YYSTACK_GAP_MAXIMUM)
/* Copy COUNT objects from FROM to TO.
The source and destination do
not overlap.
*/ # ifndef YYCOPY #
if 1 < __GNUC__ #
define YYCOPY(To, From, Count) \\
__builtin_memcpy (To, From, (Count) * sizeof (*(From))) #
define YYCOPY(To, From, Count)
register YYSIZE_T
for (yyi = 0; yyi < (Count); yyi++) \\
(To)[yyi] = (From)[yyi];
while (0) #
endif # endif
/* Relocate STACK from its old location to the new one.
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
Advance YYPTR to a properly aligned location for the next
*/ # define YYSTACK_RELOCATE(Stack)
YYCOPY (&yyptr->Stack, Stack, yysize);
Stack = &yyptr->S
yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \\
yyptr += yynewbytes / sizeof (*yyptr);
#if defined (__STDC__) || defined (__cplusplus)
typedef signed char yysigned_ #else
typedef short yysigned_ #endif
/* YYFINAL -- State number of the termination state. */ #define YYFINAL
2 /* YYLAST -- Last index in YYTABLE.
*/ #define YYLAST
/* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS
40 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS
5 /* YYNRULES -- Number of rules. */ #define YYNRULES
42 /* YYNRULES -- Number of states. */ #define YYNSTATES
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.
*/ #define YYUNDEFTOK
2 #define YYMAXUTOK
#define YYTRANSLATE(YYX)
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.
*/ static const unsigned char yytranslate[] = { 省略数据信息 };
/* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yysigned_char yyrhs[] = { 省略数据信息
/* YYRLINE[YYN] -- source line where rule number YYN was defined.
*/ static const unsigned char yyrline[] = {省略数据信息 }; #endif
#if YYDEBUG || YYERROR_VERBOSE /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = {
\\\\\\\\AND\
\\\\\\AN\\
\}; #endif
# ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
token YYLEX-NUM.
*/ static const unsigned short yytoknum[] = {
省略数据信息 }; # endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.
*/ static const unsigned char yyr1[] = {
省略数据信息 };
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
STATE-NUM when YYTABLE doesn't specify something else to do.
means the default is an error.
*/ static const unsigned char yydefact[] = {
省略数据信息 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yysigned_char yydefgoto[] = {省略数据};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM.
*/ #define YYPACT_NINF -28 static const short yypact[] = {
省略数据信息 };
/* YYPGOTO[NTERM-NUM].
*/ static const yysigned_char yypgoto[] = {省略数据信息 };
/* YYTABLE[YYPACT[STATE-NUM]].
What to do in state STATE-NUM.
positive, shift that token.
If negative, reduce the rule which
number is the opposite.
If zero, do what YYDEFACT says.
If YYTABLE_NINF, syntax error.
*/ #define YYTABLE_NINF -1 static const unsigned char yytable[] = {
省略数据信息 }; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ #endif #if ! defined (YYSIZE_T) && defined (size_t) # define YYSIZE_T size_t #endif #if ! defined (YYSIZE_T) # if defined (__STDC__) || defined (__cplusplus) #
/* INFRINGES ON USER NAME SPACE */ #
define YYSIZE_T size_t # endif #endif #if ! defined (YYSIZE_T) # define YYSIZE_T unsigned int #endif
#define yyerrok
(yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY
(-2) #define YYEOF
#define YYACCEPT goto yyacceptlab #define YYABORT
goto yyabortlab #define YYERROR
goto yyerrlab1
/* Like YYERROR except do call yyerror.
This remains here temporarily
to ease the transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go.
#define YYFAIL
goto yyerrlab
#define YYRECOVERING()
(!!yyerrstatus)
#define YYBACKUP(Token, Value)
if (yychar == YYEMPTY && yylen == 1)
yychar = (Token);
yylval = (Value);
yytoken = YYTRANSLATE (yychar);
YYPOPSTACK;
yyerror (\error: cannot back up\
\\ while (0)
#define YYTERROR 1 #define YYERRCODE 256
/* YYLLOC_DEFAULT -- Compute the default location (before the actions
#ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N)
Current.first_line
= Rhs[1].first_
Current.first_column = Rhs[1].first_
Current.last_line
= Rhs[N].last_
Current.last_column
= Rhs[N].last_ #endif
/* YYLEX -- calling `yylex' with the right arguments.
#ifdef YYLEX_PARAM # define YYLEX yylex (YYLEX_PARAM) #else # define YYLEX yylex () #endif
/* Enable debugging if requested.
*/ #if YYDEBUG
# ifndef YYFPRINTF #
/* INFRINGES ON USER NAME SPACE */ #
define YYFPRINTF fprintf # endif
# define YYDPRINTF(Args)
if (yydebug)
YYFPRINTF A
\\ } while (0)
# define YYDSYMPRINT(Args)
if (yydebug)
yysymprint A
\\ } while (0)
# define YYDSYMPRINTF(Title, Token, Value, Location) \\ do {
if (yydebug)
YYFPRINTF (stderr, \Title);
yysymprint (stderr,
Token, Value); \\
YYFPRINTF (stderr, \
YY_REDUCE_PRINT(Rule) #else
\\ #endif /* !YYDEBUG */ static void } while (0) /* YYINITDEPTH -- initial size of yysymprint (yyoutput, yytype,
the parser's stacks.
*/ yyvaluep) /*-----------------------------------------#ifndef YYINITDEPTH
FILE * -------------------------. # define YYINITDEPTH 200 | yy_stack_print -- Print the state #endif
YYSTYPE * stack from its BOTTOM up to its |
#endif | TOP (cinluded).
| size the stacks can grow to
/* Pacify ``unused variable'' `-------------------------------------------(effective only warnings.
*/ -----------------------*/
if the built-in stack extension
method is used).
#if defined (__STDC__) || defined
if (yytype < YYNTOKENS) (__cplusplus)
Do not make
{ static void the results are undefined if
YYFPRINTF (yyoutput, yy_stack_print (short *bottom, short
SIZE_MAX < \*top) YYSTACK_BYTES # ifdef YYPRINT #else (YYMAXDEPTH)
YYPRINT (yyoutput, static void
evaluated with infinite-precision yytoknum[yytype], *yyvaluep); yy_stack_print (bottom, top) integer arithmetic.
*/ # endif
short * #if YYMAXDEPTH == 0
else #endif # undef YYMAXDEPTH
YYFPRINTF (yyoutput, { #endif \
YYFPRINTF (stderr, \
now\#ifndef YYMAXDEPTH
switch (yytype)
for (/* Nothing. */; bottom <= # define YYMAXDEPTH 10000
{ ++bottom) #endif
YYFPRINTF (stderr, \%d\ *bottom); #if YYERROR_VERBOSE
YYFPRINTF (stderr, \
YYFPRINTF (yyoutput, \} # ifndef yystrlen }
if defined (__GLIBC__) &&
# define defined (_STRING_H) #endif /* ! YYDEBUG */ YY_STACK_PRINT(Bottom, Top)#
define yystrlen strlen /*-----------------------------------------
else ------. do {
/* Return the length of YYSTR.
*/ | Release the memory associated to
\\ static YYSIZE_T this symbol.
if (yydebug)
if defined (__STDC__) || `-------------------------------------------
\\ defined (__cplusplus) ----*/
yy_stack_print ((Bottom), yystrlen (const char *yystr)
else #if defined (__STDC__) || defined } while (0) yystrlen (yystr) (__cplusplus) #if defined (__STDC__) || defined
const char * static void (__cplusplus) #
endif yydestruct (int yytype, YYSTYPE static void { *yyvaluep) yy_reduce_print (int yyrule)
register const char *yys = #else #else
static void static void
while (*yys++ != '\\0') yydestruct (yytype, yyvaluep) yy_reduce_print (yyrule)
YYSTYPE * #endif
return yys - yystr - 1; #endif { } { #
unsigned int yylno = # endif
yyrline[yyrule];
switch (yytype)
YYFPRINTF (stderr, \# ifndef yystpcpy
{ stack by rule %d (line %u), \#
if defined (__GLIBC__) &&
yyrule - 1, yylno); defined (_STRING_H) && defined
/* Print the symbols being (_GNU_SOURCE) reduced, and their result.
define yystpcpy stpcpy
for (yyi = yyprhs[yyrule]; 0 <= #
else } yyrhs[yyi]; yyi++) static char *
YYFPRINTF (stderr, \\#
if defined (__STDC__) || #ifdef YYPARSE_PARAM yytname [yyrhs[yyi]]); defined (__cplusplus) # if defined (__STDC__) || defined
YYFPRINTF (stderr, \%s\\n\yystpcpy (char *yydest, const char (__cplusplus) yytname [yyr1[yyrule]]); *yysrc) int yyparse (void } #
else *YYPARSE_PARAM);
yystpcpy (yydest, yysrc) # else # define
char * int yyparse (); YY_REDUCE_PRINT(Rule)
const char * # endif
endif #else /* ! YYPARSE_PARAM */ do {
{ #if defined (__STDC__) || defined
register char *yyd = (__cplusplus)
if (yydebug)
register const char *yys = int yyparse (void);
yy_reduce_print (Rule);
while ((*yyd++ = *yys++) != '\\0') int yyparse ();
\\ #endif } while (0)
#endif /* ! YYPARSE_PARAM */
return yyd - 1;
/* Nonzero means print parse trace.
It is left uninitialized so that #
multiple parsers can coexist.
*/ # endif /* The lookahead symbol.
*/ #else /* !YYDEBUG */ #endif /* !YYERROR_VERBOSE
# define YYDPRINTF(Args) */ /* The semantic value of the # define YYDSYMPRINT(Args) #if YYDEBUG lookahead symbol.
*/ # define YYDSYMPRINTF(Title, #if defined (__STDC__) || defined YYSTYPE Token, Value, Location) (__cplusplus)
# define static void /* Number of syntax errors so far.
YY_STACK_PRINT(Bottom, Top) yysymprint (FILE *yyoutput, int */ # define yytype, YYSTYPE *yyvaluep)求大佬解答,为什么这个程序编译软件检查不出错误【c语言吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:561,040贴子:
求大佬解答,为什么这个程序编译软件检查不出错误收藏
#include&ctype.h&#include&malloc.h& /* malloc()等 */#include&stdio.h& #include&stdlib.h&#include&process.h& /* exit() */#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define OVERFLOW -2typedef int S /* Status是函数的类型,其值是函数结果状态代码,如OK等 */typedef int B /* Boolean是布尔类型,其值是TRUE或FALSE */typedef int SELemTtypedef int S /* 定义栈顶元素类型,此句要在c3-1.h的前面 */typedef struct Node{SELemTstruct Node *}Node,*LinkStackP typedef struct LinkStack {
LinkStackP/*记录链栈的元素个数*/ }LinkS /* 链栈 */ /*
链栈的基本操作(9个) */ Status InitStack(LinkStack *S) { /* 构造一个空栈S */LinkStackP
p=(LinkStackPtr)malloc(sizeof( Node));
exit(OVERFLOW); /* 存储分配失败 */
p-&next=NULL;
S-&count=0;
return OK; }Status ClearStack(LinkStack *S)/*清空链栈*/{
LinkStackP
while(S-&top)
S-&top=S-&top-&
S-&count--;
return OK;} Status DestroyStack(LinkStack *S) { /* 销毁栈S,S不再存在 */
ClearStack(&*S);
return OK; } Status StackEmpty(LinkStack S) { /* 若栈S为空栈,则返回TRUE,否则返回FALSE */
return TRUE;
return FALSE; } int StackLength(LinkStack S) { /* 返回S的元素个数,即栈的长度 */
return S. } Status GetTop(LinkStack S,SELemType*e) { /* 若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR */
if(!S.top)
return ERROR;
*e=S.top-&
return OK; } Status Push(LinkStack *S,SELemType e) { /* 插入元素e为新的栈顶元素 */ LinkStackPtr p=(LinkStackPtr)malloc(sizeof(Node)); p-&data=e; p-&next=S-& S-&top=p; S-&count++; return OK;} Status Pop(LinkStack *S,SELemType *e) { /* 若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR */
LinkStackP
if(!S-&top)
return ERROR;
S-&top=S-&top-&
S-&count--;
return OK; } Status visit(SELemType a) { printf(&%d&,a); return OK; } Status StackTraverse(LinkStack S) { /* 从栈底到栈顶依次对栈中每个元素调用函error C2081: &#39;SElemType&#39; : name in formal parameter list illegal数visit() */
LinkStackP
visit(p-&data);
printf(&\n&);
return OK; }
int main() {
if(InitStack(&s))
for(i=1;i&=10;i++)
Push(&s,i);
printf(&压栈操作后,栈中元素为:\n&);StackTraverse(s);Pop(&s,&e);printf(&出栈操作后,弹出的元素为:%d\n&,e);Pop(&s,&e);printf(&再次出栈操作后,弹出的元素为:%d\n&,e);printf(&Push将刚刚弹出的元素%d再次压入栈中\n&);Push(&s,e);printf(&StackEmpty判断栈是否为空:%d(1:是
0:不是)\n&,StackEmpty(s));GetTop(s,&e);printf(&GetTop当前的栈顶元素为:%d\n&,e);printf(&StackLength:当前的栈的长度为:%d\n&,StackLength(s));ClearStack(&s);printf(&ClearStack栈清空后,StackEmpty栈是否为空:%d(1:是
0:不是)%d&,StackEmpty(s));DestroyStack(&s);printf(&DestroyStack栈销毁&);return 0; }
找c语言?来博为峰学C语言开发,C语言开发课程,免费训练营火热开启中!找c语言?来这里学C语言开发,抢!!!C语言开发课程试听名额,总监名师主讲.
先谢谢各位大佬了!!
编译器只能找出语法错误和极为有限的逻辑问题
因为你的逻辑没错,只是赋值是错了
登录百度帐号推荐应用yacc - y.tab.c: undefined reference to yylex - Stack Overflow
Join Stack Overflow to learn, share knowledge, and build your career.
or sign in with
I am trying to run an example I found online of a calculator. But I have this error showing every time I run my gcc command. Here are the commands that I run:
flex -l calc3.l
yacc -vd calc3.y
gcc y.tab.c -lm -ll
-> at this point I got this error message:
/tmp/ccPOq58f.o : In function 'yyparse':
y.tab.c: undefined reference to 'yylex'
collect2: error: ld returned 1 exit status
Here is my code:
#include &stdlib.h&
#include "calc3.h"
#include "y.tab.h"
void yyerror(char *);
yylval.sIndex = *yytext - 'a';
return VARIABLE;
yylval.iValue = atoi(yytext);
return INTEGER;
[1-9][0-9]* {
yylval.iValue = atoi(yytext);
return INTEGER;
[-()&&=+*/;{}.] {
return GE;
return LE;
return EQ;
return NE;
return WHILE;
return IF;
return ELSE;
return PRINT;
/* ignore whitespace */
yyerror("Unknown character");
int yywrap(void) {
here is calc3.h
typedef enum { typeCon, typeId, typeOpr } nodeE
/* constants */
typedef struct {
/* value of constant */
} conNodeT
/* identifiers */
typedef struct {
/* subscript to sym array */
/* operators */
typedef struct {
/* operator */
/* number of operands */
struct nodeTypeTag **
/* operands */
} oprNodeT
typedef struct nodeTypeTag {
/* type of node */
/* constants */
/* identifiers */
/* operators */
extern int sym[26];
and here is calc3.y
#include &stdio.h&
#include &stdlib.h&
#include &stdarg.h&
#include "calc3.h"
/* prototypes */
nodeType *opr(int oper, int nops, ...);
nodeType *id(int i);
nodeType *con(int value);
void freeNode(nodeType *p);
int ex(nodeType *p);
int yylex(void);
void yyerror(char *s);
int sym[26];
/* symbol table */
/* integer value */
/* symbol table index */
nodeType *nP
/* node pointer */
%token &iValue& INTEGER
%token &sIndex& VARIABLE
%token WHILE IF PRINT
%nonassoc IFX
%nonassoc ELSE
%left GE LE EQ NE '&' '&'
%left '+' '-'
%left '*' '/'
%nonassoc UMINUS
%type &nPtr& stmt expr stmt_list
{ exit(0); }
function stmt
{ ex($2); freeNode($2); }
| /* NULL */
{ $$ = opr(';', 2, NULL, NULL); }
| expr ';'
{ $$ = $1; }
| PRINT expr ';'
{ $$ = opr(PRINT, 1, $2); }
| VARIABLE '=' expr ';'
{ $$ = opr('=', 2, id($1), $3); }
| WHILE '(' expr ')' stmt
{ $$ = opr(WHILE, 2, $3, $5); }
| IF '(' expr ')' stmt %prec IFX { $$ = opr(IF, 2, $3, $5); }
| IF '(' expr ')' stmt ELSE stmt { $$ = opr(IF, 3, $3, $5, $7); }
| '{' stmt_list '}'
{ $$ = $2; }
stmt_list:
{ $$ = $1; }
| stmt_list stmt
{ $$ = opr(';', 2, $1, $2); }
{ $$ = con($1); }
| VARIABLE
{ $$ = id($1); }
| '-' expr %prec UMINUS { $$ = opr(UMINUS, 1, $2); }
| expr '+' expr
{ $$ = opr('+', 2, $1, $3); }
| expr '-' expr
{ $$ = opr('-', 2, $1, $3); }
| expr '*' expr
{ $$ = opr('*', 2, $1, $3); }
| expr '/' expr
{ $$ = opr('/', 2, $1, $3); }
| expr '&' expr
{ $$ = opr('&', 2, $1, $3); }
| expr '&' expr
{ $$ = opr('&', 2, $1, $3); }
| expr GE expr
{ $$ = opr(GE, 2, $1, $3); }
| expr LE expr
{ $$ = opr(LE, 2, $1, $3); }
| expr NE expr
{ $$ = opr(NE, 2, $1, $3); }
| expr EQ expr
{ $$ = opr(EQ, 2, $1, $3); }
| '(' expr ')'
{ $$ = $2; }
nodeType *con(int value) {
nodeType *p;
/* allocate node */
if ((p = malloc(sizeof(nodeType))) == NULL)
yyerror("out of memory");
/* copy information */
p-&type = typeC
p-&con.value =
nodeType *id(int i) {
nodeType *p;
/* allocate node */
if ((p = malloc(sizeof(nodeType))) == NULL)
yyerror("out of memory");
/* copy information */
p-&type = typeId;
nodeType *opr(int oper, int nops, ...) {
nodeType *p;
/* allocate node */
if ((p = malloc(sizeof(nodeType))) == NULL)
yyerror("out of memory");
if ((p-&opr.op = malloc(nops * sizeof(nodeType *))) == NULL)
yyerror("out of memory");
/* copy information */
p-&type = typeO
p-&opr.oper =
p-&opr.nops =
va_start(ap, nops);
for (i = 0; i & i++)
p-&opr.op[i] = va_arg(ap, nodeType*);
va_end(ap);
void freeNode(nodeType *p) {
if (p-&type == typeOpr) {
for (i = 0; i & p-&opr. i++)
freeNode(p-&opr.op[i]);
free (p-&opr.op);
void yyerror(char *s) {
fprintf(stdout, "%s\n", s);
int main(void) {
yyparse();
1,18311125
If you just use
flex -l calc3.l
then flex produces a scanner called lex.yy.c. Similarly, if you just use
yacc -vd calc3.y
the bison will produce files called y.tab.c and y.tab.h. And
gcc y.tab.c -lm -ll
will produce a file called a.out.
None of that is a good idea. It's far better to give the files meaningful names, based on the input filenames. All three of these tools understand a -o command-line flag which specifies the output name file.
So you could do this:
flex -l calc3.l
yacc -vd calc3.y
gcc lex.yy.c y.tab.c -lm -ll
But I'd recommend something like this:
flex -o calc3.lex.c -l calc3.l
bison -o calc3.tab.c -vd calc3.y
gcc -o calc3 calc3.lex.c calc3.tab.c -lm -ll
(When you do this, you'll need to change the #include "y.tab.h" to #include "calc3.tab.h".)
Even better if you put it in a Makefile, or at least a script file.
128k16105164
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 idea 编译错误提示 的文章

 

随机推荐