What is the role of a parser in compiler design?

1 answer

Answer

1191552

2026-05-14 05:10

+ Follow

· In the compiler model, the parser obtains a string of tokens from the lexical analyser, and verifies that the string can be generated by the grammar for the source language.

· The parser returns any syntax error for the source language.

· There are three general types' parsers for grammars.

· Universal parsing methods such as the Cocke-Younger-Kasami algorithm andEarley's algorithm can parse any grammar. These methods are too inefficient to use in production compilers.

· The methods commonly used in compilers are classified as either top-down parsing or bottom-up parsing.

· Top-down parsers build parse trees from the top (root) to the bottom (leaves).

· Bottom-up parsers build parse trees from the leaves and work up to the root.

· In both case input to the parser is scanned from left to right, one symbol at a time.

· The output of the parser is some representation of the parse tree for the stream of tokens.

· There are number of tasks that might be conducted during parsing. Such as;

o Collecting information about various tokens into the symbol table.

o Performing type checking and other kinds of semantic analysis.

o Generating intermediate code.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.