加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[ZZ]bison flex for windows 使用说明

发布时间:2020-12-15 04:57:46 所属栏目:百科 来源:网络整理
导读:you will need the lastest versions of: flex-2.5.4a-1.exe bison-2.4.1-setup.exe After that,do a full install in a directory of your preference? without spaces in the name . I suggest C:GnuWin32 . Do? not ?install it in the? default ?(C:Pr

you will need the lastest versions of:

  1. flex-2.5.4a-1.exe

  2. bison-2.4.1-setup.exe

  3. After that,do a full install in a directory of your preference?without spaces in the name. I suggestC:GnuWin32. Do?not?install it in the?default?(C:Program Files (x86)GnuWin32) because bison has problems with spaces in directory names,not to say parenthesis.

  4. Also,consider installing?Dev-CPP?in the default directory (C:Dev-Cpp)

  5. After that,set the PATH variable to include the bin directories of?gcc?(in?C:Dev-Cppbin) andflexbison?(in?C:GnuWin32bin). To do that,copy this:?;C:Dev-Cppbin;C:GnuWin32bin?and append it to the end of the?PATH?variable,defined in the place show by this figure:

    step-by-step to set PATH variable under Win-7.


    If the figure is not in good resolution,you can see a?step-by-step here.

  6. Open a prompt,cd to the directory where your ".l" and ".y" are,and compile them with:

    1. flex hello.l
    2. bison -dy hello.y
    3. gcc lex.yy.c y.tab.c -o hello.exe

Commands to create lexical analyzer,parser and executable.

You will be able to run the program. I made the sources for a simple test (the infamous?Hello World):

Hello.l

? %{ ? #include <stdlib.h>"y.tab.h" ? %}%%("hi"|"oi")"n" ? ? ? { return HI; ?}"tchau""bye" BYE . ? ? ? ? ? ? ? ? ? ?  yyerror(); ? int main(void) ? ? ?yyparse ? ? ? 0 yywrap ? ? ? printf"Errorn"); ? ? ? exit(1 

Hello.y

%token HI BYE  program: ? ? ? ? ?hi bye ? ? ? ?  hi ? ? ? ? ? ? HI ? ?  printf"Hello Worldn" ? ? ? ?  bye ? ? ? ? ? ? BYE ? ?"Bye Worldn" exit ? ? ? ? ?;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读