programming language design for true beginners

i prefer python for this, but sb is my favourite basic dialect and probably my first choice after python...

# simple programming language in smallbasic

# public domain 2017 mn

# "the moment learning actually begins is not when you read the spec and not when you take the examples out the spec [but] when you ask: 'i wonder...'"

# "the documentations going to run for paaaages, and thats how you know its a 'real' language!"

# "inside every large language theres a small language" https://www.youtube.com/watch?v=3N__tvmZrzc

program = "CLS:COLOUR10:PRINThello there:SLEEP5:cls:COLOUR14:PRINThow are you:SLEEP15"

pl = len(program) + 1
buf = ""

for p = 1 to pl
t = mid(program + ":", p, 1)
if t = ":":
if left(lbuf, 3) = "cls":
cls

elif left(lbuf, 5) = "color":
color val(right(buf, len(buf) - 5))
elif left(lbuf, 6) = "colour":
color val(right(buf, len(buf) - 6))

elif left(lbuf, 5) = "print":
print right(buf, len(buf) - 5)
elif left(lbuf, 6) = "prints":
print right(buf, len(buf) - 6);

elif left(lbuf, 5) = "pause":
pause val(right(buf, len(buf) - 5))

elif left(lbuf, 5) = "sleep":
pause val(right(buf, len(buf) - 5))

fi
buf = ""
else
buf += t
lbuf = lcase(buf)
fi
next

Before one goes off and designs ones own language one should have at least a medium grasp of the language they intend to write their own language in, and better, some exposure to other languages.

figosdev premise that one could learn programming this way strikes me as backward. Has figosdev so advanced in his own development forgotten how people actually get started?

It seems very basic logic to me to write a new language you have to start with an old one. Sure, then! go ahead and try your new language and learn a bunch more about programming!

I'm sorry, but I am still confused. All this talk of creating a 'new' language, and the way it's portrayed, is not 'new' at all but an existing language being used to create a facade or the 'appearance' of a language. Like using SB or SDLBasic to to 'simulate' the Logo language. It looks like a language but it is merely a fancy interpretation. I hope I am making sense. I mean no disrespect to the programmers' ability to create the work... quite envious actually... but is it 'really' a 'new' language? I have no experience, when it comes to creating a language, I am just telling it like I see it. Please correct me if I am wrong. This is yet another reason why I leave creating languages to those that know...

J

we could go in circles like this forever johnno. if you tell me what *you* think is required for it to be a "new language," i can tell you which parts of that are not requirements, and why.

if i had to answer your question without you being more specific, i could dump a truckload of guesses onto you. it would be dull and a lot of work, and you wouldnt read it. which brings me back to: "if you tell me what *you* think is required for it to be a 'new language,' i can tell you which parts of that are not requirements, and why." i can tell you this though-- theres nothing that makes mgas implementation of logo NOT an implementation of logo. its not 100% new because... well, logo existed. but he implemented it in smallbasic, not in logo. same goes for nano.

I think it's a fine idea for a learning exercise. It may not result in anything useful, but who cares?

It you make an attempt at something and then realise all the gaps in your knowledge, that provides the impetus for further investigation and study.

For something truly useless, yet interesting and funny see:

https://en.wikipedia.org/wiki/Brainfuck

"Has figosdev so advanced in his own development forgotten how people actually get started?"

no. figosdev:

* learned at a very young age, typing examples in from a spiral-bound book published by ibm.

* notes that some people learn javascript as a first language now, there are "javascript for kids" books, and this is easier.

* isnt talking about whatever youre talking about, which is probably more difficult :P

Maybe it's like borders between countries, you see them on maps but in real world... where's the line?

I am curious as to why create 'new' languages within a language? Surely, the 'new' language, will inherit the limitations of the host? As Aristotle once said, "The whole is greater than the sum of its parts". Perhaps it's for the satisfaction that it 'can' be done; Notoriety; Challenge or just pure creativity. (or a combination of any and all )

Although the 'borders' are very clear, on a map, like the reasons for making a language, can be blurred, just like 'real' borders...

Have you watched the documentary "The Birth of Basic"? It's a little 'dry' but quite interesting. https://www.youtube.com/watch?v=WYPNjSoDrqw

