2009-10-11 26 views
1

我试图使用野牛编译(我不知道这是否是正确的单词使用),但是当我尝试编译此源代码:看到垃圾使用野牛

%{ 
#define YYSTYPE double 
#include <math.h> 
#include <stdio.h> 
%} 
%token NUM 
%% 
input: /* empty */ 
     | input line 
; 

line:  '\n' 
     | exp '\n' { printf ("\t%.10g\n", $1); } 
; 

exp:  NUM    { $$ = $1;   } 
     | exp exp '+'  { $$ = $1 + $2; } 
     | exp exp '-'  { $$ = $1 - $2; } 
     | exp exp '*'  { $$ = $1 * $2; } 
     | exp exp '/'  { $$ = $1/$2; } 
     /* Exponentiation */ 
     | exp exp '^'  { $$ = pow ($1, $2); } 
     /* Unary minus */ 
     | exp 'n'   { $$ = -$1;  } 
; 
%% 

/* Lexical analyzer returns a double floating point 
    number on the stack and the token NUM, or the ASCII 
    character read if not a number. Skips all blanks 
    and tabs, returns 0 for EOF. */ 

#include <ctype.h> 
#include <stdio.h> 

yyerror(const char *s) 

yylex() 
{ 
    int c; 

    /* skip white space */ 
    while ((c = getchar()) == ' ' || c == '\t') 
    ; 
    /* process numbers */ 
    if (c == '.' || isdigit (c))     
    { 
     ungetc (c, stdin); 
     scanf ("%lf", &yylval); 
     return NUM; 
    } 
    /* return end-of-file */ 
    if (c == EOF)        
    return 0; 
    /* return single chars */ 
    return c;         
} 

yyerror (s) /* Called by yyparse on error */ 
    char *s; 
{ 
    printf ("%s\n", s); 
} 

main() 
{ 
    yyparse(); 
} 

我越来越控制台(而不是在一个文件或类似的东西),看看一些“垃圾”:http://pastie.org/650893

问候。

+1

它看起来不像野牛的输出。你的系统上的“野牛”可能不是指向实际的野牛,而是其他的东西? – 2009-10-12 00:01:36

+0

我不知道,但这可能吗? – 2009-10-12 11:23:23

+1

NC:你真的很幸运,你用'D:\>'提示粘贴了一行。我所有的推理都是基于看到这4个角色。 :-) – DigitalRoss 2009-10-13 01:09:33

回答

1

这是一个m4输入文件或m4头。野牛和flex使用古老的unix宏处理器工具m4,这就是m4输入的样子。 (我可以让m4 -P只用警告来吃那个文件。)

通常,这一切都在幕后运行,并且是不可见的。你似乎在窗户上,并在一个dos框外壳。我猜测你有一个真正的bash控制台,可能是通过Cygwin,我建议在完整的gnu环境中重试bison命令。它可能没那么麻烦。 Windows在模拟标准输出流方面特别差,并且谁知道可能发生了什么。

如果这样做没有直接帮助,至少可以提供更多有关您的环境的信息,请描述如何构建或安装野牛,或者粘贴您正在使用的命令行。

+0

非常感谢,现在都在工作! – 2009-10-12 12:22:08