Syntax of Expressions

Learn how the syntax of expressions can be defined and how the parsing process works.

At its core, a program written in any textual programming language, such as OCaml, Java, Python is nothing more than a long string consisting of characters we enter with a keyboard. A string that makes up a valid program in one programming language might be considered invalid in another and vice versa. To illustrate, consider the following obscure string:

++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++
 ..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.

Obviously, its not a valid OCaml program.
The OCaml compiler will reject that string with a syntax error message. Yet, it is a valid Hello World program according to the esoteric programming language Brainfuck.

Conversely, the string 1 + 2 is a perfectly valid OCaml program, but the Brainfuck compiler bluntly rejects it as invalid.

Get hands-on with 1200+ tech skills courses.