ctnet'2006, ubi - march.17 gepl / di-um1 daniela da cruz pedro henriques universidade do minho...

27
CTNET'2006, UBI - March.17 gEPL / DI-UM 1 Daniela da Cruz Pedro Henriques Universidade do Minho Braga - Portugal

Post on 19-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

CTNET'2006, UBI - March.17

gEPL / DI-UM 1

Daniela da Cruz

Pedro Henriques

Universidade do Minho

Braga - Portugal

CTNET'2006, UBI - March.17

gEPL / DI-UM 2

Context

LISS, Language of Integers, Sequences and Sets, is a toy-programming language that allows us to operate with atomic or structured integers values (literals and variables)

developped in the context of a Compilers Course, to teach parsing and code generation (a complete compiler) for a traditional imperative and block-structured programming language.

CTNET'2006, UBI - March.17

gEPL / DI-UM 3

Motivation

It is our purpose in this presentation to explain: • not just the programming language LISS and its

compiler,• but also its relationship with other projects or tools

under discussion in this workshop.

CTNET'2006, UBI - March.17

gEPL / DI-UM 4

LISS Project (Conceptual Map)

CTNET'2006, UBI - March.17

gEPL / DI-UM 5

The Programming Language LISSLISS was designed with the main goal of being a

challenging case-study for Compiler courses.The language follows the verbose Pascal style, with

long keywords (case-insensitive),

but has an unsual Semantic definition!

It requires a powerful Semantic Analysis, and a clever Machine-code Generation.

CTNET'2006, UBI - March.17

gEPL / DI-UM 6

The Programming Language LISSThe design of LISS emphasizes:

• The static (compile time) and dynamic (run time) type checking

• The scope analysis• The code generation strategies (translation

schemas) to support non-standard Data-types, I/O and Control Statements

CTNET'2006, UBI - March.17

gEPL / DI-UM 7

LISS (important features)

• All variables are initialized with default values (0,empty,false).

• Just pre-defined Type Identifiers are allowed (type definition mechanism is not supported).

• The language supports Multi-Dimensional static Arrays

CTNET'2006, UBI - March.17

gEPL / DI-UM 8

LISS (important features)

• Linked Lists– Empty List

– List with some elements

– Operations: insert/delete, head/tail, member, isEmpty, index, length, assignment, write;

CTNET'2006, UBI - March.17

gEPL / DI-UM 9

LISS (important features)

• Sets:1. Are defined in comprehension

Codes = { x | x>=100 && x<500 }

2. Are represented (in memory) in a binary tree

3. Allows: union (++), intersection (**), member (in), write.

CTNET'2006, UBI - March.17

gEPL / DI-UM 10

LISS (important features)

• Subprograms, with 0 0 or moremore parameters,can becan be::

– Functions (return a value)– Procedures (don’t return a value)– Declared at the same Level, or Nested (any deep)– Called anywhere they are visible.

CTNET'2006, UBI - March.17

gEPL / DI-UM 11

LISS (important features)

• Control Statements

– If () Then {} [ Else {} ]– While () {}

– For For i in v1 [..v2 [stepup/stepdown N]] [satisfying Exp]

CTNET'2006, UBI - March.17

gEPL / DI-UM 12

LISS Compiler GenerationCoCo/R – C#

