Updates for Lex Project
-
Do not implement the signs (+ or -) for the integers. An integer is anything
made only from digits 0...9.
-
The method described in the handout for removing the quotes from a quoted
string is not correct, because it doesn't handle spaces in the string.
A correct method to remove the quotes is:
strncpy(str, &(yytext[1]), strlen(yytext)-2);
str[strlen(yytext)-2] = (char) 0;
Variable str will hold the resulting string without the quotes.
-
Add one more operator: !=
-
Add the following line to your lex code:
\/\/[^\n]* {printf("comment: %s \n", yytext);}
With this you can have comments in C++ style, as in: //this is a comment
-
For each operator, parenthesis, and keyword, use a separate line. Example:
"+" {printf("operator: + \n");}
"-" {printf("operator: - \n");}
"*" {printf("operator: * \n");}
"/" {printf("operator: / \n");}
-
For wrong input, print an error message and abort the program.