[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua grammar question
- From: David Jones <drj@...>
- Date: Mon, 28 Feb 2005 14:00:51 +0000
On Feb 26, 2005, at 13:01, Asger Ottar Alstrup wrote:
The Lua grammar contains these three lines to describe the syntax for
functioncall = p args | p ':' Name args
p = var | functioncall | '(' exp ')'
var = Name | p '[' exp ']' | p '.' Name
That is left recursive in strange ways, and thus Greek to me. Based on
my understanding of the language, I've tried to rewrite it to
something which is easier to understand for me. Does this match the
( Name | '(' exp ')' )
( args | '.' Name | ':' Name | '[' exp ']' )*
The way to get to grips with grammar is just to play around. In this
case you'd do well working from the right-hand end.
It's clear that all functioncalls must end in an args (from the first
line of the grammar you quoted). That leaves the bit before the
arguments. Let's call that the specifier. What can that look like?
Well, it can either be a p or p ':' Name.
Perhaps at this point you'd better work through some cases. But note
that p can be a functioncall, so you have things like:
f "a" "b" or f("a")("b")
p can also be a sort of generalised variable, like a simple name like
or a more complex variable like
And for all of those you can just sneak a ':' Name in just before the
(final) args, like this
Well, I don't know if that helps, but I never knew you could go f"a""b"
before reading that grammar extract. :)