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!
Re: C#: Lexing Algorithm [Variable Declaration]
What about constants?
public const int ABC = 3;
That's 4 words before the assignment.
I'm sure there are more.
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!
Re: C#: Lexing Algorithm [Variable Declaration]
Quote:
Originally Posted by
NickThissen
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.
Re: C#: Lexing Algorithm [Variable Declaration]
Super! Thanks a mill, rep+ for you!
PS Check the blog for updates on this lexing project!