flex

Published on November 2016 | Categories: Documents | Downloads: 60 | Comments: 0 | Views: 477
of 1
Download PDF   Embed   Report

Comments

Content

CS 351 : Using flex and Cygwin
Using Cygwin in Olsson 001
The Cygwin package provides a complete Unix environment from within a Windows PC. The machines in the Olsson 001 lab have Cygwin installed. After double-clicking on the Cygwin icon, a Unix console window appears with a command-line prompt. The default present working directory can be displayed with the pwd command, and for username abc2z it would be /cygdrive/c/Documents and Settings/abc2z (it might end in abc2z.CSLAB instead of just abc2z, depending on the machine configuration). Notice that the prefix /cygdrive/ c/ corresponds to the Windows C:\ prefix. If you created a Visual Studio project in directory C:\cs351, you can find those files starting at /cygdrive/c/cs351. The Olsson 001 machines also have version 2.5.4 of the flex utility installed in Cygwin. If you have a flex file called patterns.l, you can process it with flex by using the command flex patterns.l on the Cygwin command line. More details about flex are found below.

Using Cygwin on your own PC
The Cygwin package for Windows can be found at http://www.cygwin.com/. The flex 2.5.4 package for Cygwin can be found using the internal search for software packages feature at the Cygwin web site. Just enter “flex” in the search field. After you install Cygwin and then flex-2.5.4 you will be able to complete all flex assignments on your own PC.

Using Dumpbin Output in Cygwin
If you use DUMPBIN in a Visual Studio Tools window to produce a disassembled version of an executable file, the file will use the DOS carriage return/line feed convention to mark the end of each line. This sequence of hidden characters will not match the ‘\n’ newline symbol in a flex pattern. To convert from DOS to Unix newline format, use the dos2unix utility under Cygwin, e.g. dos2unix patterns.disasm will convert the file patterns.disasm in place. Running dos2unix again on the same file has no effect, so if you have any doubt, run dos2unix over your input file before you spend hours debugging your flex pattern file.

Using flex in Cygwin
When you process your flex pattern file, e.g. flex patterns.l, it produces a C code output file called lex.yy.c in the same directory that you are working in. This can be compiled and linked using the gcc compiler within Cygwin, e.g. gcc -o patterns.out lex.yy.c -lfl. The “-lfl” tells gcc to use the “fl” library during the linking step. This is the library that supports flex at runtime. You should then be able to run your flex program over the disassembled code by using redirection of input, e.g. patterns.out < patterns.disasm.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close