Jump to content

Project: qsil

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
For the past few days I've been working on a description for a general programming language using concepts I used in my stack based calculator. Through its making I have noted that its properties are in many ways the reverse of the programming language lisp. Therefore, the name of this language is qsil, though I have yet to decide on a correct pronunciation. However, pronunciation will not hinder discussion on the internet.
This language is:
* Stack-based.
* Monotypical.
* Reflective.
* Structured.
Here is the expected hello world program:
"Hello world in qsil" ;
"Hello, World!\n" #greeting := ;
greeting :print ;
This demonstrates several important features of the language. The source code is divided into tokens, (delimited by whitespace, except within quotes and brackets) each of which is then put into a queue of strings. The tokens are then evaluated for their effects, which depend on their format. Tokens in a quote delimited string format push the corresponding string onto the stack. Tokens which are symbol literals "#greeting" push their name "greeting" onto the stack. Tokens which are numbers "123.456" push the number in decimal onto the stack. However, tokens which are symbols without the # get looked up in the symbol table, and then the value that variable contains is pushed. Any tokens that do not match any of the above criteria are assumed to be built in operators.
So, let's go through that code again. The first line has a string literal, and then the operator ";". That operator discards everything on the stack. Therefore the line does nothing, since it does not alter any variables or perform any I/O. The second line contains a string literal, a symbol literal, the operator ":=", and the operator ";". First, the string literal is evaluated to a string, and pushed onto the stack. Next, the symbol literal is evaluated to the string "greeting", and pushed. Next, the ":=" operator assigns the string "Hello, World!\n" to the symbol "greeting", popping each off the stack. Finally, the ";" operator clears the stack, though it is already empty. In the last line, the "greeting" symbol is evaluated for the string "Hello, World!\n", and then the :print operator pops it off the stack and prints it.
YOu should now have a fairly good idea of how this language operates. However, there is one more intricacy to the language: code constants. In qsil, code itself can be data. This enables functional programming, and is the basis for conditionals and loops. Take a look at the following example:
"Invisigirl" "violet" := ;
"Elastigirl" "helen" := ;
"Mr. Incredible" "bob" := ;
"Dash" "dashiel" := ;
( "Name:" :print :gets #nam := 
 "Supername:" :print :gets #sup :=
 nam :deref pwd = ) #chksupname $=
The new function chksupname checks the identities of the members of the Parr family (The Incredibles) by asking them their superhero names. It returns 1 if the entered name and supername match, 0 if not. The operator $= assigns the code to a variable, but with execution on. When the name of the function is used, the code is not pushed onto the stack, but executed.
:More details later, after I've heard suggestions and stuff.

This description is public domain. Whatever.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It looks very interesting so far. I'd be interested in seeing a complete list of reserved words/operators. I particularly like the method of creating functions/function calls.

Would your calculator happen to be an HP series?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Nah, the calculator is an old project of mine, a stack based calculator with strings. Here is a list of reserved tokens, though it will probably change with more suggestions.
+ - * / ** = < > <= >= :sqrt :cos :acos :sin :asin :tan :atan :atan2 :abs
:print :gets :dup :rev2 :deref :del ; := $= & | ^ || && ! ~ :if :while :exit
They're basically C.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
# is also a reserved symbol (declaring variable)
I'm guessing ** is exponentiation.
Considering what you've said so far: there is one stack and a symbol table.
:roll is another stack operation I've seen.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
# is not exactly declaring a variable, it is a symbol literal. It puts everything up to the next whitespace into a string, as long as the characters are legal for a symbol. Legal symbols match
/[A-Za-z][-A-Za-z0-9]*/
Note that underscores are not legal in a symbol, because they're just ugly.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#6
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
I remember your calculator, mind if I include it in my OS?

#7
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Not at all.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz