Asig

From Esolang
Jump to navigation Jump to search

Asig was created by Adam on March 30, 2014. The language uses symbol characters to complete commands. It can be used to complete simple (or possibly complex) commands and make completely useless programs. The language was based on basic Java operations and commands.

Syntax

In order to make commands, use the specified symbol to carry out commands/initiate commands, which are followed by letters or numbers to complete commands.

The symbol part of the language is composed of the following characters:

`~!@#$%^&*()-_=+[]{};:'"\|,<.>/?*

Use the ~ character to start a new command, following that, write the rest of the command within a {}.

The following Extended Backus-Naur Form (EBNF) description applies to the language:

program                 := { command } ;
command                 := "~" , "{", commandBody , "}" ;
commandBody             := numericVariableCreation
                        |  mathematicalOperation
                        |  stringVariableCreation
                        |  print
                        |  input
                        |  test ;

numericVariableCreation := numericVariable ;
mathematicalOperation   := "&" , ":" , numericVariable , "#",
                           ( "+" | "-" | "*" | "/" ) ,
                           ( number | numericVariable ) ;
stringVariableCreation  := stringVariable , string ;
print                   := "|" , anyVariable ;
input                   := "^" , "(" , ( "#" | "@" ) , ")" ,
                           anyVariable ;
test                    := testPart , { conditionalPart } ;
testPart                := "^" , ":" ,
                           anyVariable ,
                           ( "=" | ">" | "<" ) ,
                           ( number | anyVariable ) ;
conditionalPart         := "\" , command ;

anyVariable             := numericVariable | stringVariable ;
numericVariable         := "%" , identifier ;
stringVariable          := "@" , identifier ;

number                  := [ "+" | "-" ] , digit, { digit } ,
                           [ "." , { digit } ] ;
string                  := "[" , { character } , "]" ;
identifier              := letter , { letter | digit | underscore } ;

underscore              := "_" ;
letter                  := "a" | ... | "z" | "A" | ... | "Z" ;
digit                   := "0" | "1" | "2" | "3" | "4"
                        |  "5" | "6" | "7" | "8" | "9" ;

Commands

Asig's capabilities embrace the definition of variables, basic arithmetic, input/output facilities, and a simple conditional construct.

Numeric variable creation

A numeric variable can be declared using the % syntax:

%variableName

The variableName must be the name of the numeric variable to create.

Mathematical operations

A mathematical operation is initiated using the marker &::

&:%leftOperandVariable#operator rightOperand

The leftOperandVariable designates the left operand to introduce in the operation and must be the name of a numeric variable which will be modified to contain the operation result.

The operator constitutes the symbolic name of an arithmetic operation and must be one of these:

Operand Meaning
+ Addition
- Subtraction
* Multiplication
/ Division

The rightOperand must be a literal number or a numeric variable's name, introduced via % and utilized as the right operand of the operation.

String variable creation

A string variable, or simply string, can be defined using the @ syntax:

@stringName[characters]

The stringName must be the name of the string variable to create.

The characters must be a sequence of zero or more characters, distinguished from the right bracket ], to be stored in the string variable.

Output

The print command is introduced using the symbol |:

|variableName

The variableName must be the name of a numeric or string variable, in the former case prefixed with %, in the latter with @.

Input

User input can be queried using ^():

^(inputType)variableName

The inputType conveys the data type expected from the user prompt, with two options valid:

Input type Meaning
# A number is expected to be supplied by the user.
@ A string is expected to be supplied by the user.

The variableName designates the name of the variable to receive the user input. If the inputType prescribes a numeric object, the variableName must be prefixed with %, whereas a string input conditions the prefixing of the variableName with @.

Test

A conditional, or if, test with a then part, but no else contingency, is committed by aide of the ^: construct:

^:testVariableName relation expectedValue \ statement_1 \ … \ statement_N

The testVariableName designates the name of the variable to test; a numeric variable must be prefixed with % and a string variable with @.

The relation describes the comparison operator and may assume one of the following guises:

Operator Meaning
= The testVariable must equal the expectedValue. Strings are compared in a case-sensitive manner.
< The testVariable must be strictly less than the expectedValue. Strings are compared in a case-sensitive manner.
> The testVariable must be strictly greater than the expectedValue. Strings are compared in a case-sensitive manner.

The expectedValue must be either a literal number or a variable. If a numeric variable, it must be preceded by %, if a string, an @ must be prepended instead.

The section composed of statement_1 through statement_N encompasses a series of zero or more commands to execute if the predicated relation is satisfied. Each statement is preceded by a backslash \; if such a character is present, a statement must be prepended. Any further command is introduced in the exact same manner.

Examples

Addition and output

To create a variable and call it 'Joe', then add 2 to it, then print it out, do the following.

~{%Joe}
~{&:%Joe#+2}
~{|%Joe}

This would print out 2.

Hello, world!

The following program prints “Hello, World!” to the standard output:

~{@greeting [Hello, World!]}
~{|@greeting}

Cat program

A one-time cat program constitutes the following:

~{@input[]}
~{^(@)@input}
~{|@input}

Number sign check

The following program expects a real number from the user and prints, depending on the input value's sign, an appropriate message.

~{@promptText      [Please input a number: ]}
~{@messagePositive [Your input number was positive.]}
~{@messageZero     [Your input number was zero.]}
~{@messageNegative [Your input number was negative.]}

~{|%promptText}
~{%input}
~{^(#)%input}

~{^:%input > 0 \ ~{|@messagePositive}}
~{^:%input = 0 \ ~{|@messageZero}}
~{^:%input < 0 \ ~{|@messageNegative}}

Interpreter

  • Common Lisp implementation of the Asig programming language.