Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (10pt) Write a regular expression that represents each of the following two sets: (1) C strings, which are all strings that: - start and

image text in transcribed

image text in transcribed

1. (10pt) Write a regular expression that represents each of the following two sets: (1) C strings, which are all strings that: - start and end with double quotes: ". - do not contain double quotes unless escaped by a backslash: \" - do not contain newline (let's denote it ENTER) unless escaped by a backslash: ENTER (Note that ENTER is different from the two-character sequence " ". To introduce a new line in your code you hit the ENTER key, not the '\' key followed by the N'key.) (2) All identifiers in a language where: - identifiers consist of one or more letters, lower or upper case, - file, for, and from are reserved keywords. Use the format in the textbook, page 46. You can use the notation () to denote the set of characters different from a given set; e.g., -(a, b) denotes the set of all characters different from a and b; -() denotes any character. Chapter 2 Programming Language Syntax 4. Two regular expressions separated by a vertical bar (), meaning any string generated by the first one or any string generated by the second one 5. A regular expression followed by a Kleene star, meaning the concatenation of zero or more strings generated by the expression in front of the star EXAMPLE 2.3 Syntax of numeric constants Parentheses are used to avoid ambiguity about where the various subexpres- sions start and end. Consider, for example, the syntax of numeric constants accepted by a simple hand-held calculator: number + integer | real integer digit digit* real integer exponent decimal (exponente) decimal digit* (. digit | digit . ) digit* exponent (E E) (+1 -1 ) integer digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 The symbols to the left of the signs provide names for the regular expres- sions. One of these (number) will serve as a token name; the others are simply DESIGN & IMPLEMENTATION 2.1 Contextual keywords In addition to distinguishing between keywords and identifiers, some lan- guages define so-called contextual keywords, which function as keywords in certain specific places in a program, but as identifiers elsewhere. In C#, for ex- ample, the word yield can appear immediately before return or break-a place where an identifier can never appear. In this context, it is interpreted as a keyword; anywhere else it is an identifier. It is therefore perfectly acceptable to have a local variable named yield: the compiler can distinguish it from the keyword by where it appears in the program. C++11 has a small handful of contextual keywords. C# 4.0 has 26. Most were introduced in the course of revising the language to create a new stan- dard version. Given a large user community, any short, intuitively appealing word is likely to have been used as an identifier by someone, in some existing program. Making that word a contextual keyword in the new version of the language, rather than a full keyword, reduces the risk that existing programs will suddenly fail to compile. 3 Some authors use to represent the empty string. Some use a period (.), rather than juxtaposi- tion, to indicate concatenation. Some use a plus sign (+), rather than a vertical bar, to indicate alternation. 1. (10pt) Write a regular expression that represents each of the following two sets: (1) C strings, which are all strings that: - start and end with double quotes: ". - do not contain double quotes unless escaped by a backslash: \" - do not contain newline (let's denote it ENTER) unless escaped by a backslash: ENTER (Note that ENTER is different from the two-character sequence " ". To introduce a new line in your code you hit the ENTER key, not the '\' key followed by the N'key.) (2) All identifiers in a language where: - identifiers consist of one or more letters, lower or upper case, - file, for, and from are reserved keywords. Use the format in the textbook, page 46. You can use the notation () to denote the set of characters different from a given set; e.g., -(a, b) denotes the set of all characters different from a and b; -() denotes any character. Chapter 2 Programming Language Syntax 4. Two regular expressions separated by a vertical bar (), meaning any string generated by the first one or any string generated by the second one 5. A regular expression followed by a Kleene star, meaning the concatenation of zero or more strings generated by the expression in front of the star EXAMPLE 2.3 Syntax of numeric constants Parentheses are used to avoid ambiguity about where the various subexpres- sions start and end. Consider, for example, the syntax of numeric constants accepted by a simple hand-held calculator: number + integer | real integer digit digit* real integer exponent decimal (exponente) decimal digit* (. digit | digit . ) digit* exponent (E E) (+1 -1 ) integer digit 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 The symbols to the left of the signs provide names for the regular expres- sions. One of these (number) will serve as a token name; the others are simply DESIGN & IMPLEMENTATION 2.1 Contextual keywords In addition to distinguishing between keywords and identifiers, some lan- guages define so-called contextual keywords, which function as keywords in certain specific places in a program, but as identifiers elsewhere. In C#, for ex- ample, the word yield can appear immediately before return or break-a place where an identifier can never appear. In this context, it is interpreted as a keyword; anywhere else it is an identifier. It is therefore perfectly acceptable to have a local variable named yield: the compiler can distinguish it from the keyword by where it appears in the program. C++11 has a small handful of contextual keywords. C# 4.0 has 26. Most were introduced in the course of revising the language to create a new stan- dard version. Given a large user community, any short, intuitively appealing word is likely to have been used as an identifier by someone, in some existing program. Making that word a contextual keyword in the new version of the language, rather than a full keyword, reduces the risk that existing programs will suddenly fail to compile. 3 Some authors use to represent the empty string. Some use a period (.), rather than juxtaposi- tion, to indicate concatenation. Some use a plus sign (+), rather than a vertical bar, to indicate alternation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions