改善我的编程语言 [英] Improving My Programming Language

查看:76
本文介绍了改善我的编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我仍在使用我的编程语言,并且已经添加了类,但是我想使用一种不同的方法来使用类.我正在按照我的课程思路来思考,就像这样:

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



类似的东西.我没有包括诸如textbox1,textbox2之类的东西.只是说,TextBox1是输入,而TextBox2是输出.所以我的最终代码如下所示:



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



抱歉,如果看起来有些混乱,但这是我认为编程语言中的类所使用的代码.我知道这不是问题,我认为它与Regex方法有关(我不知道如何使用它们,所以我没有尝试过),你们能帮我吗?

[edit]添加的代码块-OriginalGriff [/edit]



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]

推荐答案

您可能会通过研究现有语言的结构并在更常见的部分上建模来学习更多.使用goto从一种方法的结尾跳到另一种方法(或其他任何地方)的想法使我震惊,这是有史以来最糟糕的想法之一.
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.


这篇关于改善我的编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