• Generated by the Compilers Compiler– CoCo/R (C# implementation)

• LISS syntax and semantics was specified by an AG written in CoCoL

• Input files– Liss.ATG +SymbolTable.cs+VMcodegen.cs

• Output file– Liss.exe

CTNET'2006, UBI - March.17

gEPL / DI-UM 13

LISS Compiler GenerationLISA - Java

• Generated by the Compilers Compiler– Lisa

• LISS syntax and semantics also was specified by an AG written in LisaL

• Input files– Liss.lisa +SymbolTable.java+VMcodegen.java

• Output file– Liss.exe

CTNET'2006, UBI - March.17

gEPL / DI-UM 14

LISS Compiler GenerationLISA / CoCoR

• CoCoR is just a compiler (invocated in the command line) and does not provide any information about compiler generation neither compiler execution;

• LISA provides a more complete compiler development environment (editors, visualizers, etc. for both compiler generation and execution)

CTNET'2006, UBI - March.17

gEPL / DI-UM 15

LISS Compiler GenerationLISA / CoCoR

• CoCoR deals with attributes (Inh/Syn) like function input/output parameters; Attributes are evaluated during top-down parsing (SDT)

• LISA supports actually true inherited/synthesized attributes, that are in fact evaluated during a separated phase traversing

an abstract syntax tree

As a consequence, Semantic Rules (the larger and more

complex part) in LISA AG are much simpler/clear

CTNET'2006, UBI - March.17

gEPL / DI-UM 16

LISS Program (example)program Teste {

Declarations

a :=4 -> Integer;

bool -> boolean;

c := [1,2,3], vector -> Array size 5;

e, f := { x | x > 7}, g := {x | x < 8 || x > 15 && x < 13 } -> Set;

Statements

-- sets

e = f ++ g; writeLn(e);

f = g ** f; writeLn(f);

g = g ** { x | x > 6 }; writeLn(g);

flag = a << e;

bool = 8 << {x | x < 10 && x > 7 };

}

CTNET'2006, UBI - March.17

gEPL / DI-UM 17

LISS Code GenerationMSP

• Very simple Virtual Stack Machine with:

1. Instruction (program) & Data Memory

2. Execution Stack

3. An Instruction Set minimalist

CTNET'2006, UBI - March.17

gEPL / DI-UM 18

LISS Code GenerationMSP

MEMORIA DE DADOS

a 0 TAM 1 VAL 4

bool 3 TAM 1 VAL 0

c 4 TAM 5 VAL 1 2 3 0 0

vector 9 TAM 5 VAL 0 0 0 0 0

CODIGO

; Line 15: e = f ++ g

; Line 16: f = g ** f

; Line 17: g = g ** x > 6

; Line 18: flag = a << e

PSHA flag

PSHA a

LOAD

PUSH 7

GT

PSHA a

LOAD

PUSH 8

LT

PSHA a

LOAD

PUSH 15

GT

PSHA a

LOAD

PUSH 13

LT

AND

OR

OR

STORE

; Line 19: bool = 8 << { x < 10 && x > 7 }

PSHA bool

PUSH 8

…….

a << e a << e

(a > 7) (a > 7) ||||((a < 8) || ((a > 15) && (a < 13)))((a < 8) || ((a > 15) && (a < 13)))

CTNET'2006, UBI - March.17

gEPL / DI-UM 19

LISS Code GenerationVM

• Virtual Machine with:

1. Instructions Stack (program)

2. Calling stack - save pointers pairs (i,f):• i – saves pc

• f – saves fp

3. Execution stack (global/local/working memory)

4. Two Heaps

5. Four registers (pc, sp, fp, gp)

6. A more sophisticated Instruction Set

CTNET'2006, UBI - March.17

gEPL / DI-UM 20

VM Architecture

CTNET'2006, UBI - March.17

gEPL / DI-UM 21

LISS Code GenerationVM

// Line 3: a := 4 -> Integer

PUSHI 4

// Line 4: bool -> Boolean

PUSHI 0

// Line 5: vector1 := [1,2,3], vector2 -> Array size 5

PUSHI 1

PUSHI 2

PUSHI 3

PUSHI 0

PUSHI 0

PUSHN 5

// Line 10: e, f := {x|x > 7}, g := {x|x < 8 || x > 15 && x < 13} -> Set

START

// Line 13: e = f ++ g

// Line 14: writeLn(e)

PUSHS "{x > 7 || x < 8 || x > 15 && x < 13}"

WRITES

// Line 15: f = g ** f

......

STOP

CTNET'2006, UBI - March.17

gEPL / DI-UM 22

LISS AnimationAlma

• To visualize & animate the execution of LISS programs– a LISS Front-End for the animator Alma will be

developped– To create the FE we will use LISA CG and

reuse LISS AG in LisaL

CTNET'2006, UBI - March.17

gEPL / DI-UM 23

LISS VerificationLISSOM

• To verify the code generate by LISS Compiler, and validate its compliance against a formal set of requirements, guarenteeing its correctness before execution– LISSOM PCC will be be used

CTNET'2006, UBI - March.17

gEPL / DI-UM 24

LISS VerificationLISSOM

• LISSOM P(roof) C(arrying) C(ode) system:– provides a formal language for the expression

of security policies;– provides means for the construction and the

verification of formal proofs of security policy compliance.

CTNET'2006, UBI - March.17

gEPL / DI-UM 25

LISSOM Architecture

CTNET'2006, UBI - March.17

gEPL / DI-UM 26

LISS Documentation• Technical Reports on LISS Compiler Development,

written in NuWeb, includes– LISS Specification (AG in CoCol/LisaL)– Sample LISS Programs (Tests)– Compiler’s Internal Data Structures – Target Machine Description (VM)– Translation Schemas

CTNET'2006, UBI - March.17

gEPL / DI-UM 27

Conclusion

LISS is a toy imperative programming language !!!

However it proved to be an interesting “learning object” and also a good test for Compiler Generators.