[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Comments on the 4.1-alpha manual
- From: ramsdell@... (John D. Ramsdell)
- Date: 14 Aug 2001 08:48:11 -0400
ramsdell@linus.mitre.org (John D. Ramsdell) writes:
> Well, typos and things did creep in.
There was yet another error in the table grammar I suggested. The
previous version prohibited list expressions that started with a
semicolon such as: {; "a", "b"}.
I rewrote the grammar in a fashion that demonstrates it is LALR(1).
If this version is correct, it seems to me to be very easy to
understand. Also, if this version is correct, the language is
probably LL(1) too, contrary to an earlier assertion I made.
John
------------------------------------------------------------------
block --> { stmt [ ';' ] } [ finish [ ';' ] ]
stmt --> var { ',' var } '=' exprs
| call
| DO block END
| WHILE expr DO block END
| REPEAT block UNTIL expr
| IF expr THEN block
{ ELSEIF expr THEN block }
[ ELSE block ] END
| FOR name '=' expr ',' expr [ ',' expr ] DO block END
| FOR name ',' name IN expr DO block END
| FUNCTION func_name '(' [ params ] ')' block END
| LOCAL name { ',' name } [ '=' exprs ]
finish --> RETURN [ exprs ] | BREAK [ name ]
func_name --> name { '.' key } [ ':' key ]
key --> name | AND | BREAK | DO | END | ELSE | ELSEIF
| FOR | FUNCTION | GLOBAL | IF | IN | LOCAL | NIL
| NOT | OR | RETURN | REPEAT | THEN | UNTIL | WHILE
params --> '...' | name { ',' name } [ ',' '...' ]
exprs --> expr { ',' expr }
expr --> primary | var | call | expr binop expr | unop expr
primary --> NIL | number | literal | '%' name | table_cons
| FUNCTION '(' [ params ] ')' block END | ( expr )
var --> name
| primary '[' expr ']'
| primary '.' key
| var '[' expr ']'
| var '.' key
| call '[' expr ']'
| call '.' key
call --> primary [ ':' key ] args
| var [ ':' key ] args
| call [ ':' key ] args
table_cons --> '{' [ fields ] '}
fields --> expr_fields [ ';' [ mapping_fields ] ]
| mapping_fields [ ';' [ expr_fields ] ]
| ';' [ final_fields ]
final_fields --> expr_fields | mapping_fields
expr_fields --> exprs [ ',' ]
mapping_fields --> mapping_field { ',' mapping_field } [ ',' ]
mapping_field --> '[' expr ']' '=' expr | key '=' expr
binop --> ...
unop --> '-' | NOT
------------------------------------------------------------------
Note that left parenthesis, left brace, and literals are
preferentially treated as arguments rather than as starting a new
expression. This rule comes into effect when interpreting a call as a
statement, or a primary, variable, or call as an expression. Without
this rule, the grammar is ambiguous.
------------------------------------------------------------------