lua-users home
lua-l archive

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


> Lua is not in LL(1).  Telling assignments from function calls requires
> unbounded look-ahead.  You need some LL(1) extension, or you cannot
> parse Lua.  (The ANTLR parser enables backtracking, but this is
> certainly not required.)

You can use the same method that Lua uses. The parser accepts what
it calls 'primaryexp' (which includes both variables and function calls)
without knowing whether that will be a function call or an assignment:

  primaryexp = prefixexp rest
  prefixexp = NAME | '(' exp ')'
  rest = empty
       | '.' NAME rest
       | '[' exp `]' rest
       | ':' NAME funcargs rest
       | funcargs rest

  assignment_or_call = primaryexp rest1
  rest1 = empty         -- function call
        | ',' ...       -- multiple assignment
        | '=' ...       -- single assignment

After reading an entire 'assignment_or_call', the parser can use
semantic actions to raise an error for things like "f() = 3".

-- Roberto