我试图使用野牛编译(我不知道这是否是正确的单词使用),但是当我尝试编译此源代码:看到垃圾使用野牛
%{
#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
问候。
它看起来不像野牛的输出。你的系统上的“野牛”可能不是指向实际的野牛,而是其他的东西? – 2009-10-12 00:01:36
我不知道,但这可能吗? – 2009-10-12 11:23:23
NC:你真的很幸运,你用'D:\>'提示粘贴了一行。我所有的推理都是基于看到这4个角色。 :-) – DigitalRoss 2009-10-13 01:09:33