Question

In: Computer Science

(a) How are rules for lexical analysis written? (b) What are these rules used for?

(a) How are rules for lexical analysis written? (b) What are these rules used for?

Solutions

Expert Solution

During compilation process, lexical analysis is the first phase of a compiler. The lexical analyser modifies the source code of the program. It takes the source code as input and produces a set of tokens as output.

The source code is converted into a series of token which are produced by removing all the white spaces and comments present in the source code.

The alphanumeric sequence of characters in a token are known as Lexemes.

To identify these lexemes there are many rules which are predefined which are known as grammar rules.

According to these rules, patterns are observed. A pattern explains what can be a token, and these patterns are defined by means of regular expressions.

In programming language, keywords, constants, identifiers, strings, numbers, operators and punctuations symbols can be considered as tokens.

For example take variable declaration in C language,

int a=10;

Now performing lexical analysis on this code:

int (keyword), a (identifier), = (operator), 10 (constant) and ; (symbol).

(b). These are used to make the compilation process faster as the source code is not understandable to the machine, so these phases of compilers are used for converting the source code into machine code.


Related Solutions

The objective of this assignment is to gain an understanding of the lexical analysis phase of...
The objective of this assignment is to gain an understanding of the lexical analysis phase of a compiler and the process of constructing a symbol table. Problem: The first phase of compilation is called scanning or lexical analysis. This phase interprets the input program as a sequence of characters and produces a sequence of tokens, which will be used by the parser. Write a program (in C, C++, C#, Java, or Python) that implements a simple scanner for a source...
The application of lexical analysis techniques in text editor You should cover: 1) What is the...
The application of lexical analysis techniques in text editor You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
A) What is the DV? __________ What is the IV? B) What analysis should be used...
A) What is the DV? __________ What is the IV? B) What analysis should be used to determine if there is a difference in balancing time as a function of treatment? C) What is the result of that analysis? D) Given that result, can we conclude amphetamine caused a difference in balancing time? If so, what was the change (i.e., did amphetamine reduce or increase balancing time)? E) Given the result of the test, can we conclude that amphetamine does...
1)Lexical heads are typically Select one: a. closed class lexical items b. phonologically null c. no...
1)Lexical heads are typically Select one: a. closed class lexical items b. phonologically null c. no class lexical items d. open class lexical items 2)The subject of the sentence `the woman with a big dog on a flimsy leash in the public park behind my house saw a horse' is: Select one: a. the woman with a big dog b. the woman c. the woman with a big dog on a flimsy leash in the public park behind my house...
The application of lexical analysis techniques in information retrieval system You should cover: 1) What is...
The application of lexical analysis techniques in information retrieval system You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
The application of lexical analysis techniques in spam email detection You should cover: 1) What is...
The application of lexical analysis techniques in spam email detection You should cover: 1) What is the problem? 2) What is the compiler construction techniques used to solve the problem 3) How to solve the problem using the compiling techniques.
What is sunk costs and how is it used in replacement analysis?
What is sunk costs and how is it used in replacement analysis?
What is the purpose of a “convenience translation”? How are they used in financial analysis? What...
What is the purpose of a “convenience translation”? How are they used in financial analysis? What are some features of financial statements that a company might translate in a convenience translation?
IF–THEN rules can be used for classification. What are some performance measures that can be used...
IF–THEN rules can be used for classification. What are some performance measures that can be used to evaluate the accuracy of the rule, and how do these measures differ? What are the advantages and limitations of each performance measure? You should compare at least two performance measures for evaluating the performance of an IF–THEN rule.
What is an opportunity cost? How is it used in a time value analysis? Is the...
What is an opportunity cost? How is it used in a time value analysis? Is the opportunity rate a single number that is used in all situations? Integrate Bible passages into the discussion that address the Christian worldview.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT