Daniela da Cruz Pedro Henriques Universidade do Minho

  • Slides: 27
Download presentation
Daniela da Cruz Pedro Henriques Universidade do Minho Braga - Portugal CTNET'2006, UBI March.

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

Context LISS, Language of Integers, Sequences and Sets, is a toy-programming language that allows

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 blockstructured programming language. CTNET'2006, UBI March. 17 g. EPL / DI-UM 2

Motivation It is our purpose in this presentation to explain: • not just the

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 g. EPL / DI-UM 3

LISS Project (Conceptual Map) CTNET'2006, UBI March. 17 g. EPL / DI-UM 4

LISS Project (Conceptual Map) CTNET'2006, UBI March. 17 g. EPL / DI-UM 4

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

The Programming Language LISS 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 g. EPL / DI-UM 5

The Programming Language LISS The design of LISS emphasizes: • • • The static

The Programming Language LISS The 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 g. EPL / DI-UM 6

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

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 g. EPL / DI-UM 7

LISS (important features) • Linked Lists – Empty List – List with some elements

LISS (important features) • Linked Lists – Empty List – List with some elements – Operations: insert/delete, head/tail, member, is. Empty, index, length, assignment, write; CTNET'2006, UBI March. 17 g. EPL / DI-UM 8

LISS (important features) • Sets: 1. Are defined in comprehension Codes = { x

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 g. EPL / DI-UM 9

LISS (important features) • Subprograms, with 0 or more parameters, can be: – –

LISS (important features) • Subprograms, with 0 or more parameters, can 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 g. EPL / DI-UM 10

LISS (important features) • Control Statements – – If () Then {} [ Else

LISS (important features) • Control Statements – – If () Then {} [ Else {} ] While () {} – For CTNET'2006, UBI March. 17 For i in v 1 [. . v 2 [stepup/stepdown N]] [satisfying Exp] g. EPL / DI-UM 11

LISS Compiler Generation Co. Co/R – C# • Generated by the Compilers Compiler –

LISS Compiler Generation Co. Co/R – C# • Generated by the Compilers Compiler – • • LISS syntax and semantics was specified by an AG written in Co. L Input files – • Co. Co/R (C# implementation) Liss. ATG +Symbol. Table. cs+VMcodegen. cs Output file – Liss. exe CTNET'2006, UBI March. 17 g. EPL / DI-UM 12

LISS Compiler Generation LISA - Java • Generated by the Compilers Compiler – •

LISS Compiler Generation LISA - Java • Generated by the Compilers Compiler – • • LISS syntax and semantics also was specified by an AG written in Lisa. L Input files – • Lisa Liss. lisa +Symbol. Table. java+VMcodegen. java Output file – Liss. exe CTNET'2006, UBI March. 17 g. EPL / DI-UM 13

LISS Compiler Generation LISA / Co. R • Co. R is just a compiler

LISS Compiler Generation LISA / Co. R • Co. R 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 g. EPL / DI-UM 14

LISS Compiler Generation LISA / Co. R • Co. R deals with attributes (Inh/Syn)

LISS Compiler Generation LISA / Co. R • Co. R 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 g. EPL / DI-UM 15

LISS Program (example) program Teste { Declarations a : =4 -> Integer; bool ->

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; write. Ln(e); f = g ** f; write. Ln(f); g = g ** { x | x > 6 }; write. Ln(g); flag = a << e; bool = 8 << {x | x < 10 && x > 7 }; } CTNET'2006, UBI March. 17 g. EPL / DI-UM 16

LISS Code Generation MSP • Very simple Virtual Stack Machine with: 1. Instruction (program)

LISS Code Generation MSP • Very simple Virtual Stack Machine with: 1. Instruction (program) & Data Memory 2. Execution Stack 3. An Instruction Set minimalist CTNET'2006, UBI March. 17 g. EPL / DI-UM 17

LISS Code Generation MSP MEMORIA DE DADOS a 0 TAM 1 VAL 4 bool

LISS Code Generation MSP 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 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 CTNET'2006, UBI March. 17 PSHA a LOAD PUSH 15 GT PSHA a LOAD PUSH 13 LT AND OR OR STORE a << e (a > 7) || ((a < 8) || ((a > 15) && (a < 13))) ; Line 19: bool = 8 << { x < 10 && x > 7 } PSHA bool PUSH 8 ……. g. EPL / DI-UM 18

LISS Code Generation VM • Virtual Machine with: 1. 2. Instructions Stack (program) Calling

LISS Code Generation VM • Virtual Machine with: 1. 2. Instructions Stack (program) Calling stack - save pointers pairs (i, f): • • 3. 4. 5. 6. i – saves pc f – saves fp Execution stack (global/local/working memory) Two Heaps Four registers (pc, sp, fp, gp) A more sophisticated Instruction Set CTNET'2006, UBI March. 17 g. EPL / DI-UM 19

VM Architecture CTNET'2006, UBI March. 17 g. EPL / DI-UM 20

VM Architecture CTNET'2006, UBI March. 17 g. EPL / DI-UM 20

LISS Code Generation VM // Line 3: a : = 4 -> Integer PUSHI

LISS Code Generation VM // Line 3: a : = 4 -> Integer PUSHI 4 // Line 4: bool -> Boolean PUSHI 0 // Line 5: vector 1 : = [1, 2, 3], vector 2 -> Array size 5 PUSHI 1 PUSHI 2 PUSHI 3 PUSHI 0 PUSHN 5 // Line 10: START // Line 13: // Line 14: PUSHS "{x > WRITES // Line 15: . . . STOP e, f : = {x|x > 7}, g : = {x|x < 8 || x > 15 && x < 13} -> Set e = f ++ g write. Ln(e) 7 || x < 8 || x > 15 && x < 13}" f = g ** f CTNET'2006, UBI March. 17 g. EPL / DI-UM 21

LISS Animation Alma • To visualize & animate the execution of LISS programs –

LISS Animation Alma • 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 Lisa. L CTNET'2006, UBI March. 17 g. EPL / DI-UM 22

LISS Verification LISSOM • To verify the code generate by LISS Compiler, and validate

LISS Verification LISSOM • 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 g. EPL / DI-UM 23

LISS Verification LISSOM • LISSOM P(roof) C(arrying) C(ode) system: – provides a formal language

LISS Verification LISSOM • 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 g. EPL / DI-UM 24

LISSOM Architecture CTNET'2006, UBI March. 17 g. EPL / DI-UM 25

LISSOM Architecture CTNET'2006, UBI March. 17 g. EPL / DI-UM 25

LISS Documentation • Technical Reports on LISS Compiler Development, written in Nu. Web, includes

LISS Documentation • Technical Reports on LISS Compiler Development, written in Nu. Web, includes – – – LISS Specification (AG in Co. Col/Lisa. L) Sample LISS Programs (Tests) Compiler’s Internal Data Structures Target Machine Description (VM) Translation Schemas CTNET'2006, UBI March. 17 g. EPL / DI-UM 26

Conclusion LISS is a toy imperative programming language !!! However it proved to be

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. CTNET'2006, UBI March. 17 g. EPL / DI-UM 27