FloridaTech - College of Engineering
CSE1001 - LABORATORY

Author: Jamal Faik

Lab Assignment 9: Simplified IF_EXPRESSIONs.

In this lab, you will have to write a procedure recognize_tokens that takes as argument a string representing an IF_EXPRESSION and output all the tokens composing it. An IF_EXPRESSION is defined as follows:

IF_EXPRESSION ::= if EXPRESSION then
EXPRESSION ::= ARITHMETIC_EXPR COMPRAISON_OP ARITHMETIC_EXPR | BOOLEAN_IDENTIFIER
ARITHMETIC_EXPR ::= MULTIPLICATIF_TERM ADD_OP ARITHMETIC_EXPR | MULTIPLICATIF_TERM
MULTIPLICATIF_TERM ::= IDENTIFIER_OR_NUMBER MUL_OP MULTIPLICATIF_TERM | IDENTIFIER_OR_NUMBER
BOOLEAN_IDENTIFIER ::= IDENTIFER
IDENTIFIER_OR_NUMBER ::= IDENTIFIER | NUMBER
NUMBER ::= DIGIT | DIGIT NUMBER
IDENTIFIER ::= LETTER {LETTER | DIGIT}
LETTER ::= A | a | B | b | ...... Z | z
DIGIT ::= 1 | 2 | 3 | 4 | 5 | 5 | 6 | 7 | 8 | 9 | 0
COMPARAISON_OP ::= < | <= | >= | > | /= | =
ADD_OP ::= + | -
MUL_OP ::= * | /

The tokens to be recognized are : IF, THEN, IDENTIFER, ADD_OP, MUL_OP, NUMBER, END_OF_STRING. Your program must detect syntax/lexical errors and in this case, should output an appropriate error-message. Spaces are considered as token separator and should be skipped.

Example of execution :

Please enter an IF_EXPRESSION : if b*b-4*a*c < 0 then
The tokens composing the entered expression are : IF IDENTIFIER MUL_OP IDENTIFER ADD_OP NUMBER MUL_OP IDENTIFIER MUL_OP IDENTIFIER COMPARAISON_OP NUMBER THEN END_OF_STRING

Please enter an IF_EXPRESSION : if 2.3 then
Some_Error_Message(s).

Note: This lab is to be started in class, but may be submitted by next lab session.