case'&&':

switch (c)
{
case '&&' : symbol = AND; break; //case label value exceeds maximum value for type [enabled by default]
case '-' : symbol = MINUS; break;
case '(' : symbol = LPAR; break;
case ')' : symbol = RPAR; break;}


How I can replace this konditional?
Just use if/else if statements.

if (c == "&&")
symbol = AND; // enum I take it
else if (c == '-')
....

Switch statements only work on integral or char types, not strings. You will need a more modern language for that functionality like C# or Java.
Last edited on
Is 'c' a char?
IceThatJaw wrote:
You will need a more modern higher level language for that functionality like C# or Java.


I fixed that for you.
'&&' is a character literal that occupies usually four bytes (because it has type int) while type character has size of one byte. So variable c defined as char can not be equal to the character literal '&&'. And the compiler reports you about that.
Last edited on
closed account (zb0S216C)
Since a "char" (signed or unsigned) can hold only one character, you would have to check each character individually if you're using a "switch". Discarding the "switch" in favour of "if" isn't really ideal due to the compilers ability to effectively optimise the "switch" with a jump-table. "if" statements, however, are more difficult for the compiler to optimise.

Perhaps you could do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
char Current_Char_('&');
char Next_Char_('&');

switch(Current_Char_)
{
    case '&':
    {
        switch(Next_Char_)
        {
            case '&':
                Symbol = AND;
                break;
        }
    }
    break;

    case '-':
        // ...
}

Next_Char_ = Get_Next_Char( );

Wazzak
Last edited on
Topic archived. No new replies allowed.