⬆️ ⬇️

GAZ Compiler - replacement for standard BAT-files in the Windows operating system

My brother was 9 years old, and he really wanted to learn how to program. I thought for a long time what to offer him this. Most started with Turbo-Pascal. But since in the second year of primate we passed compilers, I decided to write my own compiler.



It was assumed that the compilation will go to bytecode, which will then be executed by the virtual machine. The language was supposed to be made similar to Turbo-Pascal, only easier.



In the process of writing, I got too carried away and it turned out not quite what was originally intended (programming language for learning). No, the language syntax is extremely simple, everything is in order. For training it can be used, only he has two drawbacks:

')

1) There is no literature for training. There is only a list of files with examples.

2) I think some properties of the language, such as weak typing, are not good for the first programming language.



It turned out 1C-like language, which I myself began to use to automate operations on the computer. And accordingly, “nashpigovyvat” it with new, imaginable and unthinkable functions.



The simplest program in the GAZ language looks like this:



 Message ('Hello, world!')




To run the application, you need to download the latest version of the GAZ compiler from the www.osinavi.ru/gaz page (currently it is version 2.47), then install using the install.bat file in the archive. Then you can create a file with the gaz extension on your desktop, write the program text into it, save and then launch it with a double click. That is, everything is similar to files of type pl, php, py, bat, vbs, etc.



Note: the archive contains the executable file nod32krt.exe. This file has nothing to do with viruses and antivirus. The site is serious, and I do not distribute Trojans. It just so happened historically that I really wanted to hide some processes in the task manager from the eyes of the authorities. He even wrote a special program in the GAZ language. But more about that later.



Note 2: if you just need to test the capabilities of the compiler, do NOT need to download and install SuperGAZ. He, along with the GAZ compiler, installs a whole lot more, and not everyone may like it (although in principle there is nothing criminal). Just download GAZ version 2.47. But some examples supplied with the GAZ compiler, for example, photo converter, will not work due to the lack of SuperGAZ.



When installed, the GAZ compiler registers the gaz, bnz extensions to run with the help of the compiler, adds the path to the environment variable path and actually copies the files of the compiler itself. That is, in principle, similar to installing Perl.



The main characteristics of the language GAZ:



- weak typing, there are three built-in types integer, float, string

- array support

- the ability to use procedures, functions, transfer parameters, transfer arrays as parameters

- for assignment is used "="

- exception handling try-except-end

- several types of comments: // / ** / (**) {}



Main features of the GAZ compiler:



- methods for working with files and folders (in fact, this is most often used)

- math functions

- methods for working with strings

- exception handling, exception generation

- dialogs for entering numbers, choosing a file, folder, etc.

- work with processes and windows, hiding windows

- application launch, application shutdown (KillProcess)

- work with hot keys

- mouse pointer control

- work with Firebird DBMS

- work with regular expressions

- work with threads

- the ability to add an arbitrary program to autoload using the AddProgramToAutoload procedure

- work with clipboard

- compilation in exe is possible

- it is possible to create console programs, redirect output to a file

etc.



I will give an example of a more complex, but not too complicated program to demonstrate the capabilities of the compiler.



There are such situations that you need to delete all files from any folder. But Windows does not. That would be good if he did not delete all the files. but only those that can! This program will do just that:



 If Question ('Delete all files in this folder?') <> 1 then Exit
 Message ('Enter the number 3 if you are so sure')
 if InputInteger ('') <> 3 then Exit

 ShowConsole ()

 path0 = ''

 procedure delPath (path)
    GetFiles (path, CountFiles, Names [], IsFiles [])
    for i = 0 to CountFiles-1 do begin
       try
          if IsFiles [i] = 0 then begin
             FileDelete (Names [i])
             writeln (path + '\' + Names [i])
          end
          else begin
             DelPath (path + '\' + Names [i])
          end
       except
       end
    end
    if path <> global.path0 then begin try PathDelete (path) except end end
 Endprocedure

 PathSelect ('', path0)
 DelPath (path0)

 Message ('Done!')




Here is another program for calculating alcohol in the blood:



 write ('Your weight, kg:') m = readlnfloat ()
 write ('Alcohol,%:') a = readlnfloat ()
 write ('Received amount (ml):') k = readlnfloat ()

 p = (a / 100 * k / 100) / (m / 100)

 pm = 1 / 0.7 * p
 pw = 1 / 0.6 * p

 hm = pm / 0.1
 hw = pw / 0.1

 writeln ('In 1 hour it is displayed somewhere 0.15 ppm - we will assume that just in case that 0.1')
 writeln ('Promille (if male):' + floattostr (pm, 2) + '(' + floattostr (hm, 2) + 'hour.)')
 writeln ('Promille (if female):' + floattostr (pw, 2) + '(' + floattostr (hm, 2) + 'hour.)')

 pause ()




More complex projects consisting of several hundred lines of code will not be published, since this will increase the size of the article too much. But I can send to all interested.



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



All Articles