为初学者创建一种小型编程语言 [英] Creating a small programming language for beginners

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

问题描述

我想创建自己的编程语言.也许不是完全从头开始的编程语言,但可能是基于另一种语言.

I would like to create my own programming language. Maybe not exactly a programming language from scratch but maybe base it on another language.

我听说过Yacc.因此,我安装了Flex和Bison.但是我不明白如何用它来编译.我已经在其中创建了Hello world项目,但是我将如何在其中创建编译器?

I've heard of Yacc. So, I installed Flex and Bison. But I do not understand how to make a compiler with it. I have made the Hello world project in it, but how would I make a compiler in it?

有没有简便的方法来创建小型编程语言,我听说过要像翻译Write()这样将一种语言翻译成计算机并将其理解为Print().

Are there any easy ways of creating a small programming language, I have heard of translating a language as in taking, e.g., Write() and making the computer understand it as Print().

这可能吗?

推荐答案

我的看法是,更简单的方法不是搞砸旨在自动创建词法分析器和解析器的核心工具,而是着手创建一个简单的方法. 解释程序的语法相当简单,解析器可以手工编写—涉及一个简单的状态机.

My take on this is that the simpler approach is not to mess with the hardcore tools intended to automate creation of lexers and parsers but rather to embark on creating a simple interpreter of a reasonably simple syntax, for which the parser could be written by hand — involving a simple state machine.

我想说的是,该任务的一种几乎理想的解释语言是 Tcl ,原因如下:

I'd say an almost ideal interpreted language for the task is Tcl, with the reasons for this being:

  • 超级简单的语法(几乎没有):该语法主要将字符分组定义为单词.

  • Super-simple syntax (almost absense of it): the syntax mostly defines grouping of characters into words.

然后以这种方式解释从正在处理的脚本的源代码行解析的一组单词:第一个单词是命令的名称,其余单词是该命令的位置参数.在Wikipedia上 快速获得概述.

A set of words parsed from a source line of the script being processed is then interpreted this way: the first word is the name of a command and the rest of them are positional arguments to that command. Get the quick overview of it on Wikipedia.

一切都是字符串,因为对参数的解释在处理它们的命令之手.

Everything is a string as interpretation of the arguments is in the hands of the commands processing them.

有可能逐渐使口译员更加轻松".例如,一开始可能会省略实现变量替换(Tcl< 2.0没有它们)和所有高级功能(句法和语义,例如名称空间).同样,可能没有这样的玩具解释器的脚本开始就没有命令或几乎没有命令可用.然后可能会逐渐添加它们.

It's possible to gradually make the interpreter more "beefy". For instance, for a start one might omit implementing variable substitutions (Tcl < 2.0 did not have them) and all the advanced features (both syntactic and semantic, like namespaces). Likewise, it's possible to start with no commands or almost no commands available to the scripts of such a toy interpreter. Then they might be gradually added.

通过研究其,您可以快速了解Tcl是什么.教程. .您可以在的地方使用Tcl.

You can get a quick sense of what Tcl is by working through its tutorial. More documentation is there. You can get Tcl to play with it there.

您可以在irc.freenode.net#tcl IRC频道和comp.lang.tcl新闻组(可通过Google网上论坛)上寻求帮助.

You can ask for help on the #tcl IRC channel on irc.freenode.net and on the comp.lang.tcl newsgroup (available via Google Groups).

这篇关于为初学者创建一种小型编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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