lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rici Lake wrote:
[...]
> Looked at from another perspective, the use of barewords as
> table keys is completely syntactically separate from their
> use as keywords. A table key must either follow '.' or ':'
> in postfix position, 'function' in a <function> statement,
> or it must be used as the first token in a table field and
> followed by '='.

<tangent>

By designing your grammar appropriately, it's quite possible to produce a
language with no reserved words. You just need to make sure you can determine
what type a token is from context. For example, addition of let and call
keywords would disambiguate assignments and function calls:

let x = 1;
call foo(x);

Or:

let let = 1;
call call(let);

In both cases, this is completely unambiguous. Note the use of ; at the end of
statements, to tell the parser that the next token is a keyword.

Some Algol variants in fact went one step further and required all keywords to
be quoted:

'IF' IF 'THEN'
  THEN = 0;
'ELSE'
  THEN = 1;

C is notoriously irritating to parse because the parse rules for a token can
change during compilation. This:

T(*B)[4];

...may be a function call (if T is an identifier), or a function prototype (if
T is a type). This is a good example of how *not* to design a grammar. In
another life I'm writing an Objective C preprocessor, and dealing with this
sort of thing is a total pain in the arse.

</tangent>

- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│ "Thou who might be our Father, who perhaps may be in Heaven, hallowed be
│ Thy Name, if Name Thou hast and any desire to see it hallowed..." ---
│ _Creatures of Light and Darkness_
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGH6Jqf9E0noFvlzgRAnyHAKCr6D/9sKbyAVxI4CE3R362InSYmgCfXlMr
TqN49pF1p/5UrHL2L0tEOpI=
=NzYI
-----END PGP SIGNATURE-----