lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Thu, Jul 5, 2018 at 09:03 Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

A syntax ambiguity is already there; these cases would make it worse:

  -- already ambiguous:
  a = b + c
  ('str'):fun()

  -- new ambiguity:
  a = b + c
  'str':fun()

  -- new ambiguity:
  a = b + c
  {}:fun()

-- Roberto


The language BCPL used a fairly simple strategy to detect statement ends:

Let E be the set of symbols that can end a statement, and S be the set of symbols that can start a statement. If the lexical analyzer sees a symbol in E followed by a newline, follow by a symbol in S it inserts a semicolon between them. 

For Lua E would include identifiers, literals and all the closing brackets, and S would include identifiers, literals and opening brackets.

It would be interesting to see whether this could be made to work well for Lua. In terms of LR parsing, the parser would resolve these shift-reduce ambiguities with a shift, except when a newline occurs.

The Go language uses a simplified version of this strategy: it only looks at the symbol before the newline.




--
-- Gė