Question: 1. Write regular expressions to capture the following. (a) String literals in C. These are delimited by double quotes (), and may not contain newline
1. Write regular expressions to capture the following.
(a) String literals in C. These are delimited by double quotes ("), and may not contain newline characters. Remember that the backslash character is used to escape any printable character except for the newline character (which is generated when you press the enter key on your keyboard). Let nl represent the newline character. Note that this is different than . If you need to use the double-quote or backslash character in a string literal, those characters must be escaped with a preceding backslash. You may find it helpful to introduce shorthand notation to represent any character that is not a member of a small specified set. For notational convenience, let the regular expression extension not(a1, a2, , an) = (b1|b2|...|bm) , where the bis are all the characters in the alphabet other than the a j s.
(b) Comments in Pascal. These are delimited by (* and *) or by { and }. The same pair type cannot nest, however they nest one-level within each other. For example, (* ... { ...} ... *) is acceptable as long as there isnt any further nesting. If they overlap, for example (* ... { ... *) ... }, the } will be treated as a lexical error since the closing brace, }, is not used for any other purpose in Pascal. Both { and } are used only for comments. Similarly, the two character pairs, (* and *), are only used for comments. However, individual characters ( and * are used in Pascal for other purposes. Hint: Assume the existence of a not operator and treat the two types of block comments as separate, e.g. r1 | r2, where r1 and r2 are regular expressions for (* *) and { }, respectively
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
