PDA

Click to See Complete Forum and Search --> : C#: Lexing Algorithm [Variable Declaration]


DeanMc
Sep 22nd, 2009, 04:20 PM
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!

NickThissen
Oct 2nd, 2009, 05:30 PM
What about constants?
public const int ABC = 3;

That's 4 words before the assignment.

I'm sure there are more.

DeanMc
Oct 2nd, 2009, 05:33 PM
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!

cutamacious
Oct 4th, 2009, 09:49 AM
What about constants?
public const int ABC = 3;

That's 4 words before the assignment.

I'm sure there are more.



How about this

public static readonly int a = 1;

I use this in my projects for declaring readonly variables as a part of a class file.

DeanMc
Oct 4th, 2009, 02:59 PM
Super! Thanks a mill, rep+ for you!

PS Check the blog for updates on this lexing project!