7 \frametitle{\textsc{SPL
}}
8 \framesubtitle{Acronym for:
\textsc{SPL
}: Parser and Lexer
}
9 \begin{block
}{Features
}
11 \item Implementation language:
12 Clean (
{\tiny\url{http://clean.cs.ru.nl
}})
16 \item Higher order functions
18 \item Using parser combinator library
\textsc{Yard
}
21 \item Positional data available for easy locating of errors.
23 \item Standardized parser errors. This means you can set it as
24 \texttt{buildprg
} in
\texttt{vim
} and you can then use the
30 \begin{frame
}[fragile
]
31 \frametitle{\textsc{YARD
}}
32 \framesubtitle{A minimal home grown monadic parser combinator library
}
34 \item Inspired by
\textsc{parsec
}: $
1pc=
3.375\cdot10^
{16}yd$~
\footnote{
35 A yard is exactly $
36$ inch and an inch is exactly the length
39 :: Error = PositionalError Int Int String | Error String
40 :: Parser a b = Parser (
[a
] -> (Either Error b,
[a
]))
43 \item Matches longest left-most parser
45 \item Stops immediately on error
\pause\\
50 \begin{frame
}[fragile
]
51 \frametitle{\textsc{YARD
} Combinators
}
53 instance Functor (Parser a)
54 instance Applicative (Parser a)
55 instance Monad (Parser a)
56 instance Alternative (Parser a)
58 runParser :: (Parser a b)
[a
] -> (Either Error b,
[a
])
59 (<?>) :: (Parser a b) Error -> Parser a b
63 satisfy :: (a -> Bool) -> Parser a a
64 check :: (a -> Bool) -> Parser a a
65 (until) infix
2 :: (Parser a b) (Parser a c) -> Parser a
[b
]
66 item :: a -> Parser a a | Eq a
67 list ::
[a
] -> Parser a
[a
] | Eq a
72 \section{Design choices
}
74 \frametitle{Adapting the grammar
}
76 \item Remove left recursion
77 \item Fixing associativity
78 \item Added small features such as escape characters
\texttt{
79 \textbackslash n
\textbackslash b
}
81 \item Show grammar now
\ldots
86 \frametitle{Two-phase design
}
87 \framesubtitle{Lexing
}
88 Also done with
\textsc{YARD
} because
90 \item Multiline comments
96 \begin{frame
}[fragile
]
97 \frametitle{Two-phase design
}
98 \framesubtitle{Parsing
}
99 Added some handy primitives
101 parseSColon :: (Parser Token a) -> Parser Token a
102 parseBlock :: Parser Token
[Stmt
]
103 parseOpR :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr
104 parseOpL :: (Parser Token Op2) (Parser Token Expr) -> Parser Token Expr
105 parseBBraces :: (Parser Token a) -> Parser Token a
106 parseBCBraces :: (Parser Token a) -> Parser Token a
107 parseBSqBraces :: (Parser Token a) -> Parser Token a
108 trans :: TokenValue (TokenValue -> a) -> Parser Token (Pos, a)
109 trans2 :: TokenValue (TokenValue -> a) -> Parser Token a
110 trans1 :: TokenValue a -> Parser Token a
111 peekPos :: Parser Token Pos
118 %- Anything that is specific to your parser
120 % - yard (parser combinators) Pim
121 % - Implementation language Pim
122 % - Elaborate diffulties and eases (Tussendoor)
124 %- Did you split it into two phases lexing and parsing, or just one phase? Pim
125 % - Why parser combinator for lexer
126 %- Did you change the grammar, and if so how? Mart
127 % - Standard tricks, remove left assoc, get operator assoc correct.
128 % - How did you solve the problems of precedence and associativity?
129 % - Stops, this is design, parsing should be correct!!!1!
130 %- For a couple of example programs, when you do a sequence of Mart
135 % -- Dit gaan we met een shell scriptje doen
136 %- Code metrics, loc, etc, met stomme xkcd Mart
137 % How many lines of code do you have, how many hours did you work on it?
138 % “Measuring programming progress by lines of code is like measuring
139 % aircraft building progress by weight.”
142 % Hoeveel uur, ook geen idee. Ook een stomme quote
143 %- Did you try your parser on weird inputs, like 100 megabyte of nested Mart
144 %parenthesis? 1 gigabyte?
145 % - Yes, we did, didn't work out. Uses big heap and stack
146 %- Problems and learned things
147 %- Demonstrate your parser and pretty-printer on two or three programs that you
148 % find interesting Mart (teminaldingen kun jij goed ;))