EHTML

From Esolang
Jump to navigation Jump to search
EHTML
Paradigm(s) imperative
Designed by User:CadenC
Appeared in 2024
Computational class Unknown
Major implementations Interpreter in JavaScript
File extension(s) .ehtml

EHTML is a programming language created by User:CadenC that is very syntactically similar to HTML. It was created because HTML is not a programming language, despite what people unfamiliar with programming languages might think.

Language overview

The language's statements are comprised of function calls. Variables can contain a string, number, boolean, function, or list. Variables are used to write the tag for the variable. To call a function stored in a variable, a beginning and end tag must be written with the parameters passed between them. A more detailed description of the language can be found on EHTML's website.

Types

EHTML has six different types: Strings, Numbers, Booleans, Functions, Lists, and Types. A string is a sequence of characters.

String

A string is made by surrounding the message to encode in quotes. Other values can be converted to a string by surrounding it with opening and closing <string> tags. The <to-uppercase> and <to-lowercase> functions can be used to convert all of the characters in a string that are letters to uppercase or lowercase. There are a few functions that test the value of a string. <is-number> returns true if the string can be converted to a number and returns false otherwise. <is-numeric> returns true if all of the characters in the string are numbers and returns false otherwise. <is-letters> returns true if all of the characters in a string are in the alphabet and false otherwise. <is-alphanumeric> returns true if all of the characters in a string are in the alphabet or are a number. Otherwise, it returns false. <is-whitespace> returns true if all of the characters in a string are whitespace and false otherwise. <is-uppercase> and <is-lowercase> return true if all of the characters in a string are uppercase or lowercase respectively and false otherwise.

Number

A number type holds a number with or without a decimal point and can be negative. To convert another type into a number one, surround it with opening and closing <number> tags. The <round> function takes in a number and returns the value rounded to the nearest integer. If it is halfway between two integers, it will round to the integer greater than it. The <floor> function takes in a number and returns the value rounded down to the nearest integer. The <ceil> function takes in a number and returns the value rounded up to the nearest integer. The <trunc> function takes in a number and returns the value as an integer, ignoring the numbers after the decimal place.

Boolean

A boolean is a value that can either hold true or false. Numbers can be converted to a boolean by surrounding it with opening and closing <boolean> tags. If the number is 0, the result is false. Any other number results in true.

Function

A function is a set of functions that can be called multiple times and optionally returns up to one value. When a function is created, the creator decides how many parameters it will take in. The print function takes in a string, prints the string, and then automatically prints a new line. To change the end value, a second string can be passed in to replace the new line.

List

A list is a group of values- similar to a string but able to take in any type of value. In order to create a list, call the <list> function and pass in as many values needed. A value can be added to the end of a list by passing in the list and the new value to the <push> function. The <pop> function removes the last value of the list and returns it.

Lists and strings

A lot of functions work exclusively or uniquely on lists and strings because of their similarities. Each value in a list or string has an index. The first item's index is 0, the second is item's index is 1, and so on. The <length> function returns the length of a string or list. The <value-at> function takes in a list or string and an index, and returns the item at that index. The <set-at> function takes in a list or string, an index, and a new value, and sets the value at that index to the new value. The <slice> function takes in a beginning index and an optional end index. The function returns a new list or string containing the values from the beginning index to the end index. If the end index is excluded, it will just get all the values from the beginning index to the end.

Type

The <type-of> function takes in a value and returns its type. Types can also be directly made by typing String, Number, Boolean, List, Function, and Type.

Variables

In order to declare a variable, the <set> function can be used. Set takes in two parameters. The first is a tag that will represent the variable. The second is the value that the variable will hold.

Arithmetic

Arithmetic functions are used mainly on numbers to do math but also occasionally used on lists and strings. The <add>, <subtract>, <multiply>, <divide>, and <remainder> functions take in two values and return the expected result. Each arithmetic function, except for remainder, has a counterpart that takes in a variable and a second value, and automatically sets the variable to the new value. The names for the functions are <add-to>, <subtract-to>, <multiply-to>, and <divide-to>. <add> and <add-to> can also be used to combine strings and arrays.

Comparison

Comparison functions can be used to compare two values and return a boolean value. <less> and <greater> are used to compare two numbers. The respectively represent the math < and > symbols.<equal> and <not-equal> test for equivalence of numbers, booleans, strings, and types. <and>, <or>, and <not> are functions that only take in booleans. And takes in two boolean values and returns true if both values are true. Or takes in two boolean values and returns true if one or both values are true. Not takes in one boolean value and inverts it. If true is passed in, it returns false. If false is passed in, it returns true.

Custom functions

In order to declare a function, the <set> function can be used. Set takes in two parameters. The first is a tag that will represent the variable. The second is the value that the variable will hold. For a function, the second parameter will be the <function> function. Other than set commands, statements can only be written in the function function. The <return> function can only be used inside the function function. It takes the value to return from the function and also stops the rest of the statements in the function from being called. The <params> function also can only be used inside the function function. It is used to decide the total amount of parameters that the function will accept and automatically assigns their values to the variable names chosen.

User input

To make an interactive program, the <input> function can be used. Input will pause the program and wait until the user is done entering info. Once the user hits enter, input will return the value entered, and the program will resume.

If statements

The <if> function takes in a boolean and one to two functions. The first function will only run if the boolean is true. If a second function is passed through and the boolean is false, that second function will run. Variables that hold a function can be passed in places where the function function is called.

Loops

In EHTML, there are two types of loops: <while> loops and <for-each> loops.

While

While loops take in two functions. The first function is called each time before each iteration, and should return a boolean. If the boolean is true the second function will run and the process will repeat. Otherwise if the boolean is false, the cycle will break and the second function will not run.

For-each

For-each function has two variants: <for-each> and <enum-for-each>. For both functions, the first value passed in is a string or an array. The second parameter for the regular for-each function is a function that takes in one parameter that will hold the current item's value. The loop will run for each item in the list or character in the string. The <enum-for-each> function is very similar to the <for-each> function. The only difference is that the function that loops takes in two parameters rather than one. The first parameter is still the item that the loop takes in. The second parameter is the index of that item.

Examples

Hello, world!

<set>
    <main>
    <function>
        <print>"Hello, World!"</print>
    </function>
</set>

FizzBuzz

<set>
    <main>
    <function>
        <set>
            <i>
            1
        </set>

        <while>
            <function>
                <return> <less>
                    <i>
                    101
                </less> </return>
            </function>

            <function>
                <set>
                    <result>
                    ""
                </set>

                <if>
                    <equal>
                        <remainder>
                            <i>
                            3
                        </remainder>
                        0
                    </equal>
                    <function>
                        <add-to>
                            <result>
                            "Fizz"
                        </add-to>
                    </function>
                </if>

                <if>
                    <equal>
                        <remainder> <i> 5 </remainder>
                        0
                    </equal>
                    <function>
                        <add-to>
                            <result>
                            "Buzz"
                        </add-to>
                    </function>
                </if>

                <if>
                    <equal>
                        <result>
                        ""
                    </equal>
                    <function> <print> <i> </print> </function>
                    <function> <print> <result> </print> </function>
                </if>

                <add-to>
                    <i>
                    1
                </add-to>
            </function>
        </while>
    </function>
</set>