设计简单编程语言的方法 [英] Methodologies for designing a simple programming language

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

问题描述

在我不断努力以消除对更多编程知识的不懈渴望时,我想到了尝试编写一种(至少现在)编译为字节码的简单编程语言的想法.问题是我对语言设计一无所知.有人对构建解析器的方法有什么建议吗?每种语言应具备哪些基本功能?您会为语言设计推荐什么读物?我应该拍摄多高的水准?希望能够包含一种允许以类似于gcc允许内联汇编器的方式内联字节码的功能是不现实的吗?看到我主要使用C和Java编写代码,这对于编译器编写会更好吗?

In my ongoing effort to quench my undying thirst for more programming knowledge I have come up with the idea of attempting to write a (at least for now) simple programming language that compiles into bytecode. The problem is I don't know the first thing about language design. Does anyone have any advice on a methodology to build a parser and what the basic features every language should have? What reading would you recommend for language design? How high level should I be shooting for? Is it unrealistic to hope to be able to include a feature to allow one to inline bytecode in a way similar to gcc allowing inline assembler? Seeing I primarily code in C and Java which would be better for compiler writing?

推荐答案

有很多方法...

您可以研究堆栈语言和Forth.在设计其他语言时,它不是很有用,但是可以很快完成.

You could look into stack languages and Forth. It's not very useful when it comes to designing other languages, but it's something that can be done very quickly.

您可以研究功能语言.它们中的大多数基于一些简单的概念,并且具有简单的解析.而且,它们非常强大.

You could look into functional languages. Most of them are based on a few simple concepts, and have simple parsing. And, yet, they are very powerful.

然后是传统语言.他们是最难的.您需要了解词汇分析器,解析器,LALR语法,LL语法,EBNF和常规语言,才能通过解析.

And, then, the traditional languages. They are the hardest. You'll need to learn about lexical analysers, parsers, LALR grammars, LL grammars, EBNF and regular languages just to get past the parsing.

以字节码为目标并不是一个好主意-否则,这在学习过程中简直是疯狂,而且几乎没有用.

Targeting a bytecode is not just a good idea – doing otherwise is just insane, and mostly useless, in a learning exercise.

帮个忙,并查找有关编译器的书籍和教程.

Do yourself a favour, and look up books and tutorials about compilers.

使用C或Java均可. Java可能有一个优势,因为面向对象非常适合此类任务.我个人的建议是Scala.这是一门很好的语言,可以教您有关语言设计的有趣知识.

Either C or Java will do. Java probably has an advantage, as object orientation is a good match for this type of task. My personal recommendation is Scala. It's a good language to do this type of thing, and it will teach you interesting things about language design along the way.

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

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