Intermezzo: Symbols (1) Intermezzo: Symbols (2) A complex symbol - - PowerPoint PPT Presentation

intermezzo symbols 1 intermezzo symbols 2
SMART_READER_LITE
LIVE PREVIEW

Intermezzo: Symbols (1) Intermezzo: Symbols (2) A complex symbol - - PowerPoint PPT Presentation

Intermezzo: Symbols (1) Intermezzo: Symbols (2) A complex symbol is: A complex symbol is: An elementary symbol is: Repetition: Literal: abc l b Li S* zero or more times S S ; S+ one or more times S mes: INT Sort


slide-1
SLIDE 1

Intermezzo:

An elementary symbol is:

Li l “ b ”

– Literal: “abc” – Sort (non-terminal) nam – Character classes: [a-z]:

  • ~: complement of charac

p

  • /: difference of two char

/\: intersection of two ch

  • /\: intersection of two ch
  • \/: union of two charact

Introduction

Symbols (1)

mes: INT : one of a, b, ..., z

cter class. racter classes. haracter classes haracter classes. er classes.

to ASF+SDF 1

Intermezzo:

A complex symbol is: A complex symbol is:

– Repetition:

  • S* zero or more times S
  • {S1 S2}* zero or more
  • {S1 S2}

zero or more

  • {S1 S2}+ one or more t

O ti l S?

– Optional: S? zero or one – Alternative: S | T an S o

– Tuple: <S,T> shorthand f

– Parameterized sorts: S[[

Introduction

Symbols (2)

S; S+ one or more times S

times S1 separated by S2 times S1 separated by S2 times S1 separated by S2

f S e occurrences of S

  • r a T

for “<” S “,” T “>”

[ P1, P2 ]]

to ASF+SDF 2

Intermezzo: produ

  • General form of a produ

1 2

– S1 S2 ... Sn -> S0 Attr

  • Lexical syntax and context-

– Between the symbols in

symbols may occur in th

– A context-free productio

  • S1 LAYOUT? S2 LAY
  • S1 LAYOUT? S2 LAY

Introduction

uctions (functions)

uction (function):

b ributes

  • free syntax are similar, but

a production optional layout he input text.

  • n is equivalent with:

YOUT? LAYOUT? Sn -> S0 YOUT? ... LAYOUT? Sn S0

to ASF+SDF 3

Example: floatin

sorts UnsignedInt SignedInt Unsig lexical syntax [0] | ([1-9][0-9]*) [\+\-]? UnsignedInt [\ \ ]? UnsignedInt UnsignedInt "." [0-9]+ ([eE] Sig Unsi n dInt [ E] Si n dInt UnsignedInt [eE] SignedInt UnsignedInt | UnsignedReal 0 1 14 0.1 3e4 3.014e-7

Introduction

ng point numbers

gnedReal Number

  • > UnsignedInt
  • > SignedInt

SignedInt gnedInt)? -> UnsignedReal > Unsi n dR l

  • > UnsignedReal
  • > Number

00 01 04.1 3e04 3.14e-07

to ASF+SDF 4

slide-2
SLIDE 2

Intermezzo: list

A “ ”

A+ a a a a

Assume: “a”

{A “;”}+

a ; a

a a (A “;”)+ ( “ ) a ; a ;

a ; a;

(A “;”?)+ a a a a a a

Introduction

ts, lists, lists, ...

A

  • > A

a ; a; a a ; a; a;

;

a ; a; a;

a ; a; a a ; a; a a ; a; a ; a

to ASF+SDF 5

Intermezzo: disa Intermezzo: disa

Wh l di bi ti

  • Why manual disambiguation

– Fully declarative definition of syntax

I li i di bi i b

– Implicit disambiguation can be wron – More programming languages can b

Modularity

– Modularity – Fewer non-terminals/sorts – Separation of concerns: form of rule

p

  • Costs?

– Intellectual effort

Intellectual effort

– False safety, grammar may still be am Introduction

ambiguation (1) ambiguation (1)

i SDF? in SDF?

x ng e parsed es is independent of disambiguation p g mbiguous

to ASF+SDF

Intermezzo: disa Intermezzo: disa

A i ti it f bi

  • Associativity of binary op
  • Priorities between binary

y

– Transitivity of priorities

Prefix expressions and bin

– Prefix expressions and bin – Postfix expression with bi

O l d d ’ i

– Overloaded comma’s in ex

Introduction

ambiguation (2) ambiguation (2)

t perators

  • perators

p

nary expressions nary expressions inary operator (slide 3+4) i l ( lid 5 6) xpression languages (slide 5+6)

to ASF+SDF

Intermezzo: disa Intermezzo: disa

module Expressions module Expressions exports sorts E lexical syntax [\ \t\n] -> LAYOUT context-free start-symbols E context-free syntax "e" -> E E "[" E "]" -> E E "+" E -> E {left} I t t + [ + ] Input sentence: e + e [ e + e ]

Introduction

ambiguation (3) ambiguation (3)

to ASF+SDF

slide-3
SLIDE 3

Intermezzo: disa Intermezzo: disa

module Expressions module Expressions exports sorts E lexical syntax [\ \t\n] -> LAYOUT context-free start-symbols E context-free syntax "e" -> E context-free priorities E "[" E "]" -> E <0> > E "+" E > E {l ft} E "+" E -> E {left}

Introduction

ambiguation (4) ambiguation (4)

to ASF+SDF

Intermezzo: disa Intermezzo: disa

module Expressions module Expressions exports sorts E lexical syntax [\ \t\n] -> LAYOUT context-free start-symbols E context-free syntax "e" -> E e > E "f" "(" {E ","}+ ")" -> E E "," E -> E {left}

Input sentence: f(e,e)

Introduction

ambiguation (5) ambiguation (5)

to ASF+SDF

Intermezzo: disa Intermezzo: disa

module Expressions module Expressions exports sorts E lexical syntax [\ \t\n] -> LAYOUT context-free start-symbols E context free start symbols E context-free syntax "e" -> E "f" "(" {E ","}+ ")" -> E context-free priorities { non-assoc: E -> {E “,”}+ { non assoc: E > {E , }+ E "," E -> E {left} } Introduction

ambiguation (6) ambiguation (6)

to ASF+SDF

Intermezzo: disa Intermezzo: disa

L t t h

  • Longest match
  • Runaway whitespace and

y p

  • Syntactic overloading bet

keywords keywords

  • Useless cloning of identif
  • Dynamically reserved typ
  • Dangling else and related
  • Dangling else and related

Introduction

ambiguation (7) ambiguation (7)

d comments tween identifiers and fier classes pes d ambiguities d ambiguities

to ASF+SDF

slide-4
SLIDE 4

Intermezzo: disa Intermezzo: disa

R hit d

  • Runaway whitespace and commen

module Layout exports p sorts P S context-free start-symbols P lexical syntax [\ \t\n] -> LAYOUT context-free restrictions LAYOUT? -/- [\ \t\n] context-free syntax "[" S* "]" -> P "s" -> S Introduction

ambiguation (8) ambiguation (8)

t nts

to ASF+SDF