# dumb-stack-lang This is a tinkering repo for an interpreted stack-based language implemented in Haskell. God help you if you want to use this for anything. ## Current features ### Datatypes * Booleans * Arbitrary-prescision integers * Strings ### Procedures Code is separated into procedures. A program must define a procedure named `MAIN` to serve as the entrypoint. ``` PROC is-even? 2 OVER % 0 == END PROC MAIN 4 is-even? . '''true''' 5 is-even? . '''false''' END ``` ### Postfix/Reverse Polish notation Procedures are invoked by pushing its arguments to the stack in reverse order and then calling the procedure: ``` PROC ''' compute 2+1 and print the result (3) ''' 1 2 + . ''' compute 2-1 and print the result (1) ''' 1 2 - . ''' compute 1-2 and print the result (-1) ''' 2 1 - . ''' test if 5 is greater than 6 and print the result (false) ''' 6 5 > . ''' compute 2+3, test if 3 is less than the sum, and print the result ''' 3 2 + 3 < . ''' concatenate two strings and print the result ''' " but backwards" "it's like LISP" ++ . END ``` ### Comments Comments are multi-line only and are opened and closed with three single-quotes: ``` PROC MAIN IF 2 9 % 0 == DO ''' TODO: come up with a better message to print maybe something to do with the mod result being 0? ''' "true branch" ELSE ''' i feel like we could mention that the number is odd? or something? ''' "false branch" END . END ``` ### Control-flow DSL currently has IF/ELIF/ELSE blocks and WHILE loops: ``` PROC MAIN IF get-some-number 0 == DO "the number is zero" . ELIF get-some-number 1 == DO "the number is one" . ELIF get-some-number 2 == DO "the number is two" . ELSE "this number has yet to be discovered by science" . END END ``` ### Special characters Most characters typically thought-of as 'special' have no special syntactic meaning in DSL. Some exceptions include: * Sequences of characters that would be parsed as data literals * Double-quotes, which start and end string literals * Three single-quotes in a row, which start and end comment blocks * Other special character sequences already reserved as intrinsic / proc names ``` ''' these are okay ''' PROC foo "this proc has a valid name" . END PROC +foo- "this proc has a valid name" . END PROC +fo8o- "this proc has a valid name" . END PROC $(*^$%*&#$%#]} "this proc has a valid name" . END ''' these aren't ''' PROC true "this is a parser error" . END PROC 123 "this is a parser error" . END PROC "foo" "this is a parser error" . END PROC "foo "this is a parser error" . END PROC '''foo''' "this is a parser error" . END ```