Browse Source

Allow the array typedef constructs to be used not only when declaring a variable.

release/v0.1
Rafal Kupiec 1 year ago
parent
commit
dbd39be5ed
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 11 additions and 2 deletions
  1. +11
    -2
      engine/parser.c

+ 11
- 2
engine/parser.c View File

@ -832,8 +832,14 @@ static sxi32 ExprMakeTree(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nTo
if(iLeft < 0 || apNode[iLeft] == 0 || (apNode[iLeft]->pOp == 0 && (apNode[iLeft]->xCode != PH7_CompileVariable &&
apNode[iLeft]->xCode != PH7_CompileSimpleString && apNode[iLeft]->xCode != PH7_CompileString)) ||
(apNode[iLeft]->pOp && apNode[iLeft]->pOp->iPrec != 2 /* postfix */)) {
/* Syntax error */
PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Invalid array name");
sxu32 nId = 0;
if(apNode[iLeft]->xCode == PH7_CompileLiteral && apNode[iLeft]->pStart->nType & PH7_TK_KEYWORD) {
nId = SX_PTR_TO_INT(apNode[iLeft]->pStart->pUserData);
}
if(!nId || (nId & PH7_KEYWORD_TYPEDEF) == 0) {
/* Syntax error */
PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Invalid array name");
}
}
/* Collect index tokens */
while(iArrTok < nToken) {
@ -852,6 +858,9 @@ static sxi32 ExprMakeTree(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32 nTo
++iArrTok;
}
if(iArrTok > iCur + 1) {
if(apNode[iLeft]->xCode == PH7_CompileLiteral) {
PH7_GenCompileError(pGen, E_ERROR, pNode->pStart->nLine, "Array index cannot be specified in a variable declaration");
}
/* Recurse and process this expression */
rc = ExprMakeTree(&(*pGen), &apNode[iCur + 1], iArrTok - iCur - 1);
if(rc != SXRET_OK) {

Loading…
Cancel
Save