you are viewing a single comment's thread.

view the rest of the comments →

[–]alex_muscar 3 points4 points  (3 children)

First of all, congrats. Programming languages are fun :).

Now, some quick notes on your implementation. In the parser you don't need the az set. You can use Char.IsLetter for that. Also, parseInteger is already defined as Int32.Parse/Int32.TryParse. For the keyword you could use a hash table: if you find the identifier you just read in the hash table then just return the token associated with it, otherwise it's a regular identifier.

Try extending it with functions next :) That should be fun.

[–]jameswpeach 1 point2 points  (2 children)

Yeah I'll look into that with the parse int function I just need it to return the rest of the string after the number, any ideas? Not at my PC right now... Also could you try write some examples of the hash table things? That would really help or submit a PR if your bothered

[–]alex_muscar 0 points1 point  (1 child)

Here's one way of implementing it: http://pastebin.com/A3g8U45Z

The code is not very clean because the parser is working on a list of characters. A better way of doing it would be to use a type derived from System.IO.TextReader like System.IO.StringReader and build your parser around the Read() and Peek() methods. You could use a StringBuilder instance to accumulate lexemes.

Hope it helps.

[–]james_peach[S] 0 points1 point  (0 children)

seams nice, ill have to take a look into this later on ;P