Programming Language Independent Abstract Syntax Trees Nordic - - PowerPoint PPT Presentation

programming language independent abstract syntax trees
SMART_READER_LITE
LIVE PREVIEW

Programming Language Independent Abstract Syntax Trees Nordic - - PowerPoint PPT Presentation

Programming Language Independent Abstract Syntax Trees Nordic Workshop on Programming Theory 2003 Karl Trygve Kalleberg <karltk@ii.uib.no> Magne Haveraaen <magne@ii.uib.no> Department of Informatics University of Bergen, Norway


slide-1
SLIDE 1

Programming Language Independent Abstract Syntax Trees

Karl Trygve Kalleberg

<karltk@ii.uib.no>

Department of Informatics University of Bergen, Norway Magne Haveraaen

<magne@ii.uib.no>

Nordic Workshop on Programming Theory 2003

slide-2
SLIDE 2

Overview

  • Motivation

– Better understand common/emerging

  • Programming concepts
  • Language properties

– Language tool interoperability

  • Transformation
  • Refactoring
  • Approach

– Analysis + synthesis  formalism

slide-3
SLIDE 3

CSTs and ASTs

Plus Integer Integer BinaryOp 42 23 A = 42 + 23; Assign Var A Id A Stmt SEMI Expr BinaryOp Expr EQUAL Expr PLUS Expr Expr Integer 42 Integer 23

slide-4
SLIDE 4

Programming languages vs programming concepts

++++++++[>+++++++++<-]>.<+++++[>++++++<-]>-.+++++++.. +++.<++++++++[>>++++<<-]>>.<<++++[>------<-]>.<++++[> ++++++<-]>.+++.------.--------.>+. (λx. Display x) “Hello world” language

slide-5
SLIDE 5

Language evolution

  • New concepts expressed through

– Idioms

  • language-specific recipies

– Patterns

  • recipies common to a class of languages
  • New concepts require

– Adaptation to existing semantics – Possibly new syntax

slide-6
SLIDE 6

Evolution: if+goto

label: ... code ... if(cond) goto label; while(cond) { ... code ... } if(!cond) goto label1; ... code ... goto label2 label1: ... code ... label2: if(cond) { ... code ... } else { ... code ... }

slide-7
SLIDE 7

Evolution: assertions

  • Assertions in Java 1.4

if(!cond) throw new AssertionError(stringExpr); assert cond : stringExpr;

slide-8
SLIDE 8

Evolution: contracts

  • Pre/post conditions and class-invariants in

Eiffel

func(arg: TYPE) is require boolean-expression ... do body ... ensure boolean-expression ... end

slide-9
SLIDE 9

Use case: CodeBoost

AST CST CST Source code AST CST CST Source code

Refine to obtain accurate information Perform transformation Emit code

slide-10
SLIDE 10

Accurate information

  • for(exp1; exp2; exp3) body;
  • Undecideable termination
  • Sugar for exp1; while(exp2){body; exp3;}
  • for x in [1,2,3]: body
  • Will always terminate
  • map(λx.body, [1,2,3])
slide-11
SLIDE 11

Structuring and reuse

  • Many concepts

– Classes, inheritance, aspects, coordination,

patterns, best practices

  • Fewer constructs

– package, class, template

  • Experimentation easier at the abstract level

– Not compounded by syntax – Allows domain-specific structuring

slide-12
SLIDE 12

Conclusion

  • Build more abstract AST using accurate

information

– Support language evolution in tandem with

concept evolution

– Increase convenience for tools – Simplify reasoning for programmer

  • Not a new language!

– Represented in contemporary languages