Search⌘ K
AI Features

Values of Expressions

Learn to differentiate between syntax and semantics in programming expressions. Understand how interpreted languages evaluate expressions recursively and how compiled languages translate expressions into machine code. This lesson helps you grasp the fundamental process of parsing, type checking, and executing expressions to better troubleshoot and learn programming languages.

Syntax vs. semantics

When studying languages in general and programming languages in particular, it is worth learning to differentiate between syntax and semantics. The syntax of a language specifies which character combinations are valid and which aren’t. This lesson focuses on semantics, which is concerned with the meaning of those character combinations.

Consider, for instance, the expression 12 + 34. What we enter is nothing more than a string—a character combination— consisting of characters 1, 2, 3, 4, empty space, +, and so on. The OCaml parser recognizes this input, and creates an abstract syntax tree to represent the expression. Until this point, it’s been all about syntax.

Now, an interesting ...