Validating Program Symbol Usage

To build an interpreter, compiler, or translator for a programming language such as Cymbol, we’d need to verify that Cymbol programs used symbols (identifiers) properly. In this section, we’re going to build a Cymbol validator that checks the following conditions:

  • Variable references have corresponding definitions that are visible to them (in scope).

  • Function references have corresponding definitions (functions can appear in any order).

  • Variables are not used as functions.

  • Functions are not used as variables.

To check all these conditions, we have a bit of work to do, so this example is going to take a little bit longer than the others to absorb. But, our reward will be a great base from which to build ...

Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.