diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-03 17:29:25 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-03-03 17:29:25 -0300 |
| commit | 61f97a8ace5b0df8de8da4e7473643a35956c2a7 (patch) | |
| tree | 64a89e9e5526cd152e78e452aa98eaa97e1b6da5 | |
| parent | d1ea38580ae35a3a34e7122c41682af7f9901030 (diff) | |
| download | lua-61f97a8ace5b0df8de8da4e7473643a35956c2a7.tar.gz lua-61f97a8ace5b0df8de8da4e7473643a35956c2a7.tar.bz2 lua-61f97a8ace5b0df8de8da4e7473643a35956c2a7.zip | |
maybe a concat right associative allows some optimizations...
| -rw-r--r-- | lparser.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.62 2000/03/03 14:58:26 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.63 2000/03/03 18:53:17 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -717,14 +717,14 @@ static int get_priority (int op, int *rp) { | |||
| 717 | case '>': case '<': case LE: case GE: | 717 | case '>': case '<': case LE: case GE: |
| 718 | *rp = 2; return 2; | 718 | *rp = 2; return 2; |
| 719 | case CONC: | 719 | case CONC: |
| 720 | *rp = 3; return 3; | 720 | *rp = 4; return 4; /* left associative (?) */ |
| 721 | case '+': case '-': | 721 | case '+': case '-': |
| 722 | *rp = 4; return 4; | ||
| 723 | case '*': case '/': | ||
| 724 | *rp = 5; return 5; | 722 | *rp = 5; return 5; |
| 725 | /* priority 6 is for unary operators */ | 723 | case '*': case '/': |
| 724 | *rp = 6; return 6; | ||
| 725 | #define UNARY_PRIORITY 7 | ||
| 726 | case '^': | 726 | case '^': |
| 727 | *rp = 7; return 8; /* right associative */ | 727 | *rp = 8; return 9; /* right associative */ |
| 728 | default: | 728 | default: |
| 729 | *rp = -1; return -1; | 729 | *rp = -1; return -1; |
| 730 | } | 730 | } |
| @@ -740,7 +740,7 @@ static void operator_expr (LexState *ls, expdesc *v, int limit) { | |||
| 740 | if (ls->token == '-' || ls->token == NOT) { | 740 | if (ls->token == '-' || ls->token == NOT) { |
| 741 | int op = ls->token; /* operator */ | 741 | int op = ls->token; /* operator */ |
| 742 | next(ls); | 742 | next(ls); |
| 743 | operator_expr(ls, v, 6); /* 6 == priority of NOT and unary `-' */ | 743 | operator_expr(ls, v, UNARY_PRIORITY); |
| 744 | luaK_prefix(ls, op, v); | 744 | luaK_prefix(ls, op, v); |
| 745 | } | 745 | } |
| 746 | else simpleexp(ls, v); | 746 | else simpleexp(ls, v); |
