|
|
Scanners Exercises
Reading
Slides and LectureNotesTo clarify the discussion about precedence and order of oprations in class yesterday. The order of operations is '*' > ' ' > '|'. Note that '*' and '+' have the same precedence.
So, for example, if we were to write the un-parenthesized example from class: letter letter | digit *with parenthesis to indicate the default order of operations we would get: ((letter letter) | (digit *))which would recognize strings such as: xy, aa, 1, 12345but not strings like: xyz, a, a1, abc123
If we want to force the intended meaning of an identifier as a letter
followed by some number of letters or digits, then we must use explicit
parentheses to force the '|' to happen first as follows: letter (letter | digit) * |