CSCE 314 Lecture 11

From Notes
Jump to navigation Jump to search

« previous | Wednesday, September 21, 2011 | next »


Lecture given by T.A. — too much too fast!

Modules

--MyModules/MyModuleName.hs
modulue MyModules.MyModuleName
(exportedFunctions
,otherFunction
,etc
) where

-- definitions

Importing Modules from Files

import MyModules.MyModuleName (optional,list,of,definitions)
-- module aliasing
import MyObscenelyLongModuleName as Name

Example

module Stack (StkType, push, pop, empty) where

data StkType a = EmptyStk | Stk [a]

push x (Stk s) = Stk (x:s)
pop (Stk (_:s) = Stk s
top (Stk (x:_)) = x

-- ...


Programming Language

What is a programming language?

language
language = syntax + semantics
syntax
Form of a program (how expressions, commands, etc are put together to make a final program
defines the set of valid programs
usually specified with a grammar
parser (how sentences are formed from words)
semantics
meaning of a program (how programs behave when executed on a computer)
defines how valid programs behave
informal: documentation and tutorials
formal operational: execution on an abstract machine
formal denotational: meaning as a mathematcal function


Implementation

  1. lexer: forms tokens from input stream
  2. parser: forms linear array of tokens into abstract syntax tree (AST) or sentence
  3. type checker: makes sure AST nodes are used correctly