2 On adding indents to an LALR(1) parser.
5 1/ end-of-line should sometimes be a semantic end-of-statement.
8 2/ line continuation by indent is easy to read:
10 this a semantic unit which has
11 been broken on to multiple lines but clearly
16 We could suggest that whenever something is indented it doesn't end
17 the statement, but that doesn't allow for nexting
25 Thing1 is indented but should be terminated. Only locally though, the
26 'if' shouldn't be terminated.
34 pattern of indents is identical here, but now several newlines should
35 be ignored. why is this so? Mostly because lists are declared as
36 being terminated by newlines.
41 First we need help from the lexer/scanner. It must report newlines,
42 indents, and undents (or outdents or dedents or whatever).
43 If a line in more indented than the previous line, we get an 'indent'.
44 If a line is less indented, then we get one or more undents.
45 Possibly we can get undents and indents all at once.
53 Line 2 has an indent, line3 another indent.
54 line 4 get an undent so it lines up with line 2.
55 line 5 needs an undent, but that would imply it lines up with line 1
56 which it doesn't. So it needs and undent and an indent.
58 We get the lexer to produce these and the newlines, but it does
59 something clever with newlines. An 'indent' is never accompanied by
60 a newline. Instead the newline is delayed until after the matching
62 So the above would be scanned as
64 line1 indent line2 indent line3 newline undent newline line4 newline
65 undent newline indent line5 undent newline
67 If we then choose to ignore a particular indent and all newlines,
68 indents and undents until the matching undent, then we will still see
69 a newline at the end and it indented section will look like line
72 How do we choose what to ignore?