Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unary plus #130

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions neverwinter/nwscript/native/scriptcompparsetree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ int32_t CScriptCompiler::GenerateParseTree()
// (3) ! post-expression
// (4) ++ post-expression
// (5) -- post_expression
// (6) post-expression
// (6) + post_expression
// (7) post-expression
////////////////////////////////////

case CSCRIPTCOMPILER_GRAMMAR_UNARY_EXPRESSION:
Expand Down Expand Up @@ -1035,18 +1036,24 @@ int32_t CScriptCompiler::GenerateParseTree()
PushSRStack(CSCRIPTCOMPILER_GRAMMAR_POST_EXPRESSION,0,0,NULL);
return 0;
}
else
else if (m_nTokenStatus == CSCRIPTCOMPILER_TOKEN_PLUS)
{
PushSRStack(CSCRIPTCOMPILER_GRAMMAR_UNARY_EXPRESSION,6,1,NULL);
PushSRStack(CSCRIPTCOMPILER_GRAMMAR_POST_EXPRESSION,0,0,NULL);
return 0;
}
else
{
PushSRStack(CSCRIPTCOMPILER_GRAMMAR_UNARY_EXPRESSION,7,1,NULL);
PushSRStack(CSCRIPTCOMPILER_GRAMMAR_POST_EXPRESSION,0,0,NULL);
}
}
if ((nTopStackRule >= 1 && nTopStackRule <= 5) && nTopStackTerm == 1)
{
pTopStackCurrentNode->pLeft = pTopStackReturnNode;
ModifySRStackReturnTree(pTopStackCurrentNode);
}
if (nTopStackRule == 6 && nTopStackTerm == 1)
if (nTopStackRule >= 6 && nTopStackTerm == 1)
{
ModifySRStackReturnTree(pTopStackReturnNode);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/scriptcomp/corpus/constants.nss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const int CONSTINT_MODULUS = A % B;
const int CONSTINT_BOOLEAN_NOT = !A;
const int CONSTINT_ONES_COMPLEMENT = ~A;
const int CONSTINT_NEGATION = -A;
const int CONSTINT_AFFIRMATION = +A;

const int CONSTINT_COMPLEX_EXPRESSION = A * (B/A) + !A + !B;

Expand Down Expand Up @@ -129,6 +130,7 @@ void main()
Assert(CONSTINT_BOOLEAN_NOT == 0);
Assert(CONSTINT_ONES_COMPLEMENT == -11);
Assert(CONSTINT_NEGATION == -10);
Assert(CONSTINT_AFFIRMATION == 10);

Assert(CONSTINT_COMPLEX_EXPRESSION == 20);

Expand Down
Loading