1 semântica de ações ações básicas, ações funcionais e notação de dados

Post on 19-Apr-2015

107 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Semântica de Ações

Ações Básicas, Ações Funcionais e Notação de Dados

2

Notação de Ações Básica

ações básicas são usadas para especificar fluxo de controle

ações básicas não estão relacionadas com nenhuma espécie de informação corrente

a execução de uma ação consiste de passos atômicos de execução, feitos por um ou mais agentes

consideraremos um único agente

3

Ações Básicas

ações primitivascomplete : action .escape : action .fail : action .diverge : action .commit : action .unfold : action .

4

Ações Básicas (cont.)

combinadores de açõesunfolding _ :: action -> action ._ or _ :: action, action -> action ._ and _ :: action, action -> action ._ and then _ :: action, action -> action .

5

Exemplos de Ações Básicas

completecomplete or failcomplete and then failunfolding (unfold or fail)

6

Semântica da Notação de Ações

Regras de Inferência (Semântica Natural)

antecedente1 antecedente2 ... antecedenten

consequente

Açõest, b, s |- a > o, t’, b’, s’

Produtorest, b, s |- y > d

Semântica das Ações Básicast, b, s |- complete > completed, (), {}, s

t, b, s |- a1 > completed, t1, b1, s1 t, b, s1 |- a2 > completed, t2, b2, s2

mergeable b1 b2

t, b, s |- a1 and a2 > completed, t1 ^ t2, b1 + b2, s2

(COMPLETE)

(AND-3)

(AND-2)

(AND-1)

t, b, s |- a1 > o1, t1, b1, s1 o1 <> completed

t, b, s |- a1 and a2 > o1, t1, b1, s1

t, b, s |- a1 > completed, t1, b1, s1 t, b, s1 |- a2 > o2, t2, b2, s2

o2 <> completed

t, b, s |- a1 and a2 > o2, t2, b2, s2

t, b, s |- fail > failed, (), {}, s (FAIL)

8

Comandos

/NanoSpecimen/Abstract Syntax/Comandos

grammar:(1) Comando = [[ Identificador := Expressão ]]

| [[ while Expressão do Comando end ]]| [[ local Declaração in Comando end ]]| [[ Comando ; Comando ]] .

/NanoSpecimen/Semantic Functions/Comandos

introduces: execute _ .

execute _ :: Comando -> action .

(1) ...

(2) execute [[ while E:Expressão do C:Comando ]] =unfolding

| | evaluate E| then| | | check (it is 1) and then execute C and then unfold| | or| | | check not (it is 1) .

(3) …

(4) execute [[ C1:Comando ; C2:Comando ]] =execute C1 and then execute C2 .

11

Notação de Ações Funcional

açõesgive _ :: yielder -> action .regive : action .choose _ :: yielder -> action .check _ :: yielder -> action ._ then _ :: action, action -> action .

produtoresgiven _ :: data -> yielder .given _ # _ :: datum, positive-integer -> yielder .it : yielder .

12

Exemplos de Ações Funcionais

give 5give sum(3,4)choose a natural(check true and then give 1) or (check not true

and then give 0)

Semântica das Ações Funcionais

t, b, s |- y > d

t, b, s |- give y > completed, (d), {}, s

t, b, s |- a1 > completed, t1, b1, s1 t1, b, s1 |- a2 > completed, t2, b2, s2

t, b, s |- a1 then a2 > completed, t2, b1 + b2, s2

(GIVE)

(THEN-3)

(THEN-2)

(THEN-1)

t, b, s |- a1 > o1, t1, b1, s1 o1 <> completed

t, b, s |- a1 then a2 > o1, t1, b1, s1

t, b, s |- a1 > completed, t1, b1, s1 t1, b, s1 |- a2 > o2, t2, b2, s2

o2 <> completed

t, b, s |- a1 then a2 > o2, t2, b2, s2

/NanoSpecimen/Abstract Syntax/Expressões

grammar: Expressão = Numeral-Inteiro

| Identificador| [[ if Expressão then Expressão else Expressão ]]| [[ Identificador ( Expressão ) ]]| [[ Expressão Operador Expressão ]]| [[ ( Expressão ) ]] .

Operador = + | - | * | / | = | < .

/NanoSpecimen/Semantic Functions/Expressões

introduces: avalie _ .

avalie _ :: Expressão -> action .

(1) avalie N:Numeral-Inteiro = give the valor-de N .

(2) avalie I:Identificador =| give the integer bound to token-de Ior| give the integer stored in the cell bound to token-de I .

