Click here to Skip to main content
Rate this: bad
good
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);
        currentClass.Emit(Opcodes.Set);
        currentClass.Emit(Class);
        currentClass.Emit(Name);
    }
    else
    {
        cmd = cmd.Substring(cmd.LastIndexOf(' ') + 1);
        string Class = cmd;
        string Name = "variable";
        currentClass.Emit(Opcodes.Set);
        currentClass.Emit(Class);
        currentClass.Emit(Name);
    }
}
 
please help!
Posted 17-Nov-12 20:41pm
Comments
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
good
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:
hello:this::is:wrong
would process as a class of "hello" and a name of "wrong" It also wouldn't fail if you gave it
Hello::::::::there
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;
    }
  Permalink  
Comments
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 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 319
3 Sergey Alexandrovich Kryukov 241
4 Gihan Liyanage 194
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 372
4 thatraja 370


Advertise | Privacy | Mobile
Web02 | 2.8.140902.1 | Last Updated 18 Nov 2012
Copyright © CodeProject, 1999-2014
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