Hard work beats talent when talent doesn’t work hard.
--Your friends at LectureNotes

Note for Compiler Design - CD by Sreethi Nikhil

  • Compiler Design - CD
  • Note
  • Cochin University of Science and Technology CUSAT, Eranakulam - CUSAT
  • Computer Science Engineering
  • B.Tech
  • 7 Topics
  • Uploaded 1 year ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-3

• The parser obtains a string of tokens from the lexical analyzer, and verifies that the string of token names can be generated by the grammar for the source language. • We expect the parser to report any syntax errors and to recover from commonly occurring errors to continue processing the remainder of the program. • The parser constructs a parse tree and passes it to the rest of the compiler for further processing.

Text from page-4

• top-down or bottom-up parsers. • As implied by their names, top-down methods build parse trees from the top (root) to the bottom (leaves) , while bottom-up methods start from the leaves and work their way up to the root. • In either case, the input to the parser is scanned from left to right, one symbol at a time.

Text from page-5

Representative Grammars • E represents expressions consisting of terms separated by + signs, T represents terms consisting of factors separated by * signs, and F represents factors that can be either parenthesized expressions or identifiers. • Expression grammar belongs to the class of LR grammars that are suitable for bottom-up parsing. • It cannot be used for top-down parsing because it is left recursive. The following non-left-recursive variant of the expression grammar will be used for top-down parsing.

Text from page-6

Syntax Error Handling • • A compiler is expected to assist the programmer in locating and tracking down errors. Common programming errors can occur at many different levels. • Lexical errors include misspellings of identifiers, keywords, or operators . • Syntactic errors include misplaced semicolons or extra or missing braces. • Semantic errors include type mismatches between operators and operands. • Logical errors such as infinitely recursive function call. • Reason for emphasizing error recovery during parsing is that many errors appear syntactic, whatever their cause, and are exposed when parsing cannot continue.

Lecture Notes