Click here to Skip to main content
11,478,066 members (71,881 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
hey guys,

i am currently making a new programming language. i know what you are thinking, i make a lot of programming languages, and i do. i have a couple reasons for that. i need my practice and every single one of the programming languages that i make are different. this one is am running more like a virtual machine, it will have memory and all of the commands are stored in it. example, if i were to type in the code:

push string 'Hello World'

if would put in the command: push string
and then it would put in after it: Hello World

when i run this, it will look at the instruction and see that it is push string, and then it will look at the next instruction and push it. back on topic.

i am using this system to make variables and have them like classes. so i can type in something like:

var tom,person
tom::age = 6
tom::height = 179

this means that i can store lots of values within the one variable. but if you can see, i have to have the '::'. that is basically because it looks for the characters before the first ':' and the characters after the last ':'. I have tried everything i can. here is the code i have at the moment:

else if (cmd.StartsWith("set "))
    if (cmd.Contains("::"))
        cmd = cmd.Substring(cmd.LastIndexOf(' ') + 1);
        string Class = cmd.Substring(0, cmd.IndexOf(':'));
        string Name = cmd.Substring(cmd.LastIndexOf(':') + 1);
        cmd = cmd.Substring(cmd.LastIndexOf(' ') + 1);
        string Class = cmd;
        string Name = "variable";

please help!
Posted 17-Nov-12 21:41pm
OriginalGriff at 18-Nov-12 2:52am
And what is the problem? "Please help" with what?
Member 8378691 at 18-Nov-12 3:55am
Didn't I say? sorry, i want that code to go from 'tom::age = 6' to just one character to look like 'tom.age = 6'

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have you considered using a Regex? It looks like your code is getting quite complex, and subject to errors. For example:
would process as a class of "hello" and a name of "wrong" It also wouldn't fail if you gave it
A regex to handle it is pretty simple:
Regex classAndName = new Regex(@"(?<Class>[A-Za-z][\w_]*)::(?<Name>[A-Za-z][\w_]*)");
Match m = classAndName.Match("Class::Name");
if (m.Success)
    string vName = m.Groups["Name"].Value;
    string vClass = m.Groups["Class"].Value;
Member 8378691 at 18-Nov-12 4:26am
i know all the bugs and errors of my code, i have written, tested, written and tested some more. This is the best thing that i could come up with. i don't really want to use regex that much anyway. this programming language isn't meant to be a serious programming language anyway, i upload videos on youtube and make tutorials, this programming language is meant to be easy to use and understand yet effective. if i start using regex, people who are just starting to learn how to do this kind of stuff could get really confused.
OriginalGriff at 18-Nov-12 4:38am
The problem is that what you are trying to do is complicated - and the code to do what the regex does in C# is equally complex and confusing. It's your choice - but I would use the regex!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Frankie-C 160
1 Sergey Alexandrovich Kryukov 149
2 Sascha Lefèvre 145
3 F-ES Sitecore 130
4 siddartha kopparapu 103
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,321
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,325

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100