22
Extending Repleo with static semantic checking using JastAdd(J) Jos Peeters

Extending Repleo with static semantic checking using JastAdd(J)

  • Upload
    dulcea

  • View
    45

  • Download
    3

Embed Size (px)

DESCRIPTION

Extending Repleo with static semantic checking using JastAdd(J). Jos Peeters. Goal Introduction Repleo JastAdd(J) Coupling Concept Progress Proof of Concept - Booleans Typechecking Java Adding placeholders. Goal. Repleo Syntax safe Static semantics? Goal - PowerPoint PPT Presentation

Citation preview

Page 1: Extending Repleo with static semantic checking using JastAdd(J)

Extending Repleo with static semantic checking using JastAdd(J)Jos Peeters

Page 2: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 204/22/23

• Goal• Introduction • Repleo• JastAdd(J)• Coupling Concept

• Progress• Proof of Concept - Booleans• Typechecking Java• Adding placeholders

Page 3: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 304/22/23

Goal

• Repleo• Syntax safe• Static semantics?

• Goal• Extend Repleo to support static semantic checking• Create additional checks concerning placeholders • Get coffee

Page 4: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 404/22/23

Introduction

• Repleo• JastAdd• JastAddJ

• Concept

Page 5: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 504/22/23

Repleo

Page 6: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 604/22/23

Repleo – Placeholders

• Substitution<% Expr %>

• Iterator<% foreach Expr do %>Subtemplate

<% od %>

• Conditional<% if Expr then %>Subtemplate1

<% else %>Subtemplate2

<% fi %>

Page 7: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 704/22/23

JastAdd

• Java based compiler compiler system• Designed to support analyzers, transformation tools,

etc.• Main Feature: Extention of Reference Attribute

Grammars

Page 8: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 804/22/23

JastAdd – Defining languages

• EBNF format<nonterminal name> : <inherits from> ::= <production rule>

abstract BinNumber;IntegNumber : BinNumber ::= IntegPart:BitList;RatNumber : BinNumber ::= IntegPart:BitList FracPart:BitList;abstract BitList;SingularBitList : BitList ::= Bit;PluralBitList : BitList ::= BitList Bit;abstract Bit;Zero : Bit ::= ;One : Bit ::=

Page 9: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 904/22/23

JastAdd – Aspect Weaving

• Reference Attribute Grammars (RAGs)• syn• inh• eq

aspect BinaryNumberValue {syn double Bit.value();inh int Bit.scale();…eq Zero.value() = 0eq One.value() = java.lang.Math.pow(2.0, scale());…

}

Page 10: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1004/22/23

JastAdd – JastAddJ

• Java compiler created with JastAdd• Semantic analysis for Java1.4• Scanner en parser included• JFlex (LEX descendent)• Beaver (YACC descendent)

• Definition/handling of production rules largely only in the parser definition

Page 11: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1104/22/23

JastAddJ

Page 12: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1204/22/23

Coupling Concept

Page 13: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1304/22/23

Progress

• Proof of concept: Booleans• Typechecking Java• Adding placeholders

Page 14: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1404/22/23

Proof of Concept – Booleans"(" BoolExp ")" -> BoolExp {bracket,cons("bracket")}"not" "(" BoolExp ")" -> BoolExp {cons("not")}lhs:BoolExp "&" rhs:BoolExp -> BoolExp {left, cons("and")}lhs:BoolExp "|" rhs:BoolExp -> BoolExp {left, cons("or")}BoolCon -> BoolExp {cons("constant")}"true" -> BoolCon {cons("booltrue")}"false" -> BoolCon {cons("boolfalse")}

BoolRoot ::= BoolExp;abstract BoolExp;bracket : BoolExp ::= BoolExp;not : BoolExp ::= BoolExp;and : BoolExp ::= lhs: BoolExp rhs: BoolExp;or : BoolExp ::= lhs: BoolExp rhs: BoolExp;constant : BoolExp ::= BoolCon;abstract BoolCon;booltrue : BoolCon ::= ;boolfalse : BoolCon ::= ;

Page 15: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1504/22/23

Booleans(2)

aspect Booleanvalue {syn boolean BoolRoot.value();syn boolean BoolExp.value();syn boolean BoolCon.value();

eq BoolRoot.value() = getBoolExp().value();

eq and.value() = getlhs().value() && getrhs().value();

eq or.value() = getlhs().value() || getrhs().value();

eq not.value() = ! getBoolExp().value();eq bracket.value() = getBoolExp().value();

eq booltrue.value() = true;eq boolfalse.value() = false;

}

Page 16: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1604/22/23

Typechecking Java

• Connection• SDF definition• JastAddJ definition

• JastAddJ parser• rewrite of production rules• additional instantiation of checker

Page 17: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1704/22/23

Java – Observations

• Properties• Direct (explicit) access of typed attributes

• Design decisions JastAddJ• Reduce number of tree traversals• Inability of accessing siblings

Page 18: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1804/22/23

Java – Implementation

• It works!• Not the whole language supported (yet), but almost• “creative” solutions needed to deal with

language/parser differences

• Tools used• ImplodePT• AddPosInfo

Page 19: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 1904/22/23

Adding placeholders

• Partial evaluation done by Repleo• Extracting placeholder subtrees from PT

• Current challenge• Catching typecheck errors/warning caused by

placeholders• Additional checking requirements for conditional and

iterative placeholders• Dealing with ambiguities

Page 20: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 2004/22/23

Ambiguity example

Template:public class Example {<% x %> <% y %>() {}

}

Two possible production rules apply:public class Example {public Example() {}

}

public class Example {int Something() {}

}

Page 21: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 2104/22/23

Ambiguities and JastAdd

• How to introduce an ambiguous/generic node into JastAdd?• Constructors have explicitly types attributes• Typechecker has (via attributes) direct contact with its

children and its parent

Page 22: Extending Repleo with static semantic checking using JastAdd(J)

/ name of department PAGE 2204/22/23

Questions