美文网首页
[配置] WinFlexBison VS2017

[配置] WinFlexBison VS2017

作者: CrazyTiger | 来源:发表于2018-04-02 15:05 被阅读0次

配置过程

  • 下载
    https://sourceforge.net/projects/winflexbison/?source=typ_redirect
  • 解压缩
    D:\WorkSpace\3_FlexBison\win_flex_bison-latest


    解压缩出来的文件
  • 新建MFC工程
    把FirstTry.cpp移除,因为后面的定义的Parser.y文件里面定义了一个main,这个main会生成到Parser.tab.cpp中。


    image.png
  • 生成依赖项


    生成依赖项

    按图示点击其上的查找现有的按钮,然后找到你下载的WinFlexBison工具的解压目录中的custom_build_rules目录下的win_flex_bison_custom_build.targets。

  • 设置可执行目录
    D:\WorkSpace\3_FlexBison\win_flex_bison-latest
    可执行目录
  • 新建Parser.y
%{

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

#define YYSTYPE  double

void yyerror(const char *text);

int yylex(void);
%}

/////////////////////////////////////////////////////////////////////////////
// declarations section
// place any declarations here

%token NUMBER

%left '+' '-'
%left '*' '/'
%right '^'
%%

/////////////////////////////////////////////////////////////////////////////
// rules section
// place your YACC rules here (there must be at least one)
command : exp {printf("%lf\n",$1);}
    ;

exp     : NUMBER         {$$ = $1;}
       | exp '+' exp     {$$ = $1 + $3;}
       | exp '-' exp     {$$ = $1 - $3;}
       | exp '*' exp     {$$ = $1 * $3;}
       | exp '/' exp     {
                            if(0 != $3)
                            {
                               $$ = $1 / $3;
                            }
                            else
                            {
                               $$=0;
                            }
                        }
       | exp '^' exp     {$$ = pow($1,$3);}
       | '(' exp ')'     {$$ = $2;}
    ;
%%

/////////////////////////////////////////////////////////////////////////////
// programs section

int yylex(void)
{
   // place your token retrieving code here
   int c = 0;

   while( (c = getchar()) == ' ');
   if( isdigit(c) )
   {
       ungetc(c,stdin);
       scanf_s("%lf",&yylval);
       return (NUMBER);
   }

   if( '\n' == c )
   {
       return 0;
   }
   return c;
}

int main(void)
{
    yyparse();
    system("PAUSE");
    return 0;
}

void yyerror(const char *text)
{
   fprintf(stderr,"%s\n",text);
}
  • 编译
    生成Parser.tab.h和Parser.tab.c,把这两个文件加入到工程里面。注意要设置Parser.tab.c不使用预编译头。


    不使用预编译头
  • 再次编译运行


    运行
  • 编译效果
    Yacc编译Parser.y -> 生成Parser.tab.h和Parser.tab.cpp。
    C/C++编译链接Parser.tab.h和Parser.tab.cpp -> FirstTry.exe。


    image.png

参考

相关文章

  • [配置] WinFlexBison VS2017

    配置过程 下载https://sourceforge.net/projects/winflexbison/?sou...

  • 配置 WinFlexBison VS2017

    WinFlexBison 下载地址:https://sourceforge.net/projects/winfle...

  • VS + opencv

    配置 (博客标题:VS2017配置opencv教程(超详细!!!))https://blog.csdn.net/q...

  • OpenCV VS 2017 环境

    开发环境搭载: (1)VS2017版本 (2)OpenCV 3.3.0版本 (3)配置环境变量和在VS2017中引...

  • Qt5.9 + VS2017 开发环境配置

    配置环境:win10 + Qt5.9 开源版+ VS2017社区版 1、下载VS2017 这个到微软官网下载就可以...

  • Windows 10 下配置 VS 2017 环境变量

    参考链接:Windows10下配置VS2017环境变量

  • 2018-11-17

    这几天在vs2017中配置opencv和yolov3 1.配置opencv的链接:https://blog.csd...

  • vs2017安装GDAL

    相关配置 win10vs2017 communitygdal 2.2.2 步骤 1.安装vs2017 commun...

  • ABP MPA

    环境说明 VS2017 SqlServer2014 ABP MPA 基础配置 官方模板: 下载模板 还原Nuget...

  • halcon(C++)vs2017配置

    简介:本篇文章包含halcon (C++)在vs2017中的配置和简单的示例。 1.新建项目 2.配置halcon...

网友评论

      本文标题:[配置] WinFlexBison VS2017

      本文链接:https://www.haomeiwen.com/subject/pnvthftx.html