Extending Repleo with Static Semantic Checking using JastAddJ
220 likes | 320 Views
Explore how to enhance Repleo with static semantic checking by leveraging JastAddJ to support additional checks for placeholders and improve error handling.
Extending Repleo with Static Semantic Checking using JastAddJ
E N D
Presentation Transcript
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 / name of department
Goal • Repleo • Syntax safe • Static semantics? • Goal • Extend Repleo to support static semantic checking • Create additional checks concerning placeholders • Get coffee / name of department
Introduction • Repleo • JastAdd • JastAddJ • Concept / name of department
Repleo / name of department
Repleo – Placeholders • Substitution <% Expr %> • Iterator <% foreach Expr do %> Subtemplate <% od %> • Conditional <% if Expr then %> Subtemplate1 <% else %> Subtemplate2 <% fi %> / name of department
JastAdd • Java based compiler compiler system • Designed to support analyzers, transformation tools, etc. • Main Feature: Extention of Reference Attribute Grammars / name of department
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
JastAdd – Aspect Weaving • Reference Attribute Grammars (RAGs) • syn • inh • eq aspect BinaryNumberValue { syn double Bit.value(); inh int Bit.scale(); … eq Zero.value() = 0 eq One.value() = java.lang.Math.pow(2.0, scale()); … } / name of department
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
JastAddJ / name of department
Coupling Concept / name of department
Progress • Proof of concept: Booleans • Typechecking Java • Adding placeholders / name of department
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
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
Typechecking Java • Connection • SDF definition • JastAddJ definition • JastAddJ parser • rewrite of production rules • additional instantiation of checker / name of department
Java – Observations • Properties • Direct (explicit) access of typed attributes • Design decisions JastAddJ • Reduce number of tree traversals • Inability of accessing siblings / name of department
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
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
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
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
Questions / name of department