• Keine Ergebnisse gefunden

List Terms as Sets

N/A
N/A
Protected

Academic year: 2022

Aktie "List Terms as Sets"

Copied!
14
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

2. Katja Laboratory Attribute Functions with Katja

Lecture Compilers SS 2011

Jan Schäfer (slides by Jean-Marie Gaillourdet)

Software Technology Group TU Kaiserslautern

(2)

Navigation

Generic Navigation on Term-Positions

parent() parent node in tree, or null if root

root() top most element of term position structure lsib() left sibling

rsib() right sibling

size() number of children,nfor an-tuple, or length of a list get(int n) get the nth child

position() this.parent().get(this.position()) == thisor-1 All functions returns the best possible type, safe to assumeSortPos.

(3)

Navigation

Path Navigation

Path

A path is aList<Integer>denoting the sequence of arguments toget() in order to reach a certain term position (usually starting from the root).

List<Integer> path() get the path from theroot()to this

List<Integer> pathFrom(SortPos p) get the path to reachthis fromp

SortPos follow(List<Integer> path)

(4)

Lists

List Terms

list element sort:E, list sort:Es

Es appFront(E e),Es appBack(E e) append front / back Es addAll(KatjaList<? extends E>) es add all elements ofes

Es conc(Es es) concatenate withes Es reverse() reverse the list Es remove(E e) removee

Es removeAll(KatjaList<E> es) remove all element ofes E first(), E last() get first / last element Es front(), Es back() get all but last / first

elements

boolean contains(E e) check ifeis contained boolean containsAll(KatjaList<E> es) check if all elements ofes

are contained

(5)

Lists

List Terms as Sets

Handle lists as sets.

Es toSet() remove all duplicates Es setAdd(E e) add element

Es setRemove(E e) remove elemente

boolean setEquals(Es es) compare two lists as sets Es setIntersection(Es es) intersection

Es setUnion(Es es) union Es setWithout(Es es) without

(6)

Visiting Trees

Tree walking

Post-Order (from left to right)

postOrder() get next element in post-order

postOrderStart() get first element to visit subtree in post-order

Pre-Order (from left to right)

preOrder() get next element in pre-order

preOrderSkip() get next element in pre-order skipping all children

(7)

Visiting Trees

Visitor

every sort provides a nested interface VisitorType<E extends Throwable>

I has a methodvisitS(S s) throws Efor every sort which might appear below

I there iskatja.common.NE, which is subtype ofThrowable, to declare no exception

every sort provides a nested abstract static class Visitor<E extends Throwable>

I it implementsVisitorType<E>

I it provides implementations for all methodsvisitVifVis a variant

every root position sort provides DefaultVisitor<E extends Throwable>>

I implements allVisitorTypes of sorts which may appear in position structure

I provides default implementations of all methods

to start visiting an term/position of typeScallvisitS

(8)

Visiting Trees

Visitor (2)

when overriding methodvisitS(...)there are two options

I callsuper.visitS(...)

I callthis.visitT(...)for every child!

(9)

Visiting Trees

Utilities

String KatjaElement.Utilities.prettyPrint(String s)It allows to post-process the output of atoString()method in order to prettify the output.

cast() cast to the "right" type

<T>cast() cast toT

(10)

Visiting Trees

Extended Expressions

let x = in 4 + x end

let x = 5 + let y = 3 in y + 2 end in x - 2 end let x = 4 in let x = 2 in x - 2 end end

(11)

Visiting Trees

Extendend Expressions

specification Expressions [... backend block ...]

external Int external String root Expression Pos

Expression = Literal ( Int value )

| Variable ( String name )

| Plus ( Expression left, Expression right)

| Minus ( Expression left, Expression right)

| Mult ( Expression left, Expression right)

| Div ( Expression left, Expression right)

| Let ( Variable definedVar, Expression assigned, Expression body )

VariablePosList * VariablePos

(12)

Visiting Trees

Problem 1

Attribute function:LetPos declaration(VariablePos var)

I find the binding let for a variable occurence

Attribute function:VariablePosList usages(LetPos let)

I find all usages of the variable bound by this let

(13)

Visiting Trees

Problem 2

implement a method to remove unused lets

(14)

Visiting Trees

Problem 3

implement a method to inline lets which are used only once

Referenzen

ÄHNLICHE DOKUMENTE

Including the American Democratic Party in a comparative analysis of center- left parties is unorthodox, since unlike Europe, America has not pro- duced a socialist movement tied to

[r]

E integer Bercidanung string Ereignisse Wii folgori

The cholesteric structure of certain liquid crystals can be converted to nematic by application of elec- tric or magnetic fields (see e.g. That means that the helical arrangement

The analysis of fine-root traits revealed that irrigation significantly increased biomass, length, and production, but did not alter morphological and architectural traits, such

Their original fuzzy interactive methods assumed that the membership functions related to at- tainment levels for separate objectives or criteria values are specified a

By assuming the existence of the Speech Act Phrase in German, I propose structure (19) for German main clauses and adverbial clauses that allow sentence adverbs and modal particles to

[r]