(3) avalie [[ I:Identificador ( E:Expressão ) ]] =| avalie Ethen| enact (application of the abstraction bound to token-de I

to the given integer) .

(4) avalie [[if E1:Expressão then E2:Expressão else E3:Expressão ]] =| avalie E1

then| | (check it is true) and then avalie E2

| or| | (check not(it is true) and then avalie E3 .

(5) avalie [[ E1:Expressão O:Operador E2:Expressão ]] =| avalie E1 and avalie E2

then| apliqueOperador O .

(6) avalie [[ ( E:Expressão ) ]] = avalie E .

/NanoSpecimen/Semantic Functions/Operadores

introduces: aplicaOperador _ .

aplicaOperador _ :: Operador -> action .

(1) aplicaOperador “+” =give sum(the given integer#1, the given integer#2) .

(2) aplicaOperador “-” =give difference(the given integer#1, the given integer#2) .

(3) aplicaOperador “*” =give product(the given integer#1, the given integer#2) .

(4) aplicaOperador “/” =give quotient(the given integer#1, the given integer#2) .

(5) aplicaOperador “=“ = | check (the given integer#1 is the given integer#2)| and then give 1or| check not(the given integer#1 is the given integer#2)| and then give 0 .

(6) aplicaOperador “<“ = | check (the given integer#1 is less than the given integer#2)| and then give 1or| check not(the given integer#1 is less than the given integer#2)| and then give 0 .

19

Notação de Dados

20

Notação de Dados

General.

Instant.

Tuples.

Truth-Values.

Numbers.

Characters.

Lists.

Strings.

Syntax.

Sets.

Maps.

21

Tuplas

Genericscomponent = .

Basicstuple > component.

() : tuple.

( _ , _ ) :: tuple, tuple tuple (total, associative, unit is ()).

_? :: tuple -> tuple .

_ * :: tuple -> tuple .

_ + :: tuple -> tuple .

_ - :: tuple, natural -> tuple .

22

Tuplas (cont.)

Specificscount _ :: tuple -> natural (total)._ is _ :: tuple, tuple -> truth-value (partial).

23

Booleanos (Truth-Values)

Basics truth-value = true | false (individual).

Specifics if _ then _ else_ :: truth-value, x, y -> x | y (linear) .when _ then _ :: truth-value, x - > x (partial) . there is _ :: x -> truth-value (total) .not _ :: truth-value -> truth-value (total) .both _ :: (truth-value,truth-value) -> truth-value .either _ :: (truth-value,truth-value) -> truth-value .

24

Números Naturais

Basics natural = 0 | positive-integer (disjoint). 0 : natural. successor _ :: natural positive-integer (total, injective).

Specifics 1, 2, 3, 4, 5, 6, 7, 8, 9 : natural. _0, _1, _2, _3, _4, _5, _6, _7, _8, _9 : natural natural (total). sum _ :: natural* natural (total, associative, commutative, unit is 0). product _ :: natural* natural (total, associative, commutative, unit is 1).

25

Números Inteiros

Basics integer = 0 | nonzero-integer (disjoint).nonzero-integer = positive-integer | negative-integer (disjoint). successor _ :: integer integer (total, injective).predecessor _ :: integer integer (total, injective).

Specificsnegation _ :: integer integer (total).absolute _ :: integer integer (total).difference _ :: (integer, integer) integer (total).

26

Caracteres

Basicscharacter = .character of _ :: natural -> character (partial, injective) .code _ :: character -> natural (total, injective) .

Alphanumericscharacter >= digit | letter (disjoint) .digit = ‘0’ | ‘1’ | ... | ‘9’ (individual) . letter = lowercase letter | uppercase letter (disjoint) . lowercase _ :: character -> character (total).uppercase _ :: character -> character (total).

27

Caracteres (cont.)

ASCIIcode _ :: character -> natural [max octal “177”] (total) .character = graphic-character | control-character .

28

Generics item = .

Basics flat-list = list of item*. list of _ :: item* flat-list (total, injective).

Specifics _ [_] :: flat-list, item flat-list. items _ :: flat-list items* (total, injective). head _ :: flat-list item (partial). tail _ :: flat-list flat-list (partial). empty-list : flat-list. concatenation _ :: flat-list* flat-list (total, associative, unit is empty-list).

Listas Não-aninhadas

29

Generics leaf = item | .

Basics list = list of tree* . tree = leaf | list (disjoint) . list of _ :: tree* -> list (total, injective) .

Listas Aninhadas

30

Listas Aninhadas (cont.)

Specifics _ [ _ ] :: list, tree -> list . branches _ :: list -> tree* (total, injective) . leaves _ :: head _ :: tail _ :: empty-list : list . concatenation _ :: list* -> list (total, associative, unit is empty-list) .

31

Basics character item. string = flat-list [character]. string of _ :: character* string (total, injective). characters _ :: string character* (total, injective). ““ : string. _ ^ _ :: string, string string (total, associative, unit is ““).

Alphanumerics lowercase _ :: string string (total). uppercase _ :: string string (total). decimal _ :: string of digit+ natural (total). octal _ :: string of octal-digit+ natural (total). octal-digit = ‘0’ | ‘1’ | ‘2’ | ‘3’ | ‘4’ | ‘5’ | ‘6’ | ‘7’.

Strings

32

Basics syntax-tree = character | list [syntax-tree] (disjoint) .

Specifics [[ ]] : syntax-tree. [[ _ ]] :: syntax-tree* syntax-tree (total) . [[ _ _ ]] :: syntax-tree*, syntax-tree* syntax-tree (total) .

... : syntax-tree* . : syntax-tree* syntax-tree (total) . : syntax-tree*, syntax-tree* syntax-tree (total) .

...

Sintaxe (Árvores Sintáticas)

33

Generics nonset-element = . _ is _ :: nonset-element, nonset-element truth-value (total).

Basics set = set of element*. element = nonset-element | set (disjoint). set of _ :: element* set (individual).

Conjuntos

34

Conjuntos (cont.)

Specifics_ [ _ ] :: set, element set.elements _ :: set element* (strict, linear).empty-set : set._ [in _ ] :: element, set element (partial)._ [not in _] :: element, set element (partial).

35

Generics nonmap-range = .

Basics map = disjoint-union (map of element to range)*. range = nonmap-range | map (disjoint). map of _ to _ :: element, range map (total, injective). empty-map : map. disjoint-union _ :: map* map

(partial, associative, commutative, unit is empty-map) . mapped-set _ :: map -> set (total) .

Mapeamentos

36

Mapeamentos (cont.)

Specifics _ [ _ to _ ] :: set, element set . _ at _ :: map, element range (partial) . overlay _ :: map* map (total, associative, idempotent,

unit is empty-map) . _ restricted to _ :: map, set -> map (total) . _ omitting _ :: map, set -> map (total) .

37

Action Notation/Basic/Data

includes: Data Notation/General . datum <= component . datum >= truth-value | rational | character | list | set | map |

abstraction (disjoint) . distinct-datum <= datum . distinct-datum >= truth-value | rational | character |

list [distinct-datum] | set [distinct-datum] | map [distinct-datum to distinct-datum] .

includes: Data Notation/Instant/Distinction (distinct-datum for s). data = datum* . a _, an _, the _, of _, some _ :: data -> data (total) .

38

Algumas Inclusões entre Sortes de Dados Padrões

tuple

item

truth-value

component

flat-listcharacter

string

set

approximation

map

range

tree

nonmap-range

listsyntax-tree

positive-rationalnatural

0

nonzero-rationalleaf

integer

rational

letterdigit

element

nonset-element

graphic-charactercontrol-character

nonzero-integer negative-rational

negative-integerpositive-integer

/NanoSpecimen/Abstract Syntax

needs: DataNotation/Characters/ASCII (letter, digit)closed.grammar:

Identificadores

Identificador = letter | Identificador letter | Identificador digit .

Literais

Numeral-Inteiro = digit | Numeral-Inteiro digit .

/NanoSpecimen/Semantic Functions/Identificadores

introduces: token-de _ .

token-de _ :: Identificador -> token .

(1) token-de I:Identificador = I .

/NanoSpecimen/Semantic Functions/Literais

introduces: valor-de _ .

valor-de _ :: Numeral-Inteiro -> integer .

(1) valor-de [[ 0 ]] = 0 . ...

(10) valor-de [[ 9 ]] = 9 .

(11) valor-de [[ N D ]] = sum (product (valor-de N, 10), valor-de D) .

41

Resumo/Notação de Dados

A notação de tuplas inclui uma forma de expressões regulares.

Tuplas são usadas para prover operações com um número arbitrário de argumentos.

Vários sortes, como component, são deixados abertos para uma especialização quando necessária.

Caracteres podem ser especializados para qualquer conjunto de caracteres desejado, como ASCII, por exemplo.

42

Resumo/Notação de Dados

Listas, conjuntos e mapeamentos podem ser aninhados, enquanto tuplas podem ser só concatenadas.

Árvores sintáticas têm unicamente caracteres como ramos. Strings são listas planas de caracteres, por isso também árvores sintáticas.

top related