LARA

Lecture 05: LR Parsing

Continuing Lecture 04, Lecture 03

Announcement: projects updated, include Earley parser

Introduction

LR Parser without Lookahead

LR Parser with Lookahead

Precedence

Tools

Traditional, widely used, tool is called yacc (for Yet Another Compiler Compiler) developed for C.

Its versions are available for Java (called 'CUP'), OCaml (ocamlyacc), and other languages.

Example ocamlyacc grammar

Grammar of Formulas in CUP

Reference

Discussion of Semantic Analysis

Examples of semantic analysis:

  • undeclared identifiers
  • duplicate identifiers in same scope
  • variables read but not written / written but not read / not used
  • type mismatch for built-in operators (if (7) …)
  • calling unknown methods, accessing unknown fields
  • variables read before being written
  • unreachable code
  • accessing variable out of bounds