summaryrefslogtreecommitdiff
path: root/src/map/script.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2013-09-14 08:13:28 +0200
committerHaru <haru@dotalux.com>2013-11-28 02:34:55 +0100
commit9a802b9147221ec1f31109242be2919f53401fd3 (patch)
tree22c42e57cc03151e0e1aa73f0035c614b73b468e /src/map/script.c
parentac6ae8c932efbca30ef1650fa5d7bd94ead336f5 (diff)
downloadhercules-9a802b9147221ec1f31109242be2919f53401fd3.tar.gz
hercules-9a802b9147221ec1f31109242be2919f53401fd3.tar.bz2
hercules-9a802b9147221ec1f31109242be2919f53401fd3.tar.xz
hercules-9a802b9147221ec1f31109242be2919f53401fd3.zip
Corrected operator precedence table.
- [ This commit is part of a larger script engine related update ] - Operator precedence rules now closely follow those of languages such as C and derivates/related (C++, Java, PHP, etc.) - Please note that if you had custom scripts with non parenthesized expressions containing bitwise |, &, ^ operators, they may behave incorrectly now (or perhaps they were already behaving incorrectly, since the previous behavior was undocumented). - Added an up to date operator precedence/associativity table in the script documentation. - Added an operator/keyword self-test script in the npc/custom folder, in case if may be of some use for future regression-testing.
Diffstat (limited to 'src/map/script.c')
-rw-r--r--src/map/script.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 2c4178d9b..73aaafab2 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -1158,32 +1158,32 @@ const char* script_parse_subexpr(const char* p,int limit) {
if( (op=C_ADD_PRE,p[0]=='+'&&p[1]=='+') || (op=C_SUB_PRE,p[0]=='-'&&p[1]=='-') ) { // Pre ++ -- operators
p=script->parse_variable(p);
} else if( (op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~') ) { // Unary - ! ~ operators
- p=script->parse_subexpr(p+1,10);
+ p=script->parse_subexpr(p+1,11);
script->addc(op);
} else {
p=script->parse_simpleexpr(p);
}
p=script->skip_space(p);
while((
- (op=C_OP3, opl=0,len=1,*p=='?') // ?:
- || (op=C_ADD, opl=8,len=1,*p=='+') // +
- || (op=C_SUB, opl=8,len=1,*p=='-') // -
- || (op=C_MUL, opl=9,len=1,*p=='*') // *
- || (op=C_DIV, opl=9,len=1,*p=='/') // /
- || (op=C_MOD, opl=9,len=1,*p=='%') // %
- || (op=C_LAND, opl=2,len=2,*p=='&' && p[1]=='&') // &&
- || (op=C_AND, opl=6,len=1,*p=='&') // &
- || (op=C_LOR, opl=1,len=2,*p=='|' && p[1]=='|') // ||
- || (op=C_OR, opl=5,len=1,*p=='|') // |
- || (op=C_XOR, opl=4,len=1,*p=='^') // ^
- || (op=C_EQ, opl=3,len=2,*p=='=' && p[1]=='=') // ==
- || (op=C_NE, opl=3,len=2,*p=='!' && p[1]=='=') // !=
- || (op=C_R_SHIFT,opl=7,len=2,*p=='>' && p[1]=='>') // >>
- || (op=C_GE, opl=3,len=2,*p=='>' && p[1]=='=') // >=
- || (op=C_GT, opl=3,len=1,*p=='>') // >
- || (op=C_L_SHIFT,opl=7,len=2,*p=='<' && p[1]=='<') // <<
- || (op=C_LE, opl=3,len=2,*p=='<' && p[1]=='=') // <=
- || (op=C_LT, opl=3,len=1,*p=='<') // <
+ (op=C_OP3, opl=0, len=1,*p=='?') // ?:
+ || (op=C_ADD, opl=9, len=1,*p=='+') // +
+ || (op=C_SUB, opl=9, len=1,*p=='-') // -
+ || (op=C_MUL, opl=10,len=1,*p=='*') // *
+ || (op=C_DIV, opl=10,len=1,*p=='/') // /
+ || (op=C_MOD, opl=10,len=1,*p=='%') // %
+ || (op=C_LAND, opl=2, len=2,*p=='&' && p[1]=='&') // &&
+ || (op=C_AND, opl=5, len=1,*p=='&') // &
+ || (op=C_LOR, opl=1, len=2,*p=='|' && p[1]=='|') // ||
+ || (op=C_OR, opl=3, len=1,*p=='|') // |
+ || (op=C_XOR, opl=4, len=1,*p=='^') // ^
+ || (op=C_EQ, opl=6, len=2,*p=='=' && p[1]=='=') // ==
+ || (op=C_NE, opl=6, len=2,*p=='!' && p[1]=='=') // !=
+ || (op=C_R_SHIFT,opl=8, len=2,*p=='>' && p[1]=='>') // >>
+ || (op=C_GE, opl=7, len=2,*p=='>' && p[1]=='=') // >=
+ || (op=C_GT, opl=7, len=1,*p=='>') // >
+ || (op=C_L_SHIFT,opl=8, len=2,*p=='<' && p[1]=='<') // <<
+ || (op=C_LE, opl=7, len=2,*p=='<' && p[1]=='=') // <=
+ || (op=C_LT, opl=7, len=1,*p=='<') // <
) && opl>limit) {
p+=len;
if(op == C_OP3) {