Programming Assigment 3


  • Background:

    This assignment requires you to write a flex-style scanner for a simple four-function calculator.

  • Assigment:

    The scanner should return separate tokens for each of the following:

    • The '+' (addition) symbol [PLUS]
    • The '-' (subtraction) symbol [MINUS]
    • The '*' (multiplication) symbol [MULT]
    • The '/' (division) symbol [DIV]
    • The '(' and ')' (parentheses) [OPEN], [CLOSE]
    • Positive integers (you need not worry about negative integers, nor about floating-point values) [INTEGER]
    • The ';' (end-of-calculation) symbol [SEMI]

    Whitespace such as spaces, tabs, and newlines should not be returned. All of the above tokens are predefined for you in a file called (calc.tab.h) which you should include, and you should use these symbolic values. For any other non-whitespace character, your scanner should return the symbolic value ERROR. Your scanner should terminate when end of file is reached, and should read all input from stdin.

    Don't forget that you need to pass the parser the actual value of any integers you read in. yylval can be used for this purpose.

    You will be given a parser and driver for this assignment in object form. Link this object (calc.tab.o) with the object created by compiling your flex output into a program called calc. The resulting program, when run, should function as a 4-function calculator. You are responsible for generating appropriate test cases for your scanner, and you may wish to create an alternate driver module to do so. (Makefile)

    You may discuss this assignment with other students and work the problems together. However, your programs should be your own individual work. Remember that all assignments are to be turned in in class on the date due.

  • Note:

    For this project I need you to link in these libraries -lfl

    -lfl is for flex