use*_*298 12 compiler-construction parsing nlp programming-languages
大多数语言允许"调整"语法的某些扩展部分(C++,C#)和/或将在代码中使用的语义(Katahdin,lua).但我还没有听说过一种语言可以完全定义代码的样子.那么是不是已经存在一些具有覆盖所有语法和定义语义的能力的语言?
我想要做的例子基本上来自下面的C#代码:
foreach(Fruit fruit in Fruits)
{
if(fruit is Apple)
{
fruit.Price = fruit.Price/2;
}
}
Run Code Online (Sandbox Code Playgroud)
我想能够用我这样完美的语言编写上面的代码:
Check if any fruits are Macintosh apples and discount the price by 50%.
Run Code Online (Sandbox Code Playgroud)
从这个"想象的"语言中编码器的角度来看,我想到的优点是:
我认为维护这个程序的程序员的缺点是:
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;所以我没有看到这里的问题)所以我想也许有人已经做过这样的事情?或者是否存在一些复杂的实际负担来创建我看不到的"论文风格"编程语言?我的意思是如果解析器不那么好会发生什么情况呢? - 你的程序会崩溃所以你必须重新说出来:)
Sar*_*raz 14
查看:
代码示例:
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.
Run Code Online (Sandbox Code Playgroud)
一些互动小说设计师使用非常接近英语的语言语法.这里有一些Inform 7代码,您可以在线播放:
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."
Run Code Online (Sandbox Code Playgroud)
我辅导了一门使用Inform 7的课程.其中一位导师给人的印象是设计,而不是写游戏.所以他通过阅读来标记程序,却没有意识到它们是真正的程序.