














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of Compiler Design which includes Representing Types, Type Equality, Type Coercions, Kinds of Type Systems, Primitive Types, Inherited Attributes, Computing Attribute Computations, Describing Type Systems etc. Key important points are: Standard Ml, Characteristics of Sml, First Class Functions, Applicative Style, Automatic Memory Management, Syntactic Elements, Types of Commands, Define Prefix and Lastone, Map and Filter Functions
Typology: Slides
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Characteristics of SML
The SML Read-Typecheck-Eval-Print Loop Standard ML of New Jersey v110.57 [built: Mon Nov 21 21:46:28 2005]
**-
Note the semicolon when you’re ready to evaluate. Otherwise commands can spread across several lines.
fun mymap f [] = [] | mymap f (x::xs) = (f x)::(mymap f xs);
fun filter p [] = [] | filter p (x::xs) = if (p x) then x::(filter p xs) else (filter p xs);
Course topics
The Top to Bottom Example
text:
tokens:
syntax tree:
id(z) eql id(x) plus id(pi) times float(12.0)
z = x + pi * 12.
Id(z) +
float(12.0)
=
Id(z)
Id(x)^ *****
Id(pi)
temp1 := pi * 12. z := x * temp
ld r1,x ld r2,pi add r1,r ldi r2,12. mul r1,r st r1,z
Tokens, Patterns & Lexemes
same TOKEN i.e. identifiers, integers
constants, floats
which strings are assigned to a token.
characters matched by a PATTERN.
Sentence ::= Subject Verb Object
Subject ::= Proper-noun
Object ::= Article Adjective Noun
Verb ::= ate | saw | called Noun ::= cat | ball | dish
Article ::= the | a
Adjective ::= big | bad | pretty
Proper-noun ::= tim | mary
Start Symbol = Sentence
Example sentence: tim ate the big ball
Recursive Grammar Examples
Recursive Grammars describe infinite languages
list ::= [ num morenum ]
morenum ::= , num morenum
|
derives [ 2 ], [2,4], [2,4,6] ...
Exp ::= id
| Exp + Exp
| Exp * Exp
| ( Exp ) derives x, x+x, x+x+x, ...
Syntax Directed Translations
builds a translation in the process.
Considerations
traversal come from?
Example Translation Process Translation as an abstract syntax to abstract syntax transformer
We represent this as a grammar with “actions” { ... }. The action is
performed when that production is reduced.
Exp ::= Term terms
terms ::= + Term { print "+" } term
|
Term ::= Factor factors
factors ::= * Factor { print "*" } factors
|
Factor ::= id { print id.name }
| ( Exp )