first implementation of bitwise operators '&' (band), '|' (bor),

and '~' (bxor)
This commit is contained in:
Roberto Ierusalimschy
2013-12-18 12:12:03 -02:00
parent a948054a19
commit c0edab0f6d
11 changed files with 122 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.135 2013/08/30 16:01:37 roberto Exp roberto $
** $Id: lparser.c,v 2.136 2013/12/16 19:06:52 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@@ -994,6 +994,9 @@ static BinOpr getbinopr (int op) {
case '^': return OPR_POW;
case '/': return OPR_DIV;
case TK_IDIV: return OPR_IDIV;
case '&': return OPR_BAND;
case '|': return OPR_BOR;
case '~': return OPR_BXOR;
case TK_CONCAT: return OPR_CONCAT;
case TK_NE: return OPR_NE;
case TK_EQ: return OPR_EQ;
@@ -1012,17 +1015,18 @@ static const struct {
lu_byte left; /* left priority for each binary operator */
lu_byte right; /* right priority */
} priority[] = { /* ORDER OPR */
{6, 6}, {6, 6}, /* '+' '-' */
{7, 7}, {7, 7}, /* '*' '%' */
{10, 9}, /* '^' (right associative) */
{7, 7}, {7, 7}, /* '/' '//' */
{5, 4}, /* '..' (right associative) */
{8, 8}, {8, 8}, /* '+' '-' */
{9, 9}, {9, 9}, /* '*' '%' */
{12, 11}, /* '^' (right associative) */
{9, 9}, {9, 9}, /* '/' '//' */
{6, 6}, {4, 4}, {5, 5}, /* '&' '|' '~' */
{7, 6}, /* '..' (right associative) */
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
{2, 2}, {1, 1} /* and, or */
};
#define UNARY_PRIORITY 8 /* priority for unary operators */
#define UNARY_PRIORITY 10 /* priority for unary operators */
/*