During this activity, students will be able to:
NOTE: This is an in-class exercise. No submission is required.
Write a program in Clojure that receives the name of a text file containing arithmetic expressions and comments as input. The program should print a table with each of the lexical units (tokens) found, in the order they were encountered, indicating their category. The program must be implemented using the Regular Expression API.
Arithmetic expressions may only contain the following categories of tokens:
=)+)-)*)/)^)(])]// followed by characters until the end of the line.Example:
b=7 a = 32.4 *(-8.6 - b)/ 6.1E-8 d = a ^ b // This is a comment
The previous example should produce the following output:
======================================================== Token Category ======================================================== b variable = assignment 7 integer a variable = assignment 32.4 float * multiplication ( opening-parenthesis -8.6 float - subtraction b variable ) closing-parenthesis / division 6.1E-8 float d variable = assignment a variable ^ power b variable // This is a comment comment ========================================================
_).10. or 10.0).E (upper or lowercase); however, the E must be followed only by a positive or negative integer (e.g. 2.3E3, 6.345e-5, -0.001E-3, 0.467E9).// and everything following it until the end of the line is considered a comment.