in Compiler Design retagged by
4,108 views
1 vote
1 vote

Consider the following statements

$S_{1}:$ The set of string described by a rule is called pattern associated with the token.

$S_{2}:$ A lexeme is a sequence of character in the source program that is matched by Pattern for a token.

Which of the following statement is/are true?

  1. Both $S_{1}$ and $S_{2}$ are true
  2. $S_{1}$ is true $S_{2}$ is false
  3. $S_{2}$ is true $S_{1}$ is false
  4. Both $S_{1}$ and $S_{2}$ are false
in Compiler Design retagged by
4.1k views

1 comment

Is the answer 3.
0
0

3 Answers

0 votes
0 votes

Token: A token is a syntactic category. Sentences consist of a string of tokens. For example number, identifier, keyword, string etc are tokens.

Lexeme: Sequence of characters in a token is a lexeme. For example 100.01, counter, const, "How are you?" etc are lexemes.

Pattern: Rule of description is a pattern. For example letter (letter | digit)* is a pattern to symbolize a set of strings which consist of a letter followed by a letter or digit. In general, there is a set of strings in the input for which the same token is produced as output. This set of strings is described by a rule called a pattern associated with the token. This pattern is said to match each string in the set. A lexeme is a sequence of characters in the source program that is matched by the pattern for a token. The patterns are specified using regular expressions. For example, in the Pascal statement

Const pi = 3.1416; 

Option 1.

2 Comments

What is the difference between pattern and regular expression?
0
0
Both are same.

A regular expression, often called a pattern, is an expression used to specify a set of strings required for a particular purpose.
0
0
0 votes
0 votes

For this question, we clearly need to understand, the token , lexeme and pattern

Lexeme: Lexeme is a sequence of character, that matched with pattern.

Pattern: Pattern is a sets of rule, that is form of accepted. i.e. letter(letter+digit)*

From ullman

"A lexeme is a sequence of characters in the source program that matches the pattern for a token and is identified by the lexical analyzer as an instance of that token."

 

"A token is a pair consisting of a token name and an optional attribute value. The token name is an abstract symbol representing a kind of lexical unit, e.g., a particular keyword, or sequence of input characters denoting an identifier. The token names are the input symbols that the parser processes."

 

"A pattern is a description of the form that the lexemes of a token may take. In the case of a keyword as a token, the pattern is just the sequence of characters that form the keyword. For identifiers and some other tokens, the pattern is more complex structure that is matched by many strings."

For example

Say for

int a;

DFA constructed from i, then n and then t, atlast got white-space, where i, n, t are lexeme

When it got white-space , "int" already matched with pattern. So, this token is accepted

So, here $S_{1}$ is just definition of grammar , Hence it is false.

But $S_{2}$ is true.

0 votes
0 votes
The first statement "The set of string described by a rule is called pattern associated with the token" is false. The pattern is not associated with the token, but rather it is used to match a sequence of characters in the source program to identify a token.

The second statement "A lexeme is a sequence of character in the source program that is matched by Pattern for a token" is true. A lexeme is a sequence of characters in the source program that matches a pattern for a token, and it is the basic unit of analysis in lexical analysis.

Therefore, the correct answer is "The first statement is false, and the second statement is true."

Related questions