Skip to Main Content
Language Implementation Patterns
book

Language Implementation Patterns

by Terence Parr
December 2009
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 2m
English
Pragmatic Bookshelf
Content preview from Language Implementation Patterns
Pattern 20Computing Static Expression Types

Purpose

This pattern explains how to statically compute the type of expressions in languages with explicit type declarations like C.

You’ll be able to extrapolate from this pattern everything you’d need to build a static type analyzer for C, C++, Java, or C#. Every compiler for those languages implements an extended version of this pattern. So do static bug analyzers such as FindBugs[23] and Coverity.[24]

Discussion

Type computation is an extremely broad topic. To make things more concrete, we’ll focus on the type computation rules for Cymbol itemized here:

Subexpression

Result Type

true, false

boolean.

Character literal

char.

Integer literal

int.

Floating-point literal

float.

id

The declared type of the variable ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementation Patterns

Implementation Patterns

Kent Beck

Publisher Resources

ISBN: 9781680500097Errata Page