A good way to parse code - written in C-like or Lisp-like (or any) language - into an array using C #?

What would be a good way to parse C-like or Lisp-like code into an array using C #?

So, for example, for a small fragment, for example:

if (number > 50) {
    alert('Hello, World!');
}

I want to be able to store every word and character in an array.

But so far I have managed to output the array as follows:

[0] if
[1] (number
[2] >
[3] 50)
[4] {
[5] alert('Hello,
[6] World!');
[7] }

Do you see the location of the array 1where indicated (number? This is not what I want. I want even this little bracket to be placed in its own array location.

Initially, I thought about reading each character of the code, and then starting to store them in arrays, respectively. But it looks like I'm reinventing the wheel while parsing strings. Is there an easier way to do this?

p.s. , .

+3
3

C, .

. . , - + / * -> ( ) = == != < > <= >= << >> ; ? : " ' & && | || ~ ( ..) - . , , , . "" , "/", escape- \. , , , .

+3

fslex fsyacc. , .

F # , fslex fsyacc, .NET.

+1

, , "-", .

, , , " " ( SICP) , . eval, .

0

All Articles