Introduction

Programming Languages

A programming language is a language for computers.

A language has two major components:

  1. Syntax: The structural parts of a language (alphabet, rules, grammar).
  2. Semantics: The meaning of a language (what is the action/effect of this command?)

In this Class: We’ll be focusing entirely on syntax, only dipping barely into semantics.

Problem Domain Driven Languages

One of the driving forces behind the design of programming languages is the class (domain) of problems they want to solve.

Domains that historically driven language design:

Example: Important languages made to solve problems

Professor’s book recommendation: Out of their Minds

Aside: The total number of programming languages in the world is probably in the thousands due to rarely-used domain-specific languages.

On Purpose:

Domain-specific languages are not general-purpose languages.

Paradigms

Different philosophies have emerged on how to approach the solution of a program.

Some Mainstream Paradigms:

  1. Imperative/Procedural
  2. Function/Declarative/Applicative
  3. Object-Oriented
  4. Logical/Constraint-based

There are plenty of other paradigms too!

What Makes a Good Language?

How do we choose one over the other?

Main Criteria: Is it applicable to the problem?

Desirable Features in a Language:

  1. Simplicity: A language should help a programmer think about the program in a clear manner.
  2. Orthogonal: The way constructs can be combined, and how these combinations are simple to understand and meaningful in the language.
  3. Level of Abstraction: Degree to which the language allows the definition of data abstractions that approximate the constructs in the problem domain.
  4. Portability: Degree to which a program can be moved (transported) to another computer.
  5. Cost: The total cost of using a programming language.
  6. Expressivity: How flexible the language is in providing concise, different ways to define algorithms and computations.

Making a program functional is easy. The difficulty is extensibility, maintainability, etc.

Example: Aspects of some languages

Simplicity:

Orthogonality:

Abstraction:

Portability:

Cost:

Design Issues

Computer Architecture

The computer architecture affects language design.

Example: Von Neumann Bottleneck

Every mainstream language is written where instructions are run sequentially, one step after another, because it is complementary to the Von Neumann architecture.

In the Von Neumann architecture, data and instructions are stored in main memory accessible over a shared bus, which introduces the Von Neumann Bottleneck.

Implementation

Languages are usually implemented based on one of the following:

  1. Compilers: Source code translated to machine code.
  2. Interpreters: Source code parsed and executed in real time, line-by-line.
  3. Virtual Machines: Source code translated to byte code, which is interpreted by a virtual machine.

More on VMs:

Benefits:


Syntax

Two parts of syntax:

  1. Lexicon: Symbols, rules for putting them together, and pre-existing words.
  2. Grammar: How you put words together to form valid expressions/statements/blocks/functions/programs.

Lexicon

Alphabet

We define everything very thoroughly.

We denote alphabet with regular expressions

Reserved Words

The pre-existing words in the language. There are two types:

  1. Keywords: Reserved words that have a purpose (e.g., if, class, int, float, switch)
  2. Reserved: Reserved words that have no meaning

Why?: Why would a language designer reserve a word but give it no function?

Case Sensitivity

Case Sensitivity: Whether a language differentiates between upper and lower case.

Example: Languages

Case Insensitive:

Case Sensitive:

Professor’s Note: A lot of quirks of modern programming languages are influenced by C and Fortran.

Grammar

Rules the language enforces.

Remember: Rules are enforced. Don’t confuse them with convention.

Rules for Words

What are the rules for making words?

Example: Real-World Rules

Rules for Literals

What are the rules for making literals?

Literals: Literal values (e.g., 42, true)

Example: Real-World Literals

Lexical Scanner

Syntax and grammar are used to build a lexical scanner.

Architecture of a Compiler:

Source CodeLexical Analysis(Scanner)Syntax Analysis(Parser)Semantic AnalysisTranslation(Code Generation)OptimizationTarget FormatRaw TextLexical TokensASTSymbol Table& Enriched ASTObject CodeOptimized Code

Professor’s Note: Knowing how to implement a compiler is a valuable skill worth learning.