Results 1 to 5 of 5

Thread: C#: Lexing Algorithm [Variable Declaration]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    C#: Lexing Algorithm [Variable Declaration]

    Hi guys,

    I will have a couple of these questions in the coming weeks as I am creating a new lexing DLL. Today I am looking at the structure of variable declarations in C#. So I have done all the written work and I seem to have come up with the following rules.

    1: public int myVar = 2;

    2: int MyVar = 2;

    3: Public myClass.myVar varName = 2;

    4: myClass.myVar VarName = 2;

    So the overall rule seems to be:

    (General Rules)
    1: Each declaration will always have at least 2 words before the assignment.
    2: Each declaration will have at most 3 words before the assignment.
    3: The assignment operator is always a "="
    4: The items after the = will be tested separately as they can be complex.

    (Special Rules)
    1: The first word will always be a whole word if there are 3 words before the =
    2: The second word can contain whole words and periods only if as above.
    3: The third word will follow variable conventions if as above.




    So that's all I have at the moment. Since I have been staring at these I would appreciate a fresh pair of eyes. If you have anything to add or query let me know.

    Thanks!

  2. #2

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: C#: Lexing Algorithm [Variable Declaration]

    Legend Nick, I hadn't even thought of that one. This is the issue just trying to find the ones that would not come up every day! Thanks a mill, keep em coming!

    PS: Check the blog for current progress if your interested!

  4. #4
    Addicted Member cutamacious's Avatar
    Join Date
    May 2001
    Location
    INDIA >> Andhra Pradesh >> Hyderabad
    Posts
    185

    Re: C#: Lexing Algorithm [Variable Declaration]

    Quote Originally Posted by NickThissen View Post
    What about constants?
    public const int ABC = 3;

    That's 4 words before the assignment.

    I'm sure there are more.


    How about this

    Code:
    public static readonly int a = 1;
    I use this in my projects for declaring readonly variables as a part of a class file.
    Cute Member

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: C#: Lexing Algorithm [Variable Declaration]

    Super! Thanks a mill, rep+ for you!

    PS Check the blog for updates on this lexing project!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width