Lecture 2: Syntax

Paradigms of Programming

What is a programming paradigm?

Imperative Programming

Examples: Fortran, Algol, Cobol, Pascal, C, ...

Object-oriented Programming

Examples: Simula, Java, C++, C#, Ruby, Smalltalk, ...

Functional Programming

Examples: Haskell, Lisp, Scheme, ...

Logic Programming

Examples: Prolog, Datalog (deductive databases), Mercury, OWL, Semantic Web languages, ...

The CTMCP* Approach

*Concepts, Techniques, and Models of Computer Programming — the book

The kernel language approach

Some of the features discussed in CTMCP

mdc, The Micro dc

A Specification

Programs in mdc may include any number of:

... but nothing else.

Unlike dc, our mdc has just one stack, the main stack. mdc works as follows:

This is an informal specification of the semantics of mdc. We shall use this sort of specification throughout the course, and discuss other options at one of the last lectures.

Steps in executing an mdc program

  1. Reading the input. The input is a sequence of characters provided as an argument to mdc or read from a file or from the console (stdin).
  2. Parsing the input. The sequence of characters is processed in order to identify and classify syntactic elements, and an internal representation of the input is built.
  3. Interpreting the input. The internal representation of the program is processed, i.e., the actions specified by the syntactic elements are performed.

Specifying a Programming Language

The definition of a programming language involves (at least) a specification of its syntax and semantics.

Syntax: Definition of the form of programs in a language. Specifies which sequences of symbols are valid (are programs), and which are not.

Semantics: Definition of the meaning of programs in a language. Specifies what the computer has to do during an execution of a program.

Formal Language

A formal language LL is a set of strings (sequences) of symbols from a finite alphabet AA:

Example (Formal language)

Formal Grammars

How can we specify syntax formally?

Definition (Formal grammar) A formal grammar Γ\Gamma is a 44-tuple (V,S,R,vs)(V, S, R, v_s), where:

Backus-Naur Form

BNF Notation

Elements of BNF

Derivations

Further extensions

Classification of Grammars

Chomsky's Hierarchy of Languages

Regular Languages

What is a regular language?

Context-free Languages

What is a context-free language?

Context-sensitive Languages

What is a context-sensitive language?

Recursively Enumerable (Unrestricted) Languages

What is a recursively enumerable language?

Why do we care?