LexYacc错误,谁能帮我看看?

Love AI 2008-11-04 08:48:50
今天第一次用LexYacc写了一个简单的parser,当链入VC++工程(6.0)时出现了如下错误,希望大伙能帮我看看,实在是没招了:

Build : warning : failed to (or don't know how to) build 'E:\程序\MyProjects\modal logic\ModalReader_vc\myparse.c'
Compiling...
《mylexer.c
.\mylexer.l(18) : error C2065: 'yylval' : undeclared identifier
.\mylexer.l(18) : error C2065: 'new' : undeclared identifier
.\mylexer.l(18) : error C2146: syntax error : missing ';' before identifier 'GFormula'
.\mylexer.l(18) : error C2065: 'GFormula' : undeclared identifier
.\mylexer.l(19) : error C2223: left of '->kind' must point to struct/union
.\mylexer.l(20) : error C2223: left of '->atom' must point to struct/union
.\mylexer.l(36) : warning C4028: formal parameter 1 different from declaration
Error executing cl.exe.

ModalReader_vc.exe - 6 error(s), 2 warning(s)

下面是原代码:
-----------------
《MainAPP.cpp》
#include "myparser.h"
#include "GeneralizedFormula.h"

GFormula *ggform;

void main()
{
}
----------------
《GeneralizedFormula.h》
#ifndef _GFormula_h_
#define _GFormula_h_

struct GFormula
{
int kind;
struct GFormula *part1;
struct GFormula *part2;
int atom;
};

#endif
---------------
《myparser.y》
%token ATOM
%token BOX
%token DIAMOND

%left BOX DIAMOND
%left '>'
%left '='
%left '|'
%left '&'
%nonassoc '!'

%{
#include "GeneralizedFormula.h"
#include "mylexer.h"

extern GFormula * ggform;

%}

// attribute type
%include {
#ifndef YYSTYPE
#define YYSTYPE GFormula *
#endif
}

%%

FILE:
FORM { ggform = $1; }
;

FORM:
ATOM
|'!' FORM { GFormula * f = new GFormula;
f->kind = -1;
f->part1 = $2;
$$ = f; }
|BOX FORM { GFormula * f = new GFormula;
f->kind = 3;
f->part1 = $2;
$$ = f; }
|DIAMOND FORM { GFormula * f = new GFormula;
f->kind = 4;
f->part1 = $2 ;
$$ = f; }
|'(' FORM ')' { $$ = $2; }
|FORM '|' FORM { GFormula * f = new GFormula;
f->kind = 2;
f->part1 = $1;
f->part2 = $3;
$$ = f; }
|FORM '&' FORM { GFormula * f = new GFormula;
f->kind = 1;
f->part1 = $1;
f->part2 = $3;
$$ = f; }
|FORM '>' FORM { GFormula * f = new GFormula;
f->kind = 5;
f->part1 = $1;
f->part2 = $3;
$$ = f; }
|FORM '=' FORM { GFormula * f = new GFormula;
f->kind = 6;
f->part1 = $1;
f->part2 = $3;
$$ = f; }
;

%%


--------------
《mylexer.l》
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "GeneralizedFormula.h"
#include "myparser.h"

void yyerror( const char * );
int string2int( char * );

char global_atom[10000][100];
int max_pos;
int i;
%}

%%

[a-zA-Z][a-zA-Z0-9]* { yylval = new GFormula;
yylval->kind = 0;
yylval->atom = string2int( yytext ) + 1;
return ATOM; }
"<>" { return DIAMOND; }
"[]" { return BOX; }
[|&!()] { return *yytext; }
"->" { return '>'; }
"<->" { return '='; }
. { yyerror( "INVALID CHARACTER !! \n" ); }
%%

void yyerror( const char * str )
{
printf( "%s", str );
}

int string2int( const char * string )
{
strcpy( global_atom[max_pos], string );
for ( i = 0; i < max_pos; i++ ) {
if ( strcmp( global_atom[i], string ) == 0 ) return i;
}
strcpy( global_atom[max_pos], string );
max_pos++;
}



...全文
166 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
18917618796 2009-07-16
  • 打赏
  • 举报
回复
老兄,咱们遇到了同样的问题,我找到解决办法了,好像是跟域有关,你在.l文件中加入extern int yylval;就可以了
Love AI 2009-01-03
  • 打赏
  • 举报
回复

a = a + 1

Love AI 2009-01-03
  • 打赏
  • 举报
回复

Love AI 2008-11-05
  • 打赏
  • 举报
回复
我没明白你的意思,我第一次使用LexYacc
lann64 2008-11-04
  • 打赏
  • 举报
回复
怎么看上去你是在用cl编译lex文件呢?
Love AI 2008-11-04
  • 打赏
  • 举报
回复
Parser Generator
lann64 2008-11-04
  • 打赏
  • 举报
回复
你用的是哪个版本?专门为vc做的?还是原始版本?原始版本是unix下的不能生成vc可编译的程序。
lann64 2008-11-04
  • 打赏
  • 举报
回复
lex&yacc 在vc下?
是bison&flex?

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