J

is not problem if you whish to create your own language
but problem is when you try to do that without enough knowlege or experience
about that..so i agree with Mark about that ..

I totally agree... I am fascinated by the concept of creating a language but I am seriously lacking in both knowledge and experience... *sigh* This is where I get to watch you guys shine...

J

the sad thing is, that most people know the difference between a definition and an instance-- but when it comes to creating languages, people cant get past the fanciest instances. you dont need a 4-stage parser and a machine-code compiler to create a language.

there isnt "a" point in creating a language within an existing language-- there are several points.

but to answer johnno directly-- no, your language will NOT necessarily have all the limits of the language used to implement it. many of those can be worked around, except speed. sometimes thats a real limit, sometimes not.

the point of writing a simple, easy language is to find out how easily you can create a language. then you can build on it (if you want) and learn as you go. a lot of people seem to want to be able to do things, but they think they cant learn. then when presented with an easy way to learn, they say "well what is the point of this?" um, i guess you have to do it for the point to become obvious. making it easy is vital to getting people to try it, so thats the point of doing such a simple version. why not start easy?

its funny-- everyone accepts "hello world" but make a "hello world" of something more complex, like creating a language, and people say "yes, but WHAT IS THE POINT?" well, explain "hello world" to someone who has never coded. except this hello world can turn into something useful VERY quickly. but not until you start.

also:

i didnt invent implementing languages in existing languages. ALL software languages are implemented in existing languages. freebasic does NOT compile to machine code, it compiles to c. qb64-- does NOT compile to machine code, it compiles to c++. fig does not compile to machine code-- it compiles to python. and python is case-sensitive, but fig (like basic) is not. python is sensitive to whitespace, but fig (like basic) is not. you can overcome or override the parameters of your implementation language.

Following figosdev example / idea, Nano uses no other punctuation than a space (A really cool idea I picked up from figosdev!). That is something SmallBASIC can't do and yet it can be done with a small subset of SmallBASIC commands.

This actually might be useful for those like me loosing their eyesight and can't make out the difference between a comma and a period!

i stole the idea from logo. and in particular qb draw strings.

for many years i wondered what it would be like if you could code in basic without punctuation. i could use newlines for strings to avoid quotes, but im ok with quotes.

by the way, im now working on a book inspired by this thread. you can find the first 12 pages here: (it already answers some of johnnos excellent questions) http://www.thejoyfulprogrammer.com/qb64/forum/showthread.php?tid=851

why python and smallbasic are especially nice for language design

my favourite language for making languages is python, and my favourite basic dialect is smallbasic. i will now explain why i find these two languages ideal for creating languages.

python of course, lets you create a com-terpreter with the exec() command. exec() lets you take a huge shortcut while creating your first language, by building a string (either a line at a time, or a program at a time!) and then running it without leaving the python interpreter. but i dont think this is a great design (fun and interesting, perhaps not ideal) and it isnt the only reason i think python is especially good for making languages.

python and smallbasic arent the fastest languages, so raw speed isnt something i would name in their favour. what they are is flexible-- python is extremely flexible, and a feature like a hash table is great for storing variables:

vars["a"] = "value of a" ; vars["program_name"] = "name of program" ; vars["height"] = 177.5

a programming environment that has hash tables makes it trivial to keep track of all the programs variables in a single hash table.

both python and smallbasic have excellent array handling. with 32 and 64 bit string access, you can certainly get by handling strings and re-dimensioning dynamic arrays, but smallbasic and python both make it easy with array concatenation, array slices (like what the mid command does to strings) and split and join commands for converting strings to arrays and arrays to strings without having to create your own loops for doing that.

some people argue that split and join arent needed in a basic dialect, but they are such useful and friendly features-- i believe the only reason basic didnt have them sooner is that they made less sense or were more trouble to implement with 16 bit memory limits. they can be useful for simple parsers.

Hi updater,

I am glad you have updated this last comment/reply, the original links to the other end were kind of blown away.

Now this vars thing is really interesting!

While I was digging in Python Docs, I did finally find EXEC after your helpful explanation (better than what I found in DOCs) and I ran across EVAL on the way to EXEC. As you might or might not know I am at moment studying EVALs across BASICs for FB compile of Nano as standalone. This is big lesson of difference between interpreters and compilers I am learning at FB forum!

I was looking forward to this VARS sort of thing discussed at The QB64 Editition, NOW especially seeing flukiluke's gem posted there. Though I did not run it just reading the DOCs and looking over the code, I was saying hey! I wanna do something like that someday! hey! there is a working example of an object, a virtual machine?

Cool stuff!

the use of the phrase "virtual machine" is going to get to me. to me, a virtual machine is a computer implemented in software. qemu is a virtual machine. theres also hardware virtualisation. and a "vm" will let you run from a server-- amazon offers this. these days you can do websites from vms.

in programming theres a thing called a "finite state machine" which is more like a subroutine than a virtual machine. im not saying its a subroutine, im saying a "vm" is usually a big complicated thing, and a fsm is a little snippet of a thing, like a little part of a program.

based on wikipedia, i think what luke is talking about is a "process virtual machine," which is relevant to programming languages. if you want to get into object-oriented design, you should talk to him, or possibly to walt (as walt is interested in objects.)

i have practically no interest in objects and i never did. as ive said over and over and over, they have their place but they do complicate things sometimes.

what i love about python (this is a matter of style or attitude as much as a matter of design) is that it has virtually all the power of objects (literally everything in python is an object) but python doesnt push them on you. a lot of languages are multi-paradigm and oop is a paradigm, which python doesnt REQUIRE you to mess with. the programs i write in fig for example, translate much more easily to something like smallbasic than if i designed them with objects. but i dont do it for compatibility-- i do it because its easier.

smalltalk (probably) made objects easy. java is complicated enough that universities are switching to python courses for "beginners." note thats also where basic started-- universities. then schools for younger students.

theres more than one paradigm to code from, and while objects are cool sometimes, theyve never done for me interest-wise what other things do. objects arent elitist, but a lot of its fans are-- and the condescension is a regular turn-off.

of course if i wanted to recreate python i would need to implement objects. theres no oop code in the cpu though, and im more interested in telling people how computers work than telling them how to abstract everything to the point where everything is an object.

the problem with elitism is how narrow it is. for example, people will tell me that doing it "my way" has limitations. i know doing it my way has limitations-- thats a fundamentally absurd caveat, any design choice you make will have limitations.

what theyre saying when they critique my choices is they dont care about the limitations inherent in their choices, but i should care about mine enough to do it their way. thats less like science and more like cult, but geeks are like that sometimes. on most days im a geek, but not all elitists agree.

"vars" is just a dictionary (a hash table in this case.) dictionaries are just arrays where instead of an index number a(1) a(2) a(500) you can use other kinds of data like a("height") a("weight") a("preference for programming paradigm") -- you can have a(5) and also a("5") in a dict, but they arent indexed (or in order.) theyre "keyed." and yes, theyre implemented with objects. we covered that-- everything in python is an object, but you dont have to worry about that unless you want to. luke wants to. i dont. he thinks thats reason to insult me. i find that really, really boring. elitism doesnt impress me.

basic has always provided easier ways to do things. outside of this smallbasic thing, most of the dialects out there have started harassing people over doing anything a simpler way.

i mean harassing like bullying and ridicule. this is the ANTITHESIS of basic (not offering more complex ways to do things, which is fine,) -- trying to push people into more complex ways of doing things; even when they dont feel a need, arbitrarily; and acting like a simpler way never suffices and is only for people that dont know what theyre doing. thats irritating. and it was never what basic was about.

i like dictionaries because even when i was using qbasic, i wondered why you couldnt have an array that used string indexes instead of numeric. i think the answer was "because there are only so many k in base memory."

most of the basic community is swept up with advanced features-- fine, the problem is how pushy they are about it. i dont mean they dont shut up, i mean theyre puffed up and full of abuse about it. every dialect that goes that way, i lose interest in. you couldnt pay me to work with qb64-- when do you hear from galleon? hes hiding from his toxic community.

the nun-with-a-ruler model of education i have no time for, but some of these people were obviously toilet-trained at gunpoint. i mostly associate objects with jerks, but dont worry-- its not really the objects fault.