Build and play with the SLANG compiler. Experiment with the frontend (syntax/type checker) and be prepared to discuss what you have done in the supervision. It is OK if the changes you make do not work.
Write down a pipeline of steps involved in compilation paying special attention to what goes into each step and what goes out. You can be as vague or specific as you want, but be prepared to discuss compiler related concepts and how it fits to your pipeline.
How is LLVM approach to compiler construction is different than that is presented in this course?
Why does
past.mlin first Slang compiler havelocparameter for every constructor, while the corresponding constructors inast.mldon’t have them?According to lexical analysis algorithm described in the slides, what are the two rules that disambiguate multiple possible matches out of the same character stream?
Starting with regular expressions that match individual tokens, how do we generate a single lexing program?
What does it mean for a grammar to be ambiguous? How can this ambiguity be resolved?
How does a recursive descent parser work? What class of languages can it be used to describe? What are the problems with it?
2012/3/4 (a) (b)
Consider a language of regular expressions consisting of
- characters (e.g.,
amatching the stringa), - concatenation operation (e.g.,
abmatchingathenb), - alternative operator (e.g.,
a|bmatchingaorb), - the Kleene star (e.g.,
a*matching zero or moreas), - a restricted form of character classes with ranges (e.g.,
[a-c]to mean matchingaorborc) as well as lists (e.g.,[abc]to mean matchingaorborc), - and parantheses (e.g.,
a(b|c)meaning matchingafollowed by matchingborc).
For this language,
Design a grammar for this language taking operator precedence into account (concatenation binds tighter than alternative). Write it down using the EBNF notation;
Write a hand-coded lexer and a recursive descent parser for this grammar in OCaml. Clearly explain any transformations you made to your original grammar to accomplish this;
Write a computer generated lexer and parser using
ocamllexandmenhirOCaml packages. You might like to consult this tutorial to learn more about the tools.
- characters (e.g.,
Thanks to Zébulon Goriely for catching a typo.