Upload
dulcea
View
50
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
Extending Repleo with static semantic checking using JastAdd(J)Jos Peeters
/ name of department PAGE 204/22/23
• Goal• Introduction • Repleo• JastAdd(J)• Coupling Concept
• Progress• Proof of Concept - Booleans• Typechecking Java• Adding placeholders
/ 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
/ name of department PAGE 404/22/23
Introduction
• Repleo• JastAdd• JastAddJ
• Concept
/ name of department PAGE 504/22/23
Repleo
/ 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 %>
/ 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
/ 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 ::=
/ 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());…
}
/ 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
/ name of department PAGE 1104/22/23
JastAddJ
/ name of department PAGE 1204/22/23
Coupling Concept
/ name of department PAGE 1304/22/23
Progress
• Proof of concept: Booleans• Typechecking Java• Adding placeholders
/ 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 ::= ;
/ 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;
}
/ name of department PAGE 1604/22/23
Typechecking Java
• Connection• SDF definition• JastAddJ definition
• JastAddJ parser• rewrite of production rules• additional instantiation of checker
/ 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
/ 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
/ 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
/ 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() {}
}
/ 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
/ name of department PAGE 2204/22/23
Questions