i was making a lexical analyzer but i am stuck here can anybody please help with this where am i going wrong :S

Console.WriteLine("ENTER STRING:");
            // string ch = string.Intern(System.Console.ReadLine());
            string str = Console.ReadLine();
            Console.ReadLine();


            string[] kw = new string[2]{ "for","while"};
            string[] punc = new string[2]{ ";","."};
            //if(kw.Contains(str))

            switch (str)
            {

                case kw:
                    {



                     Console.WriteLine("\n\nkeyword");
                    return str;
                        //Console.WriteLine(kw.Contains(str));
                        Console.ReadLine();

                    }

                //else if(punc.Contains(str))
                case punc:
                    {

                        Console.WriteLine("\n\npunctuation");
                        //Console.WriteLine(punc.Contains(str));
                        Console.ReadLine();



                    }

                default:

                        Console.WriteLine("\n\ninvalid string");



            }

        }

    }
}

You can't do this. You will need to check if the array contains your string.

It might be better to put your syntax into a structure so that you can mark particular items as puntuation or keywords.

public enum TokenType
{
    Keyword,
    Punctuation
}

public class Token
{
    public String Value;
    public TokenType Type;
}

public TokenList : List<Token>
{
    public Token GetTokenByValue(String value)
    {
        return this.Where(item => item.Value.Equals(value));
    }
}

Or something like that...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.