ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Parsing F# with PetitParser
F# indentation sensitive
lightweight syntax
?
?
Milan Kubicek ?
SCG Seminar ?
06.01.2015
some F# code..
2
3
..some nicer F# code
Output:?
1: 1
2: 1
3: 2
4: 3
5: 5
6: 8
7: 13
8: 21
9: 34
10: 55
4
indentation?
as secondary notation
indentation?
as formal notation
indentation?
in programming
secondary notation ?
/ syntactic sugar
define structure
F#
Python
Haskell
¡°curly bracket programming languages¡±
5
¡°indentation sensitive?
programming languages¡±
6
off-side rule
off-side on-side
off-side line
valid pass!
foul pass!
7
off-side rule
8
off-side rule
off-side on-side
off-side line
9
off-side rule
10
off-side rule exceptions
off-side on-side
off-side line
11
off-side rule exceptions
¡°then-&else-body on-side aligned¡±
¡°then-body aligned¡±
¡°else-body aligned¡±
12
challanges
F# language definition
(Petit)Parsing knowledge
mini F# PetitParser grammar
(using PetitIndent)
13
F# lightweight syntax
indentation as primary notation:
..code position changes semantics!
off-side
on-side
off-side line
aligned
14
questions?
15
¨C http://en.wikipedia.org/wiki/Secondary_notation 05.01.2015
¡°¡­An example of secondary notation is in
computer programming, where code is often
displayed with positioning, indentation, color
and symmetry. This does not affect the
behaviour of the program, but it makes it easier
to read and understand the code¡­¡±
16
secondary notation
¨CPeter J. Landin, ¡°The Next 700 Programming Languages¡±
¡°Any non-whitespace token to the left of the first
such token on the previous line is taken to be
the start of a new declaration.¡±
Off-side rule
17

More Related Content

2015.01.06 f sharp_intro_milan_kubicek