Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey Guys,

I am still working on my programming language and I have already added classes, but I want a different way to use classes. I was thinking along the lines of my classes being something like this:

Program()
{
code goes here
goto Next
}

Next()
{
jumps to here
}


That is what I have in mind, but I don't know how to do it. I was thinking it would be something like:

dim class as string = "Program"
dim id as integer = indexof("{")
dim id2 as integer = lastindexof("}")
dim code as string = class, id + 1, id2 - id - 1

It would be something like that and then changing classes would be something like:

Begin:
dim class as string = "Program"
dim id as integer = indexof("{")
dim id2 as integer = lastindexof("}")
dim code as string = class, id + 1, id2 - id - 1

Begin:

for each a as string in code.split(system.environment.newline())
some code goes here
some code goes here
some code goes here
if a.startswith("goto ") then
class = a.substring(5)
goto Begin
endif
next


something along the lines of that. I didn't include some things like the textbox1, textbox2. Just saying, TextBox1 is the input and the TextBox2 is the output. So my final code looks something like this:

dim class as string = "Program"
dim id as integer = indexof("{")
dim id2 as integer = lastindexof("}")
dim code as string = textbox1.text
dim source as string = ""

Begin:

for each a as string in code.split(system.environment.newline())
if a.startswith(class) then
source = class, id + 1, id2 - id - 1
for each b as string in source.split(system.environment.newline())
(some code goes here)
(some code goes here)
(some code goes here)
if b.startswith("goto ")
class = a.substring(5)
goto Begin
endif
next
endif
next


sorry if it looks a little confusing but this is what I think the code would look like for classes in my programming langauge. I know that this isn't what it is and I think it has something to do with Regex Methods(I don't know how to use them, so I havn't tried) and can you guys please help me?

[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 5-May-12 19:16pm
v2

1 solution

You would probably learn more by studying the structure of existing languages and modelling yours on the more common parts. The idea of using goto to jump from the end of one method into another (or anywhere else) strikes me as one of the worst ideas ever.
 
Share this answer
 
Comments
Member 8378691 9-May-12 5:39am    
well, its in a lot of programming languages. look at visual basic, c# and batch. they are all great languages and they all use the goto statement at the end to go the the next.
Richard MacCutchan 9-May-12 5:51am    
goto has been deprecated in programming languages for many years, particularly since the advent of OOP, but even in procedural code it is only acceptable in the most extreme cases.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900