Writing a programming language: where to start? [closed]

Closed. This question is off-topic. Answers to it are not accepted at the moment.

Want to improve this question? Update the question so that it it fit into the theme of Stack Overflow in Russian.

Closed 5 years ago.

Improve the question

I am far from an ace, but I want to try to write some simple programming language for the web. No delusions of grandeur, just want to try. Can you tell me where to start?

Author: Arhadthedev, 2011-08-18

6 answers

  1. If you want to create a language for the web, you will obviously write a tool for interpreting / compiling applications that receive data from the server and output text to the standard output stream, in order to be able to output the results of the program (a web page, for example)-here I can advise you to read about CGI technology, write a couple of simple CGI scripts (on anything)...
  2. Decide which language you will create - interpreted or compiled. What is it it will be the result of the "compiler" (for example, you can just write a translator that will translate a program in YOUR language into an equivalent in PHP, which will be used in the future).
  3. Finally, on syntactic analysis, compilation, and so on-I advise (not for the first time) - J. R. R. Tolkien. Crenshaw, "Let's create a compiler" - for a person who is not going to bother with the theory of formal languages, reverse Polish notation, Backus-Naur forms and pr... pr... pr... - in just right. If you want to seriously deal with compilers-A. Aho "Compilers: principles, technologies and tools" ("Dragon book")...

P.S. If you are interested in scripts (in particular, for games) and scripting languages, I also advise you to pay attention to Alex Varanese "Game Scripting Mastery" - well written and easy to read (for my taste)

 12
Author: gote, 2011-08-18 13:41:04

A programming language is simply its idea, a specification describing the syntax, semantics, and standard library.

A programming language implementation is a program that translates a program from the source code of that language into the code of some other output language. The output language can be assembly language, virtual machine bytecode, or any other language.

Programming language implementation - a program that receives the most ordinary text, converts and outputs the result of the conversion (text or binary). I.e. there is no magic here.

The programming language itself can be invented without writing a single line of code (although it is damn difficult, because the code can be tested). What you want is to write aimplementation of a programming language.

A program that translates text like

print('test')

In the code

<?php
echo("test");
?>

It can be considered a primitive version of the translator.

Guided by the materials specified by others participants can make a much more complex example.

 6
Author: Vladimir Gordeev, 2011-08-19 14:34:03

I recommend it: Sverdlov - "Programming languages and translation methods"

The book contains the source code of the simplified version of the Oberon compiler in several languages (Java, C++, Delphi). As a target, it implements its own stack VM on bytecode(as is done in Java and .NET) (the source code of the performer and assembler is given). I liked the book for its practical orientation.

 4
Author: codemo, 2011-08-18 13:49:55

Start by writing examples of small programs (for starters, "Hello World !") in your language, accompanied by human descriptions, what, how, and for what this program does. Input data, event flow, and what we see as a result.

Then it will become clear how to parse the syntax (and which is the most convenient), what intermediate forms to build, how to execute-interpret (and on what) or what to compile.

 1
Author: avp, 2011-08-18 14:51:33

Learn assembly language. And in general, scripting languages have appeared relatively recently, so they willy-nilly have their ancestors of the big three C, Pascal, Java. So if you create something new in the scripting direction, then you can hardly do without them. And if you want to create a language, then write in Assembly language - this is the language of machines - and this is already a phase of low-level programming. And pcp c and others are high-level programming. That is, we wrote a program on a Sishka, a compiler I surpassed it in Assembler and the machine understood our program. So the Assembler will suit you.

 1
Author: new_russian_man, 2011-08-19 13:49:48

To write another programming language, you must use some language all the same. For example, take php.

Mylang.php

<?
  function h1($text){
    $text = "<h1>".$text."</h1>";
  }
  function sql($sql){
    $colsql = 0;
    $sql = mysql_query($sql) or die (mysql_error());
    $colsql+;
  }
  function text($text){
    print $text;
  }
?>

Index.php

<?
include ("mylang.php");
$text = h1("Текст в размере h1 по html разметкам");
text($text);
sql('Update table set text ='.$text);
text('<br />Сделано'.$colsql.' запроса в базу данных.');
?>

?>

 0
Author: Node_pro, 2011-08-19 08:49:40