Q.n.2 Explain the significance of Lexical analysis and Syntax analysis.
lexical analysis is the process of converting a sequence of characters into a sequence of tokens. A program or function which performs lexical analysis is called a lexical analyzer, laxer or scanner. A laxer often exists as a single function which is called by a parser or another function. The lexical analysis or scanning of a program breaks it into a Sequence of tokens. For example, a sequence of letters and digits May be transformed into a single token representing an identi_er. Similarly, numbers of various types are tokens. Some tokens may correspond to individual symbols in the original string. For Example, the character + may generate a single token. Even in thisCase, the resulting token has been recognized as an operator and The token will normally carry this information. Each type of token is denned by a regular language. The lexical Analysis of a program basically simulates a _niter state machine.
Syntax analysis: syntax analysis or parsing is about discovering structure in text and is used to determine whether or not a text conforms to an expected format. "Is this a textually correct Java program?" or "Is this bibliographic entry textually correct?" are typical questions that can be answered by syntax analysis. We are mostly interested in syntax analysis to determine that the source code of a program is correct and to convert it into a more structured representation (parse tree) for further processing like semantic analysis or transformation.
Syntax analysis is one of the very mature areas of language theory and many methods have been proposed to implement parsers. Giving even a brief overview of these techniques is beyond the scope of this paper, but sees the references in the section called “Further reading”. In the Meta-Environment we use a parsing method called Scanner less Generalized Left-to-Right parsing or SGLR for short. The least we can do is explain what this method is about. The method depends on writing a separate parsing procedure for each kind of syntactic structure, such as if statement, assignment statement, expression and so on, and each of these is only responsible for analysing its own kind of structure. If any structure contains another structure then the parsing procedure can call the procedure for this contained structure.
No comments:
Post a Comment