How to create a computer language

Source: Internet
Author: User

How to create a computer language
  1. Need to have basic knowledge of compiling principles. Constructs the basic common sense of compiling principles, on the one hand from the use of existing language experience, understand the basic terminology. For example, C, at least know the language elements include macros, expressions, statements, statement blocks, functions, pointers, and so on, and also know that C language has three stages of compiling, linking and executing. These basic concepts are necessary to master the learning process in a macroscopic sense. On the other hand, the common sense of compiling principles should come from books. such as Dragon Book, SICP. In this step, you need to know that most of the language processing is divided into lexical, grammatical, semantic and code generation four stages. Each stage, what is the difference.
  2. Understand the specific compilation algorithm. How much you know depends on whether you're using a third-party tool or if you need to start with a character. Personal advice, the Chomsky Grammar system, (extension) of the Basque paradigm (EBNF), regular expressions, and LL (1) Recursive descent analysis is a must. For LL (k), LR (k) to have a concept. Among them, the analysis of arithmetic expression is very good practice.
  3. The sense of grammar. Beginners have two points of difficulty in designing languages. first, do not know what kind of grammar/semantics are needed, second, do not know whether the design of the grammar can be achieved. If you practice a recursive descent method, you should already have a basic feeling. This time you can try to realize the familiar language. Some of the most common language grammar rule can be found. Although these syntaxes, especially C + +, may be context-sensitive, the book approach is difficult to implement, but a subset of it can be implemented. With this practice, you have a general experience of what you can do with your analytical algorithms.
  4. Gain insight into your area and define your needs. Whether you need a script that is similar to a natural language, or just an expression. After 3 stages of training, we have the ability to write grammar independently. Can write a basic version of the out.
  5. Implement your own language, especially the lexical and grammatical parts. This step is best to log out as much information as possible, such as a word list and print out the analysis tree.
  6. When you have an analysis tree, you can do semantic analysis. For beginners, the size of the language to be as small as possible, so that the interpretation of language and semantic analysis can be integrated, do not worry about which part of the code generation, which part of the semantic analysis. So this step is best to write the interpreter. The requirement for this step is simple, knowing what the symbol table does, learning to generalize and deduce types, and correctly handle branching and looping statements (if any).
  7. Design a VM language similar to ASM, which can be a stack machine model or a register machine model. Compose code generation from the syntax tree to generate this VM language out. and write a VM actuator. This step seems to be impossible, in fact, as long as willing to write, not a week to know how to do. At first, this VM language can only be used as an integer subtraction on the line, you can slowly add other more important features, such as running stacks, code addresses, jumps and so on. In addition, the LLVM as a goal is also a good choice, at least the interpretation of instructions do not have their own time, LLVM manual reading is also easy. That tutorial is particularly good.
at this point, the language was initially established. But because of the limited ability at the beginning, the language designed is stuttered. This time you can choose:
    • Move closer to an existing language;
    • Understand the mechanisms of existing languages and weigh them. At this time what is the dynamic/static type, the function is the first class, and the classes and objects are the issues to consider. Be sure to read more and use the existing language at this time. Thanks to the compiler experience, the existing language will be treated in a different perspective;
    • Learning functional programming is a great help in designing better grammars, writing and modifying compilers faster. For example, you can use Combinator to configure syntax in C + + in a DSL-like manner;
    • All that remains is the endless excavation of the language field. Context-sensitive syntax, syntax sugar design, runtime-assisted mechanisms (such as async,await these generalized control flow statements), GC, type derivation and static analysis, and so on. ;
    • Finally, the most important, fully understand the needs , in order to make a choice between many language elements.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to create a computer language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.