lua-users home
lua-l archive

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

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 '='.


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);


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:

  THEN = 0;
  THEN = 1;

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


...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.


- --
┌── ─── ───────────────────
│ "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_
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla -