elseif(index<CodeLine.size()-2 && (CodeLine[index+1].Token!="]" || (CodeLine[index+1].Type!=TokenType::Integer && CodeLine[index+2].Token!="]")))
i'm testing if the next token is ']' or is an integer and the next is ']', unless isn't valid...
what is wrong between the or and the and boolean combinations?
i fix it in a different way with several tries :(
1 - i test the right rules for ignore it;
2 - unless will be an error.
1 2 3 4 5 6 7 8 9
elseif(index<CodeLine.size() && (CodeLine[index+1].Token=="]" || (CodeLine[index+1].Type==TokenType::Integer && CodeLine[index+2].Token=="]" )))
{
//correct combination
}
else
{
ErrorList.push_back({"Var creation error!!!", "You must use ']' and or a size for close the array creation and the type!!!",intCodeLine, index});
break;
}
1. You are checking "!=" rather than "==". Is that what you want?
2. Is token a char or a string? If it's a char, you want to check against ']', not "]".
3. When you have a convoluted if condition like this, it helps to break it down into more lines. That will make it not only easier for you to see your logic, but also allows others to read and comment on your code. The following may be overkill, but it shows you how breaking up a condition can make it a little bit easier to understand.
i'm sorry but i need ask: my last code works fine.. but i still thinking: why the previous code don't works?
on last code, i have an empty 'if' for works. but i do it directly on previous code: elseif(index<CodeLine.size()-2 && (CodeLine[index+1].Token!="]" || (CodeLine[index+1].Type!=TokenType::Integer && CodeLine[index+2].Token!="]")))
you can see the difference between the 2 codes.. that's why is make me so confused
forget the 'size()'(is for avoid index problems).. my problem is these line: (CodeLine[index+1].Token!="]" || (CodeLine[index+1].Type!=TokenType::Integer && CodeLine[index+2].Token!="]")))
but seems not working... that's why i use these empty 'if': (CodeLine[index+1].Token=="]" || (CodeLine[index+1].Type==TokenType::Integer && CodeLine[index+2].Token=="]" ))
what i'm doing wrong on 1st 'if'?
A or B
// is neither equal nor opposite of
(not A) or (not B)
You should look at De Morgan's laws.
7 or 42 is true if the value is either of those two values.
!7 or !42 is true with all values, because at least one side of or is always true.
!(7 or 42) is true when the value is not 7 and is not 42. Anything, but 7 and 42.
keskiverto: i'm thinking and i think that i can use that empty 'if' and it's the best for do the correct code...
i'm sorry, but can you share the link?
i don't remember it :(
thank you so much for all to all
elseif(index<CodeLine.size() && (CodeLine[index+1].Token=="]" || (CodeLine[index+1].Type==TokenType::Integer && CodeLine[index+2].Token=="]" )))
{
//correct combination
}
else
{
ErrorList.push_back({"Var creation error!!!", "You must use ']' and or a size for close the array creation and the type!!!",intCodeLine, index});
break;
}
is indeed the correct logic you could just negate the entire statement to get rid of the empty if():
1 2 3 4 5 6
elseif(!(index<CodeLine.size() && (CodeLine[index+1].Token=="]" || (CodeLine[index+1].Type==TokenType::Integer && CodeLine[index+2].Token=="]" ))))
{
ErrorList.push_back({"Var creation error!!!", "You must use ']' and or a size for close the array creation and the type!!!",intCodeLine, index});
break;
}