1. Regular expressions do not have a no negation operator.

    In Flex, ^ can occur as the first character inside brackets. It only takes the complement of a set of characters. It means "any single character except these."

    When ^ occurs outside brackets, it only matches if the next character is at the beginning of a line.

  2. Square brackets are only used to describe a set of characters. [aaa] matches one a. It is just a redundant specification of set {a}.

  3. In Flex, a dot matches any character except newline. To match any character at all, you can use (.|"\n").

  4. $ is not the same as "\n". $ matches at the end of a line, but it does not match the newline character.

  5. If you define a regular expression, then you must put braces around the name where you use it.

  6. The problem about comments of the form /*...*/ is difficult, and nobody got it. I will show you how to find that regular expression later, when I have time to write it up.

  7. A few students wrote aaa for the answer to question 1(a) (strings that contain exactly 3 a's and no newlines). A correct answer is

    [^a\n]*a[^a\n]*a[^a\n]*a[^a\n]*
    or, more succinctly
    ([^a\n]*a){3}[^a\n]*

  8. The action done by Flex for a regular expression must start on the same line as the regular expression.

  9. Any time you submit a program to me, indent it correctly. I promise that I will take off points for poorly indented programs.

  10. If you are going to use Flex to solve a problem, then let Flex do what it is good at rather than taking a more difficult approach. Here is a solution to problem 3.

    {%
    # include 
    %}
    
    vowel	[aeiouAEIOU]
    letter	[a-zA-Z]
    
    %%
    
    {vowel}{letter}*	{printf("%say", yytext);
    			}
    
    {letter}+		{printf("%s%cay", yytext+1, yytext[0]);
    			}
    
    (.|"\n")		{printf("%s", yytext);
    			}
    
    %%
    int main()
    {
      yyin = stdin;
      yylex();
      return 0;
    }
    
    int yywrap(void)
    {
      return 1;
    }