CS 4352 - Compilers and Interpreters - Assignment L1



Comma-separated values are a commonly used, portable format for database-type data. For example, we might have
   "Nigel Ward", 41, "David Herrera", 2x
   LU, 21.3, Jan31-02, MS, 89.9, "July 18, 2001", T, 12.3, 7-26-99


Build a tokenizer for comma separated values using flex.

Test Data

test input is on the file server at /share/classes/nigelward/csv/input.csv (taken from http://ostermiller.org/utils/CSVRegressionTest.csv )

expected output is at /share/classes/nigelward/csv/output.txt (taken from http://ostermiller.org/utils/CSVRegressionTestResults.txt )

(thanks to Stephen Ostermiller)

Running Lex

Instructions for running lex (actually Flex) (courtesy of David Herrera)

Here's how you use flex on your unix machine:

First you create your file using any text editor. Save your file with a .l extension. If you are using Windows, this means type exactly: "myFile.l" in the file name. As you know, this tells Windows that it is a file of type *.l .

Assuming you have no errors, and you have imported your file to your unix account (maybe you used Secure File Transfer), you are ready to invoke flex. If your file is in the current directory, type: flex (name of your file) at your command prompt. This creates a lex.yy.c file.

% flex myflexfile.l

You can now compile this file using the c compiler by typing: gcc lex.yy.c -ll which compiles this file. To run it, type: a.out

% gcc lex.yy.c -ll
% a.out

If instead you want to save your executable other than a.out you type: gcc lex.yy.c -o (desired file name) -ll . To run it, type: (desired file name)

% gcc lex.yy.c -o Example1 -ll
% Example1

That's it. Here are two examples to get you started
Example one
Example two:

The second one is to be used in conjunction with a filename, ie.:
% a.out anyfile


Hand in a print-out of your lex code and its output on the test data, with any discrepencies circled. (diff may be helpful in detecting discrepancies.)

If you wish, include mention of how much experience each team member had with C.