Python:
from calendar import weekday, SUNDAY
[year for year in range(2008, 2122)
if weekday(year, 12, 25) == SUNDAY]
Lua:
require("date")
for year=2008,2121 do
if date(year, 12, 25):getweekday() == 1 then
print(year)
end
end
Javascript:
for (var year = 2008; year <= 2121; year++) {
var xmas = new Date(year, 11, 25)
if ( xmas.getDay() === 0 )
console.log(year)
}
example.ml
¹ let x = 5;
² let y = 6
³ let z = 7
ocamlc example.ml
File "example.ml", line 3, characters 0-3:
3 | let z = 7
^^^
Error: Syntax error
A frustrating experience for developers!
Terminals:
Nonterminals:
How could we recognize an expression like:
Nonterminals:
Hand-writting parsers quickly appeared to be problematic: this process was tedious and error-prone.
This motivated a long line of research on parsing algorithms.
In this thesis, I worked on the family of LR parsers:
Yet, mainstream compilers tend to abandon generated parsers:
Why?
We can recognize any sentence by repeating two actions:
Let us write
Question: How do we know which actions are applicable?
Idea: Keep track of the grammar rules have been partially recognized.
An item mark a position in a rule with a
For instance,
When starting, we want to recognize an expression.
This is the initial state.
A state is a set of items, representing the candidates applicable to a situation.
Let's repeat the parsing process while tracking states:
Two kinds of actions are sufficient to recognize every sentence:
An item, written
A state tracks active items and gives the applicable actions.
Let us look at examples of incomplete input.
We would like to report: "Expecting a number".
We get stuck with a stack and a state.
We would like to report: "Unclosed parenthesis".
The input is invalid if actions do not permit reaching the goal.
The position of failure is well-defined (after the last shift).
The concept of "failing configuration" is slippery because of reductions.
Could we also specify the handling of errors?
How to specify the association between a failure and a message?
How to realize this specification efficiently?
How to help author this specification?
We focus on the technical aspect and not the human aspect:
If error looks like "1+"
report "Expecting a number"
If error looks like "(1"
report "A parenthesis has not been closed"
Used in earlier versions of Go.
In case of error, reduce T and E (if possible)
If error looks like "1+"
report "Expecting a number"
If error looks like "(1"
report "A parenthesis has not been closed"
Used in Compcert C, Catala, ...