GNU bison

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
(Allen移动GNU Bison页面至GNU bison)
(未显示1个用户的1个中间版本)
第1行: 第1行:
 
{{SeeWikipedia}}
 
{{SeeWikipedia}}
  
GNU Bison is a free parser generator computer program written for the GNU project, and available for virtually all common operating systems. It is mostly compatible with Yacc, and offers several improvements over the earlier program. It is commonly used in conjunction with flex.
+
GNU bison是一个自由软件,用于自动生成语法分析器程序,实际上可用于所有常见的操作系统。Bison把LALR形式的上下文无关文法描述转换为可做语法分析的C或C++程序。在新版本中,Bison增加了对GLR语法分析算法的支持。
  
Bison converts a grammar description for a LALR context-free grammar into a C or C++ program to parse that grammar.
+
GNU bison基本兼容[[Yacc]],并做了一些改进。它一般与[[flex]]一起使用。
 
+
http://www.gnu.org/software/bison/
+
  
 
==Examples==
 
==Examples==
第46行: 第44行:
 
bison parse.y
 
bison parse.y
  
[[Category:GNU]]
+
==链接==
 +
*[http://www.gnu.org/software/bison/ GNU bison主页]
 +
 
 +
[[category:GNU]]

2014年11月20日 (四) 02:39的版本

Wikipedia-35x35.png 您可以在Wikipedia上了解到此条目的英文信息 GNU bison Thanks, Wikipedia.

GNU bison是一个自由软件,用于自动生成语法分析器程序,实际上可用于所有常见的操作系统。Bison把LALR形式的上下文无关文法描述转换为可做语法分析的C或C++程序。在新版本中,Bison增加了对GLR语法分析算法的支持。

GNU bison基本兼容Yacc,并做了一些改进。它一般与flex一起使用。

Examples

touch parse.y

%{
#include<stdio.h>
%}
%token NUM
%left '+' '-'
%left '*' '/'
%start line 
%%

line:

     /* empty */ 
     |line exp '\n' {printf("%d\n",$2);}
     | error '\n';
exp:      exp '+' exp {$$ = $1 + $3;}
        | exp '*' exp {$$ = $1 * $3;}
        | exp '-' exp {$$ = $1 - $3;}
        | exp '/' exp { if ($3 == 0)
                                $$ = 0;
                        else
                                $$ = $1/$3;}
        | NUM          {$$ = $1;};
%%
yyerror()
{
        printf("Error detected in parsing\n");
}
main()
{
        yyparse();
}

bison parse.y

链接

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