Docsity

Study Guide for Programming Languages and Compilers | CS 5363, Study notes of Computer Science

Toggle sidebar
bg1
CS 5363: Type Rules for TL07
Jeffery von Ronne
August 29, 2007
Rules
Top-level and variable declarations
PROG
Σ` C
Σ`PROGRAM name BEGIN CEND
(where name is any legal identifier)
DECLVAR
Σ|(`→τ)`PROGRAM name DBEGIN CEND
Σ`PROGRAM name VAR `AS τ;DBEGIN CEND
SEQ
Σ` C1Σ` C2
Σ` C1C2
Statements
IF
Σ`e:bool Σ` C
Σ`IF eTHEN CEND ;
IFELSE
Σ`e:bool Σ` C1Σ` C2
Σ`IF eTHEN C1ELSE C2END ;
WHILE
Σ`e:bool Σ` C
Σ`WHILE eDO CEND ;
ASGN
Σ``:R(τ)Σ`e:τ
Σ``:= e
READINT
Σ``:R(int)
Σ``:= READINT ;
WRITEINT
Σ`e:int
Σ`WRITEINT e;
1
pf2

Partial preview of the text

Download Study Guide for Programming Languages and Compilers | CS 5363 and more Study notes Computer Science in PDF only on Docsity!

CS 5363: Type Rules for TL

Jeffery von Ronne August 29, 2007

Rules

Top-level and variable declarations

PROG

Σ ` C

Σ ` PROGRAM name BEGIN C END

(where name is any legal identifier)

DECLVAR

Σ | (→ _τ_ ) PROGRAM name D BEGIN C END Σ PROGRAM name VAR AS τ ; D BEGIN C END

SEQ

Σ C 1 Σ C 2

Σ ` C 1 C 2

Statements

IF

Σ e : bool Σ C Σ ` IF e THEN C END ;

IFELSE

Σ e : bool Σ C 1 Σ C 2 Σ IF e THEN C 1 ELSE C 2 END ;

WHILE

Σ e : bool Σ C Σ ` WHILE e DO C END ;

ASGN

Σ : R( τ ) Σ e : _τ_ Σ ` := e

READINT

Σ : R(int) Σ := READINT ;

WRITEINT

Σ e : int Σ WRITEINT e;

Expressions and Operators

OP

Σ e 1 : int Σ e 2 : int Σ ` e 1 OP2 e 2 : int

OP

Σ e 1 : int Σ e 2 : int Σ ` e 1 OP3 e 2 : int

OP

Σ e 1 : int Σ e 2 : int Σ ` e 1 OP4 e 2 : bool

Variables and Literals

VARREF Σ | (→ _τ_ ) ` : R( τ ))

DEREF

Σ : R( τ ) ` : τ

INDEX

Σ : R(ARRAY ι OF INT) Σ e : int Σ ` [ e ] : R(int)

FALSE Σ ` FALSE : bool

TRUE Σ ` TRUE : bool

NUM Σ ` number : int

(where number is literal integer from -2147483648 through 2147483647)

Conventions

C is a metavariable over sequences of zero or more statements (including the semicolons). D is a metavariable over sequences of zero or more variable declarations (in- cluding the last semicolon). e is metavariable over r-values. τ is a meta-variable over types. ι is some non-negative integer literal. R( τ ) is a type denoting a reference to a memory cell whose contents is of type τ. ` is some program variable name (name of a location in memory).