• Complain

Peter Sestoft - Programming Language Concepts

Here you can read online Peter Sestoft - Programming Language Concepts full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: London, publisher: Springer London, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Peter Sestoft Programming Language Concepts
  • Book:
    Programming Language Concepts
  • Author:
  • Publisher:
    Springer London
  • Genre:
  • City:
    London
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Programming Language Concepts: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Programming Language Concepts" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Peter Sestoft: author's other books


Who wrote Programming Language Concepts? Find out the surname, the name of the author of the book and a list of all author's works by series.

Programming Language Concepts — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Programming Language Concepts" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Peter Sestoft Undergraduate Topics in Computer Science Programming Language Concepts 2012 10.1007/978-1-4471-4156-3_1 Springer-Verlag London 2012
1. Introduction
Peter Sestoft 1
(1)
IT University of Copenhagen, Copenhagen, Denmark
Abstract
This chapter introduces the approach taken and the plan followed in this book. We show how to represent arithmetic expressions and other program fragments as data structures in F# as well as Java, and how to compute with such program fragments. We also introduce various basic concepts of programming languages.
This chapter introduces the approach taken and the plan followed in this book. We show how to represent arithmetic expressions and other program fragments as data structures in F# as well as Java, and how to compute with such program fragments. We also introduce various basic concepts of programming languages.
1.1 Files for This Chapter
File
Contents
Intro/Intro1.fs
simple expressions without variables, in F#
Intro/Intro2.fs
simple expressions with variables, in F#
Intro/SimpleExpr.java
simple expressions with variables, in Java
1.2 Meta Language and Object Language
In linguistics and mathematics, an object language is a language we study (such as C++ or Latin) and the meta language is the language in which we conduct our discussions (such as Danish or English). Throughout this book we shall use the F# language as the meta language. We could use Java or C#, but that would be more cumbersome because of the lack of pattern matching.
F# is a strict, strongly typed functional programming language in the ML family. Appendix A presents the basic concepts of F#: value, variable, binding, type, tuple, function, recursion, list, pattern matching, and datatype. Several books give a more detailed introduction, including Syme et al. [].
It is convenient to run F# interactive sessions inside Microsoft Visual Studio (under MS Windows), or executing fsi interactive sessions using Mono (under Linux and MacOS X); see Appendix A.
1.3 A Simple Language of Expressions
As an example object language we start by studying a simple language of expressions, with constants, variables (of integer type), let-bindings, nested scope, and operators; see files Intro1.fs and Intro2.fs .
1.3.1 Expressions Without Variables
First, let us consider expressions consisting only of integer constants and two-argument (dyadic) operators such as ( + ) and ( * ). We represent an expression as a term of an F# datatype expr , where integer constants are represented by constructor CstI , and operator applications are represented by constructor Prim :
A value of type expr is an abstract syntax tree that represents an expression - photo 1
A value of type expr is an abstract syntax tree that represents an expression. Here are some example expressions and their representations as expr values:
Expression
Representation in type expr
CstI 17
Prim("-", CstI 3, CstI 4)
79+10
Prim("+", Prim("*", CstI 7, CstI 9), CstI 10)
An expression in this representation can be evaluated to an integer by a function eval : expr -> int that uses pattern matching to distinguish the various forms of expression. Note that to evaluate e 1+ e 2, it must first evaluate e 1 and e 2 to obtain two integers and then add those integers, so the evaluation function must call itself recursively:
The eval function is an interpreter for programs in the expression language It - photo 2
The eval function is an interpreter for programs in the expression language. It looks rather boring, as it implements the expression language constructs directly by similar F# constructs. However, we might change it to interpret the operator ( - ) as cut-off subtraction, whose result is never negative. Then we get a language with the same expressions but a very different meaning. For instance, 34 now evaluates to zero:
132 Expressions with Variables Now let us extend our expression language - photo 3
1.3.2 Expressions with Variables
Now, let us extend our expression language with variables such as x and y . First, we add a new constructor Var to the syntax:
Here are some expressions and their representation in this syntax - photo 4
Here are some expressions and their representation in this syntax:
Expression
Representation in type expr
CstI 17
x
Var "x"
3+ a
Prim("+", CstI 3, Var "a")
b 9+ a
Prim("+", Prim("*", Var "b", CstI 9), Var "a")
Next we need to extend the eval interpreter to give a meaning to such variables. To do this, we give eval an extra argument env , a so-called environment . The role of the environment is to associate a value (here, an integer) with a variable; that is, the environment is a map or dictionary, mapping a variable name to the variables current value. A simple classical representation of such a map is an association list : a list of pairs of a variable name and the associated value:
This environment maps a to 3 c to 78 and so on The environment has type - photo 5
This environment maps "a" to 3, "c" to 78, and so on. The environment has type (string * int) list . An empty environment, which does not map any variable to anything, is represented by the empty association list
Programming Language Concepts - image 6
To look up a variable in an environment, we define a function lookup of type (string * int) list -> string -> int . An attempt to look up variable x in an empty environment fails; otherwise, if the environment associates y with v , and x equals y , the result is v ; else the result is obtained by looking for x in the rest r of the environment:
As promised our new eval function takes both an expression and an environment - photo 7
As promised, our new eval function takes both an expression and an environment, and uses the environment and the lookup function to determine the value of a variable Var x . Otherwise the function is as before, except that env must be passed on in recursive calls:
Note that our lookup function returns the first value associated with a - photo 8
Note that our lookup function returns the first value associated with a variable, so if env is [("x", 11); ("x", 22)] , then lookup env "x" is 11, not 22. This is useful when we consider nested scopes in Chap..
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Programming Language Concepts»

Look at similar books to Programming Language Concepts. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Programming Language Concepts»

Discussion, reviews of the book Programming Language Concepts and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.