是否有一种语言接近英语的编程语言?

时间:2010-12-30 18:49:37

标签: parsing compiler-construction programming-languages nlp

大多数语言允许“调整”语法的某些扩展部分(C++C#)和/或您将在代码中使用的语义(Katahdin,{ {3}})。但我还没有听说过一种语言可以完全定义代码的样子。所以不存在一些已经存在的语言,它具有覆盖所有语法和语法的能力。定义语义?

我想要做的例子基本上来自下面的C#代码:

foreach(Fruit fruit in Fruits)
{
  if(fruit is Apple)
  {
    fruit.Price =  fruit.Price/2;
  }
}

我希望能够用我这样完美的语言编写上面的代码:

Check if any fruits are Macintosh apples and discount the price by 50%.

从这个“想象”语言中编码器的角度来看,我想到的优点是:

  1. 非常清楚发生了什么(自我描述) - 即使是小孩也能理解我的节目,这只是简单的英语
  2. 隐藏了我必须用C#编写的所有复杂性。但我为什么要关心这一点 if语句,算术运算符等,因为已经实现了
  3. 我认为维护这个程序的程序员的缺点是:

    1. 也许你会以不同于我的方式表达这个程序,所以你可能得不到全部 我在句子中表达的信息
    2. 程序可能非常冗长且难以调试,但如果可能甚至接近上述类型的语法,可能会有更多人开始正确编程?我觉得这太棒了。我可以去上班,然后写一篇文章在这样的winform上画一个正方形:
    3. Create a form called MyGreetingForm. Draw a square with in the middle of MyGreetingFormwith a side of 100 points. In the middle of the square write "Hello! Click here to continue" in Arial font.

      在上面的代码中,解析器基本上必须猜测我想要使用     上一句话中未命名的方块,我猜这么聪明的解析器很难写,但是我想做的事情很简单。

      If the user clicks on square in the middle of MyGreetingForm show MyMainForm.

      在上面的代码中“基本上”编译器必须:1)生成一个事件处理程序2)检查表单中间是否有任何正方形,如果有 - 3)隐藏表单并显示另一个表单

      看起来很难做但看起来并不是不可能的IMO对我来说至少近似于此(我个人可以生成一个解析器来执行np以上的3个步骤;它基本上与它必须以任何方式相同甚至在c#a.MyEvent=+handler;中添加,所以我在这里看不到问题所以我想也许有人已经做过这样的事了?或者是否存在一些复杂的实际负担来创建我看不到的“论文风格”编程语言?我的意思是如果解析器不那么好会发生什么情况呢? - 你的程序会崩溃,所以你必须重新说出来:)

6 个答案:

答案 0 :(得分:14)

退房:

The Osmosian Order of Plain English Programmers

代码示例:

The background is a picture.

A button has a box and a name.

To clear the status:
  Clear the status' string.
  Show everything.

To create the background:
  Draw the screen's box with the white color.
  Loop.
  Pick a spot anywhere in the screen's box.
  Pick a color between the lightest gray color and the white color.
  Dab the color on the spot.
  If a counter is past 80000, break.
  If the counter is evenly divisible by 1000, refresh the screen.
  Repeat.
  Extract the background given the screen's box. \or Create the background from the screen. Or something.

答案 1 :(得分:5)

一些互动小说设计师使用非常接近英语的语言语法。这是一些Inform 7代码,您可以play online

The foyer is a room.

The apple is in the foyer. It is edible. The description is "This is a ripe, 
green granny smith apple."

The apple core is a thing. The description is "This apple core all that is 
left of that granny smith apple you just consumed."

After eating the apple:  
  now the apple core is in the player;
  say "You gobble down the apple careful not to eat any of those cyanide-
  laced seeds you heard about."

我辅导了一个使用Inform 7的课程。其中一位导师给人的印象是设计,而不是写游戏。所以他通过阅读来标记程序,却没有意识到它们是真正的程序。

答案 2 :(得分:2)

我认为这不是一件容易的事,也不认为它会让调试生活更轻松

你会如何处理这些问题?

  • 拼写错误
  • 世界不同地区的不同方言
  • 世界同一地区的不同方言
  • 同义词
  • 你先解析哪一部分句子?
  • 撕裂(撕裂)和撕裂(从眼睛)两个单词拼写相同但意味着两个不同的东西。

带回COBOL或者你还记得“走西”,“检查门”,“推门”,“打开门”,“门上使用钥匙”:)

修改 - 您如何强烈输入此内容?

答案 3 :(得分:1)

我编写了一个名为EngScript的可扩展的英语到Python编译器,它将结构化英语转换为可用的Python代码。

这是EngScript代码的示例:

print{create a string from the file called "README.txt"}
print{save the string "Woohoo!" to a file called "ExampleText.txt"}
print{the first 3 letters of "EngScript"}

这是EngScript编译器生成的输出:

print(pythonFunctions.stringFromTextFile("README.txt"))
print(pythonFunctions.writeStringToFile("ExampleText.txt", "Woohoo!"))
print("EngScript"[0:(3 - 1)+1])

答案 4 :(得分:0)

LiveCode! 有一些"自然语言",高级,类似英语的编程或脚本语言。可能所有人都受到了最古老的COBOL的启发。我个人最喜欢的这些语言是LiveCode。 LiveCode是MetaCard的后代,它是Apple现已解散的HyperCard的Linux克隆版,它使用了类似英语的脚本语言HyperTalk,该语言受到SmallTalk的启发,反过来激发了JavaScript(以及整个万维网)。 HyperTalk是另一种名为AppleScript(以及后来的AppleScriptObjC)的英语类脚本语言的基础,该语言至今仍配备了macOS。 LiveCode使用一种叫做LiveCodeScript的语言,或LCS,就像其他HyperCard克隆一样,多年来一直存在(SuperCard,Adobe的Lingo / Flash ActionScript,Open Xion,Oracle的工具书等),它与HyperTalk的核心非常类似,通常被称为X-Talk语言。 LiveCode有几个优点;它仍然在生产中,它有双重许可证(开源和商业版本),引擎是跨平台的(Mac,Win,Linux,HTML5,iOS,Android和服务器版本),和HyperCard一样,它是也是一个GUI工具包,它是可扩展的。 LiveCode团队目前正在开发一种名为LiveCode Builder或LCB的新型低级编程语言。 LCB也是类似英语的,虽然LCB的可读性比LCS稍差,但其目标是具有与C ++,Objective C等低级语言相同的功能,允许使用代码库扩展LiveCode平台和其他编程语言库生成的框架,最终允许LiveCode IDE用自己的语言编写。

答案 5 :(得分:-1)

尝试使用名为“Google”的编程语言 - 它具有自然的英文界面,您的代码片段会抛出您建议的所有答案。有趣的是,在你提出这个问题的六分钟之后,这个页面的查询结果是#1:

  

检查是否有任何水果是Macintosh   苹果和价格折扣50%

使用Google API,我认为您拥有自然英语编程语言的基础。