Do-if

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Do-if is an esolang created by User:Martsadas which uses do-if and do-while

Syntax

The following Extended Backus-Naur Form (EBNF) decription applies to the language's syntaxis:

program            := statementList ;
statementList      := { statement } ;
statement          := letStatement | printStatement | doIfStatement | doWhileStatement ;
letStatement       := "let" , variableName , "=" , expression ;
printStatement     := "PRINT" , "{" , printArguments , "}" ;
printArguments     := [ expression , { "," , expression } ] ;
doIfStatement      := doStatements , "if"    , expression ;
doWhileStatement   := doStatements , "while" , expression ;
doStatements       := "do" , statementList ;
expression         := integerLiteral | stringLiteral | variableName | binaryExpression | relationExpression | input ;
input              := "INPN" , "{" , "}" ;
binaryExpression   := expression , binaryOperator , expression ;
binaryOperator     := "+" | "-" | "*" | "/" ;
relationExpression := expression , relationOperator , expression;
relationOperator   := "=" | "<" | ">" ;
stringLiteral      := doubleQuotedString | singleQuotedString ;
doubleQuotedString := '"' , { ( character - '"' ) | escapeSequence } , '"' ;
singleQuotedString := "'" ,  { ( character - "'" ) | escapeSequence } , "'" ;
escapeSequence     := "\" , character ;
integerLiteral     := [ "+" | "-" ] , digit , { digit } ;
digit              := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;

Commands

The language provides five instructions:

Command Description
let variableName = value Assigns the value to the variable amenable to the variableName. If such a placeholder already exists, its content is overwritten; otherwise a new variable is declared and initialized.
do
  statements
while antecedent

Executes the statements as long as the antecedent is satisfied.
do
  statements
if antecedent

Executes the statements once if the antecedent is satisfied; otherwise omits the statements.
PRINT {arguments} Prints the arguments to the standard output. Each twissel of subsequent print arguments must be separated by exactly one comma (,). In the final output, no implicit content is inserted, the evaluated elements being concatenated directly, with no adscititious linebreak appendage. Escape characters may be introduced in order to accommodate particular necessities, which please consult below.
INPN {} Queries the standard input for a single signed or unsigned integer number and returns the same.

Escape Sequences

A set of escape sequences is homologated in any string for the accommodation of special requirements:

Escape sequence Effect
\n Inserts a newline character.
\t Inserts a horizontal tab.
\\ Inserts a backslash (\).
\character Inserts the character in its ipsissima verba form.

Examples

Hello, World!

This program displays the message “Hello, World!”:

PRINT {'Hello, World!\n'}

Iteration with Counter

The following program counts from zero (0) up to nine (9), in each cycle printing a message comprehending the current counter state:

let $X = 0
do
  PRINT {'Hello world ', $X, '!\n'}
  let $X = $X + 1
while $X < 10

Factorial

This program queries the standard input for an integer number n and computes its factorial n!:

let $N = INPN {}
let $X = $N
let $R = 1
do
  let $R = $R * $X
  let $X = $X - 1
while $X > 1
PRINT {$N, '! = ', $R}

Looping Counter

This looping counter iterates from inclusive one (1) to inclusive ten (10):

let $rowNumber     = 0
let $columnCounter = 0

do
  let $columnCounter = 1
  do
    PRINT {'*'}
    let $columnCounter = $columnCounter + 1
  while $columnCounter < $rowNumber + 1
  
  PRINT {'\n'}
  
  let $rowNumber = $rowNumber + 1
while $rowNumber < 11

Truth-Machine

A truth-machine is realized in the following:

PRINT {'Please input 0 or 1: '}
let $input = INPN {}
PRINT {$input}
do
  PRINT {$input}
while $input = 1

Interpreter

  • Common Lisp implementation of the Do-if programming language.