flat assembler
Message board for the users of flat assembler.

Index > Programming Language Design > basics of a minimal language interpreter or compiler

Author
Thread Post new topic Reply to topic
MajorDill



Joined: 01 Nov 2010
Posts: 20
MajorDill
I know people have written ultra small compilers like brainf**k that really don't do anything but prove it can be done. I was wondering what the minimal language requirements would be for an interpreter that could create usable programs (play chess, solve math problems, language parsing (like ELIZA from the 70's).

My thinking is you would need 3 basic types of variables

1. real number variables
2. string variables
3. arrays

and these 7 basic commands:

1 PRINT to the screen
2 INPUT from a user
3 IF for decision making (ELSE) might be a luxury
4 DO-LOOP for repeating code
5 READ a file of data from somewhere
6 WRITE a file of data back
7 '=' assignment statement (like LET in basic)
+, -, *, / for numerics
split, concat for strings

Ability to define some type of function (rather than a subroutine which
doesn't return a value?)

Minimum functions: generate a random number
get system time and date

If think all other functions could be defined/created by the user or am I mistaken?

Anything I'm missing?

Any opinions?
Post 01 Aug 2020, 15:35
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 104
Location: Argentina
pabloreda
Post 01 Aug 2020, 18:04
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 774
Location: Belarus
DimonSoft
MajorDill wrote:
My thinking is you would need 3 basic types of variables

1. real number variables
2. string variables
3. arrays

and these 7 basic commands:

1 PRINT to the screen
2 INPUT from a user
3 IF for decision making (ELSE) might be a luxury
4 DO-LOOP for repeating code
5 READ a file of data from somewhere
6 WRITE a file of data back
7 '=' assignment statement (like LET in basic)
+, -, *, / for numerics
split, concat for strings

Ability to define some type of function (rather than a subroutine which
doesn't return a value?)

Minimum functions: generate a random number
get system time and date

Well, you’ve basically enumerated the basic feature set of classical Basic language (pun intended).

OISC has already been mentioned, so I’ll just add that, technically, even the retrieval of random number, date and time can be mapped to the READ statement.

Having a GOTO, an assignment statement, a few basic operators, an IF and a means to access arbitrary memory address might be enough for pretty comfortable usage. The rest is easily built on top of those.
Post 01 Aug 2020, 21:11
View user's profile Send private message Visit poster's website Reply with quote
MajorDill



Joined: 01 Nov 2010
Posts: 20
MajorDill
After playing around with it a bit I think a 32-bit program interpreter could be done at under 10k. Shorting all commands to 1 character and putting everything; program, variables, and stack into one string with pointers and no error checking could do it. If I remember right Tiny Basic (8-bit) was around 4k-6k
and only handled integers, no strings, arrays or subs/functions. I don't know about goto (it seems like cheating). Does anyone know of anything smaller?
(BrainF**K, Befunge and others don't count - you have to be able to write actual programs on it, like chess or Go)

Someone pointed out MOUSE by Dr. Peter Grogono around the 1980's but you need a PASCAL compiler and still doesn't do strings. (I don't know the compiled size)
Post 05 Aug 2020, 21:49
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 104
Location: Argentina
pabloreda
in forth is very common ultra small system,
my 32 bits lang is 34kb with compiler to bytecodes, interpreter, vector graphics with antialias and only dll for make sound (fmod)
the next lang, 64bits is 52 kb, with SDL library and the same vector graphics library.
the raspberry pi 4 version of the same lang has 35kb (all 64 bits)
Post 06 Aug 2020, 01:35
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.