Skip to content
Evan Marcey edited this page Jun 6, 2018 · 8 revisions

Table of Contents

  1. Variables

  2. Expression Evaluation

  3. Control-Flow Expressions

    3.1 If-Else Logic

    3.2 For Loops

    3.3 While Loops

  4. Functions

  5. Printing

Variables

Variables must be declared with an accepted type in the following format:

Declare variable {type}
// or
Declare variable {type} = {expression}

which is translated into SunnyLang as:

JoinTheGang variable {type}
// or
JoinTheGang variable {type} MilkSteak {expression}

The current acceptable types are:

SunnyLang Name Type
Dennis Int
Mac float
Dee boolean
Charlie string

Notes:

  • boolean variables are much the same as in C, where True = 1 and False = 0.
    • As such, boolean variables can be used in any mathematical expression

Expression Evaluation

The evaluator expects an infix expression and evaluates as such.

Order of operations is much the same as in a math class, except that some additional handling is invoked so that equality signs can be used. Equality signs evaluate the entire left-hand side of an expression (up to a '('), store the result of the left-hand side, then continue evaluating the entirety of the right-hand side (up to a ')') before comparing the results.

Numeric variables (int, boolean, numeric) can be operated on using any of the existing operations.

String variables can be added together or compared.

In addition, a string variable can be multiplied by a numeric variable to duplicate it (i.e. "test" * 2 -> "testtest")

Below, I've included a list of all operators acceptable in SunnyLang:

Term SunnyLang Equivalent
+ BrownOut
- CoverYourKneesIfYou'reGonnaBeWalkingAroundHere
* Let'sHuffSomeGlue
/ GoToeToToeOnBirdLawAndSeeWhatHappens
^ StrapOnMyJobHelmetAndSqueezeDownIntoAJobCannonAndFireOffIntoJobLand
% PayTheTrollToll
( BlastMe
) InTheAss
> WadOfHundreds
< MagnumCondoms
== ReadyToPlow
>= WadOfHundredsReadyToPlow
<= MagnumCondomsReadyToPlow
and LiamMcPoyle
or RyanMcPoyle
+= LittleGreenGhouls
-= YourFinestJellyBeans
/= BoiledJeans
*= RatStick
%= GreenMan
^= KittenMittons
++ AnEggInThisTryingTime
-- FightMilk

Known-Issues:

There is a bug in the infix evaluation algorithm which causes the interpreter to fail if equality operators (i.e. ==) or and/or operators are used in complex expressions without parentheses.

  • Working: 1 == 2
  • Working: (1 + 2) == 2
  • Not Working: 1 + 2 == 2

Control-Flow Expressions

SunnyLang only uses for whitespace to tokenize commands. So there aren't any tabs, and we don't surround code with brackets. Instead, every expression will have a Begin and an End statement that create and terminate the control-flow logic, respectively.

If-Else Logic

If-Else statements operate much the same as in any other language, if an expression is evaluated as True, then the code under it is executed. Otherwise, we jump to the next statement that evaluates as true. There are two important syntactical pieces to note. 1. Since Boolean variables are 1/0, if an expression evaluates to anything other than a 1 or a 0, the If statement will error out at runtime. 2. An If-Else statement must begin with an 'If' statement and end with an 'EndIf' statement, but the Else If and Else statements are optional.

The commands for an if/else statement are as follows:

SunnyLangName Translation
Dayman If
MasterOfTheNightman Else If
ChampionOfTheSun Else
MasterOfKarateAndFriendshipForEveryone EndIf

And so, the syntax will be as follows:

Dayman {expression}
{additional code to execute if statement evaluates to 1}
MasterOfTheNightman {expression}
{additional code to execute if statement evaluates to 1}
ChampionOfTheSun
{additional code to execute if no Dayman or MasterOfTheNightman statement evaluated to 1}
MasterOfKarateAndFriendshipForEveryone

For Loops

For Loops, again, are similar to most languages, with the exception that loops will be operated using a ForBegin and ForEnd. In addition, the for loop will receive as input the name of the variable to be used, the start value, the inequality to use, the end value and the interval over which to iterate. The interval value can be either positive or negative, and does not need to be an integer.

If a variable is already declared, the for loop expects only the name of the variable. If it has not been declared, then it will search for a supplied data type. If this is not provided, the interpreter will assume that the new variable is an integer.

The for loop uses the following commands:

SunnyLangName Translation
Rickety ForBegin
Cricket ForEnd

And so the syntax will be as follows:

Rickety {variable} {begin value} {inequality} {end value} {interval}
{code to execute}
Cricket
//or
Rickety {variable} {variable_type} {begin value} {inequality} {end value} {interval}
{code to execute}
Cricket

While Loops

While loop syntax is similar to for loop syntax, except that:

  1. Any variable used in the evaluation expression must exist prior to the WhileBegin call.
  2. Like all while loops, any iteration must be performed within the body of the While statement (i.e. there is no interval)

As long as the expression in the while loop evaluates to 1, the code within the loop will be executed. If the expression evaluates to 0, the code will be skipped, and if the loop evalutes to any other value, an error will be thrown.

The while loop uses the following commands:

SunnyLangName Translation
Pepe WhileBegin
Sylvia WhileEnd

And the syntax will be as follows:

Pepe {expression}
{code}
Sylvia

Functions

Currently functions in SunnyLang can accept any number of arguments, and return a single value - multiple values to be implemented later

However, SunnyLang remembers variables declared in the global environment, so these variables can be used without passing, and therefore the values can be maintained. If you do override the value of an existing global variable, SunnyLang will create a temporary version of the variable within the function, which will be discarded after the function completes.

Function calls use the following commands:

SunnyLangName Translation
FunctionBegin TheBirdsOfWar
FunctionEnd TheTrashman
Return TheTalibum
void Frank

and the syntax is as follows:

TheBirdsOfWar Frank {nameOfFunction} {variable1} {datatype1} {variable2} {datatype2} ...
{code to execute}
TheTrashman 

or

TheBirdsOfWar {return datatype} {nameOfFunction} {variable1} {datatype1} {variable2} {datatype2} ...
{code to execute}
TheTalibum {return datatype}
TheTrashman 

Printing

Printing out a response in SunnyLang is relatively simple. It can be done either with a line of code that is purely an expression (including variables), or by a line that has the print function, followed by an expression.

SunnyLangName Translation
Print BangTheWaitress

Here's a quick example of two ways to print something.

1 BrownOut 2
--- or ---
BangTheWaitress 1 BrownOut 2

Either of these return 3 (the result of 1+2).

Note:

I plan to add more to the print function, like the use of variables, in the future.