📜 ⬆️ ⬇️

W.Script languages. Part 2 - high-level languages, or why are we in the C ++ corporation

I recently published a review of how to write the Hello World program in the corporate language R.Script LLP. This language is considered in our corporation low-level, as it is the fastest used by us. Now I will tell about its modification - R.Script M HPL (Modified HighProgrammingLanguage).

What are these languages ​​designed for?


All WS class languages ​​are written by us to speed up the performance of our tasks and already with a ready-made set of functions. Languages ​​are written in pure assembler so they have great performance. Since microcontrollers are often programmed in these languages ​​and the logic of processors, the main bias in R.Script was made for performance. The performance of the HPL language is approximately equal to the C language, but its use requires large processor and memory resources. It is more profitable for us to develop and maintain our language than to use third-party, because in ours we will do everything as it is convenient and necessary for us.


Preface, or what this article is written for


This article is written solely to show how we in our corporation implement those or other tasks, as well as show our developments. WS programming languages ​​(R.Script, L.Script, W-Script) are used only in our corporation and are not subject to full disclosure, only familiarity with syntax and other features.
')

R.Script Modified Overview


Writing Hello, world

Writing Hello, world is much easier compared to LLP. Here, language modifications are first loaded:
LOAD(INCLUDE{SCRIPT[~SYSTEM:.add>highlevel#]}); //Loading file C:/R.Script/highlevel.add 

And then actually use the language. In this modification, the main body is already provided:
 source .main { //Some code there } 

And now use the built-in output functions:
 var(int) conid = Console.OpenWindow(title="Hello,world",desp="Example application"); Console.WriteLine("Hello,world"); Console.CloseWindow(id=conid); 

And we get this not very wise program, and for all it works on almost all platforms using the Console on Windows and the terminal on Linux / Mac.
 //R.Script 2012 M HPL Hello world source .main { var(int) conid = Console.OpenWindow(title="Hello,world",desp="Example application"); //  ,    Console.WriteLine("Hello,world"); //  ,     App.Wait(5s); // 5     ( App.Sleep) Console.CloseWindows(id=conid); //   } 

And now practice

Well, now I decided to write a translator script in the console, using the Google Translate service and working with its API.
 create function .getTranslatedText (pagecode) { if (var.isset=pagecode and var.!empty==pagecode and String.Search(result,"translatedText")==TRUE) { var(str) result = String.Cut(mode="searchline","\"translatedText\" :\"(.*)\"","intext"); //        return result; } else { if (Console.IsOpened()==FALSE) var(int) conid = Console.OpenWindow(); //    -  Console.WriteLine("translated text get error"); // use finish(conid); //   .  use   ,          return 0; } } create function .finish(consoleid) { if (Console.IsOpened==FALSE) App.Exit(); //,    ,   -  if (var.!isset=consoleid and var.empty=consoleid and Console.WindowExists(consoleid)) App.Exit(); //     Console.WriteLine(text=" ,     ",window=consoleid); Console.WaitKey(); App.Exit(); } source .main { include("SYSTEM:.dir>HTTP:.hpl>prot"); // ,     HTTP ( C:\Source\HTTP\prot.hpl) conid = Console.OpenWindow(title="- ","Powered by Google Translate"); var(arr) messages = Array.Create(0>"  !    ",1>"   ",2>"  :",3>"  ,     ,  F2    "); var(int) messnum = 0; Console.WriteLine(messages[messnum]); var(str) texttotrans = Console.ReadLine(); Console.WriteLine(messages[messnum++]); result = HTTP.GetHTML(url="https://www.googleapis.com/language/translate/v2?key=MY_KEY&source=en&target=ru&q="..String.Change(" ">"%20",texttotrans),mode="secure"); var(str) return = use getTranslatedText(result); Console.WriteLine(messages[messnum++].."\n\r"..return.."\n\r"..messages[messnum++]); var(int) userkey = Console.ReadKey(); if (userkey==K_KEY_F2) { App.ClearVars(); App.StartMain(); } else App.Exit(); } 

As a result, we received a console multiplatform English-Russian translator. Here is a practical application. In this code, you can learn almost all the features of this language. If something is not clear - you can ask questions.

From the author

This language is practically not used in practice. It is used in the main L.Script and W.Script Platform, which I will write about in the next article and write out in detail what is there and why, and also compare their codes with C ++ codes and their advantages as compared to it. I will also talk about building GUI applications using the built-in L.Script libraries.

To be continued...

Source: https://habr.com/ru/post/158099/


All Articles