70
Logic Characterization of Invisibly Structured Languages: the Case of Floyd Languages Violetta Lonati 2 Dino Mandrioli 1 Matteo Pradella 1 (1) DEIB - Politecnico di Milano (2) DI - Universit` a degli Studi di Milano SOFSEM 2013 Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 1 / 17

Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Logic Characterization of Invisibly StructuredLanguages: the Case of Floyd Languages

Violetta Lonati2 Dino Mandrioli1 Matteo Pradella1

(1) DEIB - Politecnico di Milano(2) DI - Universita degli Studi di Milano

SOFSEM 2013

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 1 / 17

Page 2: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Outline

1 Background and motivations

2 Floyd’s Operator-precedence languages

3 Automata for Operator-precedence languages

4 Logic

5 Applications and Conclusions

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 2 / 17

Page 3: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Background (1)

Floyd’s Operator-precedence languages

R. Floyd introduced Operator-precedence (OP) grammars in 1963,inspired by the structure of arithmetic expressions, and aimed atdeterministic parsing of programming languages

Early investigation on the algebraic and closure propertiese.g. in [Crespi Reghizzi, Mandrioli and Martin 1978].

Interest on OP languages was “virtually killed” by Knuth’s LRalgorithm.

OP parsers are simple and efficient, still sometimes used in practice(e.g. for evaluating arithmetic expressions in gcc)

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 3 / 17

Page 4: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Background (1)

Floyd’s Operator-precedence languages

R. Floyd introduced Operator-precedence (OP) grammars in 1963,inspired by the structure of arithmetic expressions, and aimed atdeterministic parsing of programming languages

Early investigation on the algebraic and closure propertiese.g. in [Crespi Reghizzi, Mandrioli and Martin 1978].

Interest on OP languages was “virtually killed” by Knuth’s LRalgorithm.

OP parsers are simple and efficient, still sometimes used in practice(e.g. for evaluating arithmetic expressions in gcc)

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 3 / 17

Page 5: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Background (2)

After 40+ years

Visibly Pushdown (VP) languages [Alur and Madhusudan 2004]

they exhibit many closure properties of regular languages(Boolean, concatenation, Kleene’s ∗, . . . )

suitable to model structured mark-up languages such as XML;properties enable model checking.

Floyd’s OP languages are back

OP languages actually include VP languages and enjoy the sameclosure properties

[Crespi Reghizzi, Mandrioli 2009]

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 4 / 17

Page 6: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Background (2)

After 40+ years

Visibly Pushdown (VP) languages [Alur and Madhusudan 2004]

they exhibit many closure properties of regular languages(Boolean, concatenation, Kleene’s ∗, . . . )

suitable to model structured mark-up languages such as XML;properties enable model checking.

Floyd’s OP languages are back

OP languages actually include VP languages and enjoy the sameclosure properties

[Crespi Reghizzi, Mandrioli 2009]

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 4 / 17

Page 7: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Example: parsing arithmetic expressions

The classical context-free grammar for arithmetic expressions:

S → EE → E + TE → T × nE → nT → T × nT → n

n + n × n

S

E

E

n

+ T

T

n

× n

This grammar is such that × takes precedence over + (as usual):n + n × n

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 5 / 17

Page 8: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Example: parsing arithmetic expressions

The classical context-free grammar for arithmetic expressions:

S → EE → E + TE → T × nE → nT → T × nT → n

n + n × n

S

E

E

n

+ T

T

n

× n

This grammar is such that × takes precedence over + (as usual):n + n × n

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 5 / 17

Page 9: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Example: parsing arithmetic expressions

The classical context-free grammar for arithmetic expressions:

S → EE → E + TE → T × nE → nT → T × nT → n

n + n × n

S

E

E

n

+ T

T

n

× n

This grammar is such that × takes precedence over + (as usual):n + n × n

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 5 / 17

Page 10: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Example: parsing arithmetic expressions

The classical context-free grammar for arithmetic expressions:

S → EE → E + TE → T × nE → nT → T × nT → n

n + n × n

S

E

E

n

+ T

T

n

× n

This grammar is such that × takes precedence over + (as usual):n + n × n

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 5 / 17

Page 11: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Example: parsing arithmetic expressions

The classical context-free grammar for arithmetic expressions:

S → EE → E + TE → T × nE → nT → T × nT → n

n + n × n

S

E

E

n

+ T

T

n

× n

This grammar is such that × takes precedence over + (as usual):n + n × n

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 5 / 17

Page 12: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s idea

A method for inserting parentheses into an expression is based onprecedence relations between terminal symbols

a l b (a yields precedence over b)

a m b (a takes precedence over b)

a � b (a equals in precedence b)

For each pair of symbols we determine the proper precedence and obtainthe precedence table

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 6 / 17

Page 13: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s idea

A method for inserting parentheses into an expression is based onprecedence relations between terminal symbols

a l b (a yields precedence over b)

a m b (a takes precedence over b)

a � b (a equals in precedence b)

For each pair of symbols we determine the proper precedence and obtainthe precedence table

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 6 / 17

Page 14: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s idea

A method for inserting parentheses into an expression is based onprecedence relations between terminal symbols

a l b (a yields precedence over b)

a m b (a takes precedence over b)

a � b (a equals in precedence b)

For each pair of symbols we determine the proper precedence and obtainthe precedence table

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 6 / 17

Page 15: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s idea

A method for inserting parentheses into an expression is based onprecedence relations between terminal symbols

a l b (a yields precedence over b)

a m b (a takes precedence over b)

a � b (a equals in precedence b)

For each pair of symbols we determine the proper precedence and obtainthe precedence table

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 6 / 17

Page 16: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Precedence table - example

In a sense, there are no visible parentheses, but precedence relationsintroduce invisible ones, e.g.:

Precedence table

n + × #n m m m

+ l m l m

× = m

# l l l =

n + n × n

# l n � + lnm︸︷︷︸× � n m#

# l n � +l× � nm︸ ︷︷ ︸#

#ln � +m︸ ︷︷ ︸#

#=#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 7 / 17

Page 17: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Precedence table - example

In a sense, there are no visible parentheses, but precedence relationsintroduce invisible ones, e.g.:

Precedence table

n + × #n m m m

+ l m l m

× = m

# l l l =

# is the boundary symbol

n + n × n

# l n � + lnm︸︷︷︸× � n m#

# l n � +l× � nm︸ ︷︷ ︸#

#ln � +m︸ ︷︷ ︸#

#=#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 7 / 17

Page 18: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Precedence table - example

In a sense, there are no visible parentheses, but precedence relationsintroduce invisible ones, e.g.:

Precedence table

n + × #n m m m

+ l m l m

× = m

# l l l =

# is the boundary symbol

n + n × n

# l n � + lnm︸︷︷︸× � n m#

# l n � +l× � nm︸ ︷︷ ︸#

#ln � +m︸ ︷︷ ︸#

#=#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 7 / 17

Page 19: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Precedence table - example

In a sense, there are no visible parentheses, but precedence relationsintroduce invisible ones, e.g.:

Precedence table

n + × #n m m m

+ l m l m

× = m

# l l l =

# is the boundary symbol

n + n × n

# l n � + lnm︸︷︷︸× � n m#

# l n � +l× � nm︸ ︷︷ ︸#

#ln � +m︸ ︷︷ ︸#

#=#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 7 / 17

Page 20: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Precedence table - example

In a sense, there are no visible parentheses, but precedence relationsintroduce invisible ones, e.g.:

Precedence table

n + × #n m m m

+ l m l m

× = m

# l l l =

# is the boundary symbol

n + n × n

# l n � + lnm︸︷︷︸× � n m#

# l n � +l× � nm︸ ︷︷ ︸#

#ln � +m︸ ︷︷ ︸#

#=#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 7 / 17

Page 21: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s Operator-precedence grammars

Operator grammar

A CF grammar is an operator grammar if no right-hand side contains twoconsecutive nonterminals (and it is not empty).

OP grammar

An operator grammar is a operator-precedence grammar if there are noconflicts in its precedence matrix

i.e. given a pair of symbols, there is at most one precedence relation.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 8 / 17

Page 22: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Floyd’s Operator-precedence grammars

Operator grammar

A CF grammar is an operator grammar if no right-hand side contains twoconsecutive nonterminals (and it is not empty).

OP grammar

An operator grammar is a operator-precedence grammar if there are noconflicts in its precedence matrix

i.e. given a pair of symbols, there is at most one precedence relation.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 8 / 17

Page 23: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

OP automata are stack-based

The stack alphabet consists of pairs [ a q ] wherea is a symbol from the input alphabet,q is a state.

Variant: the symbol may be marked [ a′ q ]

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 9 / 17

Page 24: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

OP automata are stack-based

The stack alphabet consists of pairs [ a q ] wherea is a symbol from the input alphabet,q is a state.

Variant: the symbol may be marked [ a′ q ]

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 9 / 17

Page 25: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;

note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 26: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;

note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 27: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;

note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 28: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;

note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 29: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;note: b is not consumed (look-ahead);

note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 30: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 31: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Operator-precedence Automata

3 kinds of moves, depending on the precedence relation between thesymbol a on top of the stack and next input symbol b:

push move when a � bb is pushed on the stack

mark move when a l bb ′ is pushed on the stack

flush move when a m bpop from the stack until a marked symbol c′ is found;note: b is not consumed (look-ahead);note: c′ is popped as well (look-back).

e.g. in n+︷ ︸︸ ︷l × nm#, × is marked, + is the look-back and

# the look-ahead.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 10 / 17

Page 32: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

Dyck language with parentheses pairs a, a (high priority) and b , b.

High priority means that a closes both an a and every pending b afterit; e.g. ︷ ︸︸ ︷

a b b︷ ︸︸ ︷b︷︸︸︷

aa b a

also, it is required that the string has only top-level a pairs (e.g. itcannot start with b).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 11 / 17

Page 33: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

Dyck language with parentheses pairs a, a (high priority) and b , b.

High priority means that a closes both an a and every pending b afterit; e.g. ︷ ︸︸ ︷

a b b︷ ︸︸ ︷b︷︸︸︷

aa b a

also, it is required that the string has only top-level a pairs (e.g. itcannot start with b).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 11 / 17

Page 34: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

Dyck language with parentheses pairs a, a (high priority) and b , b.

High priority means that a closes both an a and every pending b afterit; e.g. ︷ ︸︸ ︷

a b b︷ ︸︸ ︷b︷︸︸︷

aa b a

also, it is required that the string has only top-level a pairs (e.g. itcannot start with b).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 11 / 17

Page 35: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 36: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 37: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

mark

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 38: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 39: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

mark

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 40: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 41: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

mark

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 42: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 43: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

mark

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 44: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 45: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

push

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 46: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 47: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

flush

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 48: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 49: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

push

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 50: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][b q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 51: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

flush

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1][b ′ q1][b q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 52: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 53: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

flush

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][b ′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 54: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 55: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

push

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 56: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][a q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 57: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

flush

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0][a′ q1][a q1] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 58: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 59: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

An example automaton

restart skip

Dyck language with parentheses pairs a, a (high priority) and b , b.

a a b b #

a l = l

a l m l m m

b l m l =

b l m l m

# l l =

q0 q1

a

a , a , b , b

q1q0

accept

[# q0][a′ q1][b ′ q1][b ′ q1][a′ q1][a q1]

[# q0] abbaaba#

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 12 / 17

Page 60: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Equivalence theorems

Deterministic OP automata are equivalent to nondeterministic ones.

OP grammars and automata have the same expressive power.

[Lonati, Mandrioli, Pradella 2011]

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 13 / 17

Page 61: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

A logic for operator-precedence languages

The MSOΣ,M (monadic second-order logic) is interpreted over(Σ,M) strings, and it is defined by the following syntax

where a ∈ Σ, x, y are first-order variables (representing positions inthe string) and X is a set variable.

ϕ :=a(x) | x ∈ X | x ≤ y | x = y + 1 | ¬ϕ | ϕ ∨ ϕ | ∃x.ϕ | ∃X .ϕ |x y y matching relation

Intuitively, x y y holds iff positions x and y are to become “adjacent”during parsing

i.e. the symbol at x is used as look-back, and the one at y aslook-ahead in a flush move.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 14 / 17

Page 62: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

A logic for operator-precedence languages

The MSOΣ,M (monadic second-order logic) is interpreted over(Σ,M) strings, and it is defined by the following syntax

where a ∈ Σ, x, y are first-order variables (representing positions inthe string) and X is a set variable.

ϕ :=a(x) | x ∈ X | x ≤ y | x = y + 1 | ¬ϕ | ϕ ∨ ϕ | ∃x.ϕ | ∃X .ϕ |x y y matching relation

Intuitively, x y y holds iff positions x and y are to become “adjacent”during parsing

i.e. the symbol at x is used as look-back, and the one at y aslook-ahead in a flush move.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 14 / 17

Page 63: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

A logic for operator-precedence languages

The MSOΣ,M (monadic second-order logic) is interpreted over(Σ,M) strings, and it is defined by the following syntax

where a ∈ Σ, x, y are first-order variables (representing positions inthe string) and X is a set variable.

ϕ :=a(x) | x ∈ X | x ≤ y | x = y + 1 | ¬ϕ | ϕ ∨ ϕ | ∃x.ϕ | ∃X .ϕ |x y y matching relation

Intuitively, x y y holds iff positions x and y are to become “adjacent”during parsing

i.e. the symbol at x is used as look-back, and the one at y aslook-ahead in a flush move.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 14 / 17

Page 64: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Logic-Automata equivalence

The construction from logic to automata is quite standard

From automata to logic, it is not:

Finite-state and VP automata are real-time machines;OP automata are not, so it is not easy to represent their runtimeconfiguration in logic;Indeedy represents a relation that is not one-to-one(the structure can be invisible).

In parenthesis languages (like VPL) the structure is visible;the analogous ofy in VPL matches parentheses (one-to-one).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 15 / 17

Page 65: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Logic-Automata equivalence

The construction from logic to automata is quite standard

From automata to logic, it is not:

Finite-state and VP automata are real-time machines;OP automata are not, so it is not easy to represent their runtimeconfiguration in logic;Indeedy represents a relation that is not one-to-one(the structure can be invisible).

In parenthesis languages (like VPL) the structure is visible;the analogous ofy in VPL matches parentheses (one-to-one).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 15 / 17

Page 66: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Logic-Automata equivalence

The construction from logic to automata is quite standard

From automata to logic, it is not:

Finite-state and VP automata are real-time machines;OP automata are not, so it is not easy to represent their runtimeconfiguration in logic;Indeedy represents a relation that is not one-to-one(the structure can be invisible).

In parenthesis languages (like VPL) the structure is visible;the analogous ofy in VPL matches parentheses (one-to-one).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 15 / 17

Page 67: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Applications

Parallel and incremental parsing

OP languages are locally parsable: i.e. we can parse substrings withoutmodifying the outcome when considering larger strings (PAPAGENO)

[Barenghi, Crespi Reghizzi, Mandrioli, Pradella 2012; 2013]

Model checking

Closure properties enable infinite-state model checking.

OP languages can model some characteristics exhibited by real-worldsystems, as transactions, interrupts and hierarchical management(e.g. in operating systems, distributed databases, privilege-basedaccesses, versioning systems).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 16 / 17

Page 68: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Applications

Parallel and incremental parsing

OP languages are locally parsable: i.e. we can parse substrings withoutmodifying the outcome when considering larger strings (PAPAGENO)

[Barenghi, Crespi Reghizzi, Mandrioli, Pradella 2012; 2013]

Model checking

Closure properties enable infinite-state model checking.

OP languages can model some characteristics exhibited by real-worldsystems, as transactions, interrupts and hierarchical management(e.g. in operating systems, distributed databases, privilege-basedaccesses, versioning systems).

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 16 / 17

Page 69: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Conclusions

OP automata and logic

We defined OP automata and a MSO logic that perfectly matches thegenerative power of OP grammars

Operator-precedence languages

OP languages have almost the full generality of deterministic context-freebut enjoy all the nice properties of regular and VP languages.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 17 / 17

Page 70: Logic Characterization of Invisibly Structured Languages ... · suitable to model structured mark-up languages such as XML; properties enable model checking. Floyd’s OP languages

Conclusions

OP automata and logic

We defined OP automata and a MSO logic that perfectly matches thegenerative power of OP grammars

Operator-precedence languages

OP languages have almost the full generality of deterministic context-freebut enjoy all the nice properties of regular and VP languages.

Matteo Pradella (Politecnico di Milano) Logic for operator-precedence languages SOFSEM 2013 17 / 17