免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2802 | 回复: 8
打印 上一主题 下一主题

着急死了,lex文件编译不过。。郁闷死了。高手拜托帮忙指点下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-23 21:03 |只看该作者 |倒序浏览
lex chk.l
cc -g -c lex.yy.c
lex.yy.c:567:24: 错误:宏input传递了 1个参数,但只需要 0 个


%{
#include "y.tab.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

extern int yylval;
extern char *chkexpstr;
extern int opt;
extern int parentheses;

#ifdef USE_FLEX
    #undef YY_INPUT
    #define YY_INPUT(buf,result,max_size) \
                { \
                int c = '*', n; \
                for ( n = 0; n < max_size && \
                             (c = toupper(*(chkexpstr++))) != '\0'; ++n ) \
                        buf[n] = (char) c; \
                result = n; \
                }
#else
    #undef input
    #undef unput
    #define input() (toupper(*(chkexpstr++)))
    #define unput(c) (*(--chkexpstr)=c)
#endif

%}

%%
A[0-9]+    {
              yylval = atoi (yytext+1);
              return NUMBER;
          }

\!       {
              opt = NOT;
              return NOT;
          }

\&\&       {
              opt = AND;
              return AND;
          }

\|\|        {
              opt = OR;
              return OR;
          }

\(         {
              parentheses += 1;
              return '(';
          }

\)         {
              parentheses -= 1;
              return ')';
          }

[ \t] ;
.         {
             return (yytext[0]);
          }
%%

论坛徽章:
0
2 [报告]
发表于 2010-06-23 21:11 |只看该作者
补充下在suse linux系统

论坛徽章:
0
3 [报告]
发表于 2010-06-24 09:23 |只看该作者
今天换了个系统,我在scounix上编译又是成功的。哎。

论坛徽章:
0
4 [报告]
发表于 2010-06-24 14:56 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2010-06-30 14:39 |只看该作者
为什么这样呢。suse linux为什么编译不过。而SCO编译却成功的。问题出在哪儿呢。哪个高手谢谢指点一二

论坛徽章:
0
6 [报告]
发表于 2010-07-01 08:26 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
7 [报告]
发表于 2010-07-01 13:00 |只看该作者
顶一下LZ。你没有给出yacc文件,不好测啊,全是报错。

论坛徽章:
0
8 [报告]
发表于 2010-07-22 15:21 |只看该作者
%{
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

extern int yylex(void);
extern void yyerror(char *msg);

extern int opt;
extern int parentheses;
extern char * chkexpstr;
extern int CHK_ExprCalc (int iExprId);

static int ign = 0;
%}

%token NUMBER NOT AND OR
%left OR
%left AND
%left NOT
%nonassoc UMINUS

%%
statment: expression   
            {
                return ($1 << 4);
            }
expression: expression OR { ign = $1 ? 1 : ign; } expression
            {
                if (ign) {
                    $$ = 1;
                } else {
                    $$ = $1 || $4;
                }
                ign = 0;
            }
      |     expression AND { ign = $1 ? ign : 1; } expression
            {
                if (ign) {
                    $$ = 0;
                } else {
                    $$ = $1 && $4;
                }
                ign = 0;
            }
      |     NOT expression            
            {
                $$ = !$2;
            }
      |     '(' expression ')'        
            {
                $$ = $2;
            }
      |     NUMBER                    
            {
                if (!ign) {
                    $$ = CHK_ExprCalc ($1);
                } else {
                    $$ = 0;
                }
            }
      ;
%%

void yyerror(char* msg)
{
      printf("error: %s encountered \n", msg);
}

/***
main (int argc, char *argv[])
{
    int i;
    for (i = 1; i < argc ; i++) {
        opt = 0;
        parentheses = 0;
        chkexpstr = argv[i];
        printf ("ret %d\n", yyparse());
        //printf ("ret %d\n", yylex());
    }
}
***/

顶楼上的。。这里付上yacc,帮忙测试看看。

论坛徽章:
0
9 [报告]
发表于 2010-07-23 09:20 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP