COMPILER DESIGN

SYNTAX ANALYSIS

ROLE OF THE PARSER

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
How many sections are present in a LEX program?
A
2
B
3
C
4
D
6
Explanation: 

Detailed explanation-1: -A lex program consists of three sections: a section containing definitions, a section containing translations, and a section containing functions.

Detailed explanation-2: -A lex program consists of three parts: the definition section, the rules section, and the user subroutines. The parts are separated by lines consisting of two percent signs. The first two parts are required, although a part may be empty.

Detailed explanation-3: -LEX is a program generator designed for lexical processing of character input/output stream. Anything from simple text search program that looks for pattern in its input-output file to a C compiler that transforms a program into optimized code. In program with structure input-output two tasks occurs over and over.

Detailed explanation-4: -A rule in a LEX program comprises of a ‘pattern’ part (specified by a regular expression) and a corresponding (semantic) ‘action’ part (a sequence of C statements). In the above example, “integer” is the pattern and return ID TYPE INTEGER; is the corresponding action.

Detailed explanation-5: -Lex is a lexical analysis tool that can be used to identify specific text strings in a structured way from source text. Yacc is a grammar parser; it reads text and can be used to turn a sequence of words into a structured format for processing.

There is 1 question to complete.