-
Notifications
You must be signed in to change notification settings - Fork 0
Design & Language Reference Breakdown
Lexi edited this page Nov 6, 2024
·
7 revisions
The various elements such as data types, variables, identifiers, and their declarations that play a role in the structure and semantics
| Non-Terminal | Definition | Explanation | Symbol Example | Keyword Example |
|---|---|---|---|---|
<data_type> |
"spud", "tater", "chip", "sack" | Represents data types |
spud, tater, chip, sack spud, sack sack spud
|
|
<variable> |
A named storage location that holds a value or data | |||
<identifier> |
A name used to uniquely identify a user-defined item | |||
<variable_declaration> |
Specifying the type and name of a variable, can also assign a value |
spud intVal = 4, tater bin, tater bin = true, chip str, chip str = "this is a string", sack spud arr[], sack spud arr[4] = {0,1,2,3}
|
<data_type> ::= "spud" // Integer
| "tater" // Boolean
| "chipper" // String
| "sack" <data_type> // Array of a specific data type
<variable> ::= <identifier>
<identifier> ::= <characters> { <characters> | <digits> | "_" }*
<digits> ::= <digit> { <digit> }*
<digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<characters> ::= <upper-case-character> | <lower-case-character> { <upper-case-character> | <lower-case-character> }*
<upper-case-character> ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
<lower-case-character> ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
<variable_declaration> ::= <data_type> <variable>
| <data_type> <variable> "=" <term>
| "sack" <data_type> <variable> "=" "[" { <expression> { "," <expression> }* }? "]"
Left here for further bnf language development
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<array_access> |
Allows both reading and assigning values to specific indexes | numbers[5] |
||
<array_length> |
A way to get the length of an array | numbers.length |
||
<array_append> |
Appending to an array | numbers.plant(6) // Add 6 to the array |
||
<array_remove> |
Removing a specific index of an array | numbers.peel(2) // Remove the element at index 2 |
<array_access> ::= <variable> "[" <expression> "]"
<array_length> ::= <variable> "." "length"
<array_append> ::= <variable> "." "plant" "(" <expression> ")"
<array_remove> ::= <variable> "." "peel" "(" <expression> ")"
| Non-Terminal | Definition | Explanation | Symbol Example | Keyword Example |
|---|---|---|---|---|
<literal> |
A constant value directly specified in the code | |||
<integer_literal> |
Represents integers | spud x = 42 |
spud x plant 42 |
|
<floating_point_literal> |
Represents floating-point numbers | spud y = 3.14 |
spud y plant 3.14 |
|
<boolean_literal> |
Represents boolean values. | tater flag = true |
tater flag plant true |
|
<string_literal> |
Represents strings enclosed in quotes. | chip greeting = "Hello, world!" |
chip greeting plant "Hello, world!" |
<literal> ::= <integer_literal>
| <boolean_literal>
| <string_literal>
<integer_literal> ::= <digits>
<floating_point_literal> ::= <digits> "." <digits>
<boolean_literal> ::= "true" | "false"
<string_literal> ::= """ { <characters> }* """
Any valid expression including arithmetic, logical, comparison, or assignment expressions.
| Non-Terminal | Definition | Explanation | Symbol Example | Keyword Example |
|---|---|---|---|---|
<arithmetic_expression> |
Performs mathematical operations on numbers | |||
<logical_expression> |
Evaluates boolean values and uses logical operators | |||
<relational_expression> |
Compares two values and returns a boolean result based on relational operators | |||
<term> |
Represents a basic unit of an arithmetic expression, such as a number, variable, or more complex expression |
5, x, (a+b)
|
||
<primary> |
Refers to the simplest, indivisible components of expressions |
3, x, sqrt(16), (3 + x)
|
||
<factor> |
Extends the concept of primary by including the application of unary operators |
3, x, sqrt(16), (3 + x), - (3 + x)
|
<expression> ::= <arithmetic_expression>
| <logical_expression>
| <relational_expression>
<term> ::= <factor> { <arithmetic_operator> <factor> }*
<primary> ::= <literal>
| <variable>
| "(" <expression> ")"
| <function_call>
<factor> ::= <primary>
| <unary_operator> <factor>
<unary_operator> ::= "+" | "-" | "abs" | "sqrt"
| Non-Terminal | Definition | Explanation | Symbol Example | Keyword Example |
|---|---|---|---|---|
<addition_operator> |
"+" or "mash" | Represents addition | x + 1 |
x mash 1 |
<subtraction_operator> |
"-" or "peel" | Represents subtraction | x - 1 |
x peel 1 |
<multiplication_operator> |
"*" or "fry" | Represents multiplication | x * 1 |
x fry 1 |
<division_operator> |
"/" or "slice" | Represents division | x / 1 |
x slice 1 |
<arithmetic_expression> ::= <term> { <arithmetic_operator> <term> }*
<arithmetic_operator> ::= <addition_operator>
| <subtraction_operator>
| <multiplication_operator>
| <division_operator>
<addition_operator> ::= "+" | "mash"
<subtraction_operator> ::= "-" | "peel"
<multiplication_operator> ::= "*" | "fry"
<division_operator> ::= "/" | "slice"
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<and_operator> |
"&&" or "prep" | Evaluates to true if both A and B are true. If either A or B is false, the result is false | x == 10 && y == 20 |
x planted 10 prep y planted 20 |
<or_operator> |
"\" or "mix" | Evaluates to true if either A or B is true. If both are false, the result is false | x == 10 \\ x == 20 |
x planted 10 mix x planted 20 |
<not_operator> |
"!" or "raw" | Inverts the boolean value | !x |
raw x |
<nor_operator> |
"~\" or "spudStop" | Evaluates to true if both A and B are false; if either is true, the result is false. | x == 0 ~\\ y == 0 |
x planted 0 spudStop y planted 0 |
<xor_operator> |
"+\" or "eitherSpud" | Evaluates to true if A and B are different (one true, one false); otherwise, the result is false. | x > 10 +\\ y < 5 |
x biggerSpud 10 eitherSpud y smallerSpud 5 |
<nand_operator> |
"~&" or "mashless" | Evaluates to true if either A or B is false; if both are true, the result is false. | x == 5 ~& y == 6 |
x planted 5 mashless y planted 6 |
<logical_expression> ::= <relational_expression> { <logical_operator> <relational_expression> }**
<logical_operator> ::= <and_operator>
| <or_operator>
| <not_operator>
| <nor_operator>
| <xor_operator>
| <nand_operator>
<and_operator> ::= "&&" | "prep"
<or_operator> ::= "\\" | "mix"
<not_operator> ::= "!" | "raw"
<nor_operator> ::= "~\\" | "spudStop"
<xor_operator> ::= "+\\" | "eitherSpud"
<nand_operator> ::= "~&" | "mashless"
| Non-Terminal | Definition | Explanation | Symbol Example | Keyword Example |
|---|---|---|---|---|
<assignment_expression> |
Assigns a value to a variable. Simple assignments or assignments combined with arithmetic operations. | |||
<assignment_operator> |
"=" or "plant" | Assigns a value to a variable | x = 1 |
x plant 1 |
<addition_assignment_operator> |
"+=" or "mashed" | Addition and assignment | x += 1 |
x mashed 1 |
<subtraction_assignment_operator> |
"-=" or "peeled" | Subtraction and assignment | x -= 1 |
x peeled 1 |
<multiplication_assignment_operator> |
"*-" or "fried" | Multiplication and assignment | x * 1 |
x fried 1 |
<division_assignment_operator> |
"/=" or "sliced" | Division and assignment | x /= 1 |
x sliced 1 |
<assignment_expression> ::= <variable> <assignment_operator> { <variable> | <digit> | <expression> }
<assignment_operator> ::= "=" | "plant"
| <addition-assignment-operator>
| <subtraction-assignment-operator>
| <multiplication-assignment-operator>
| <division-assignment-operator>
<addition_assignment_operator> ::= "+=" | "mashed"
<subtraction_assignment_operator> ::= "-=" | "peeled"
<multiplication_assignment_operator> ::= "*=" | "fried"
<division_assignment_operator> ::= "/=" | "sliced"
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<equal_to_operator> |
"==" or "spudMatch" | Checks if A is equal to B. | x == 10 |
x spudMatch 10 |
<not_equal_to_operator> |
"!=" or "mashApart" | Checks if A is not equal to B. | x != y |
x mashApart y |
<less_than_operator> |
"<" or "smallerSpud" | Checks if A is less than B. | x < 10 |
x smallerSpud 10 |
<greater_than_operator> |
">" or "biggerSpud" | Checks if A is greater than B. | x > 10 |
x biggerSpud 10 |
<less_than_or_equal_to_operator> |
"<=" or "notBiggerSpud" | Checks if A less than or equal to B. | x <= 10 |
x notBiggerSpud 10 |
<greater_than_or_equal_to_operator> |
">=" or "notSmallerSpud" | Checks if A greater than or equal to B. | x >= 10 |
x notSmallerSpud 10 |
<relational_expression> ::= <expression> <relational_operator> <expression>
<relational_operator> ::= <equal_to_operator>
| <not_equal_to_operator>
| <less_than_operator>
| <greater_than_operator>
| <less_than_or_equal_to_operator>
| <greater_than_or_equal_to_operator>
<equal_to_operator> ::= "==" | "spudMatch"
<not_equal_to_operator> ::= "!=" | "mashApart"
<less_than_operator> ::= "<" | "smallerSpud"
<greater_than_operator> ::= ">" | "biggerSpud"
<less_than_or_equal_to_operator> ::= "<=" | "notBiggerSpud"
<greater_than_or_equal_to_operator> ::= ">=" | "notSmallerSpud"
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<if_statement> |
"bake" | Executes if evaluates to true. | Code Sample | |
if_elif_statement> |
"bake" "else bake" | Executes the first if the first is true; otherwise, checks subsequent elif conditions. | Code Sample | |
<if_else_statement> |
"bake" "else" | Executes if is true; otherwise, executes the else block. | Code Sample |
<if_statement> ::= "bake (" <condition> ")" "{" { <statement> }* "}"
{ "else bake (" <condition> ")" "{" { <statement> }* "}" }*
[ "else" "{" { <statement> }* "}" ]
| <condition> ? {<expression> | <function_call>} : {<expression> | <function_call>}
<condition> ::= <relational_expression>
bake (x == 10) {
bite " X is worth 10 potatoes "
}
bake (x == 10) {
bite " X is worth 10 potatoes "
} else bake (x == 20) {
bite " You have doubled our potatoes worth! "
}
bake (x == 10) {
bite " X is worth 10 potatoes "
} else bake (x == 20) {
bite " You have doubled our potatoes worth! "
} else {
bite " You know what a potato is, right? "
}
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<bounded_loop> |
"season" | Executes repeatedly while is true, initializing and incrementing as specified. | Code Sample | |
<unbounded_loop> |
"fryAsLongAs" | Repeatedly executes until becomes true. | Code Sample | |
<do_while_loop> |
"do" "fryAsLongAs" | Executes at least once, then repeats while is true. | Code Sample |
<bounded_loop> ::= "season (" [ <data_type> ] <assignment_expression> ";" <condition> ";" <assignment_expression> ")"
"{" { <statement> }* "}"
<unbounded_loop> ::= "fryAsLongAs (" <condition> ")"
"{" { <statement> }* "}"
<do_while_loop> ::= "do"
"{" { <statement> }* "}"
"fryAsLongAs (" <condition> ")"
season ( spud x = 10 ; x >= 0 ; x = x - 1) {
bite " Potato #" x
}
spud x = 10
fryAsLongAs ( x >= 0) {
bite " Potato #" x
x = x - 1
}
spud x = 10
do {
bite " Potato #" x
x = x - 1
} fryAsLongAs ( x >= 0)
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<return-statement |
"serve" or ":<=" | Exits a function and optionally returns a value to the calling code | :<= |
serve, serve false
|
<return-statement> ::= ":<=" [ <expression> ] | "serve" [ <expression> ]
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<input_statement> |
"unearth" | unearth x |
||
<output_statement> |
"bite" |
bite "%s is starchy", str, bite x " is starchy"
|
||
reference |
"%" | format specifier |
%s, %i, %f
|
<input_statement> ::= "unearth" <variable>
<output_statement> ::= "bite" "\"" { <characters> | <digits> | <reference> | <escape_sequence> }* "\""
[ { "," <characters> | <digits> | <reference> | <escape_sequence> }* ]
| "bite" "'" { <characters> | <digits> | <escape_sequence> }* "'" ) [ { "," <variable> }* ]
| "bite" <escape_sequence>
<reference> ::= "%" <shorthand_data_type>
<shorthand_data_type> ::= "i" | "s" | "f" | "c" | "b" | "a"
<escape_sequence> ::= <newline> | "\t" | "\\"
<newline> ::= "endl" | "\n"
The bite keyword is used for output, and there are two forms of output:
- String-based output: Double quotes (
") surround a mixture of characters, digits, and references (%followed by a shorthand data type). It also supports variables via commas. - Character-based output: Single quotes (
') enclose characters or digits, allowing interpolation of variables between single quotes.
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|
<function> |
"crisp" | Defines a function with optional return type, name, parameters, and body. | Code Sample | |
<function_call> |
Represents a call to a function with optional arguments. | |||
<parameter> |
Defines a list of parameters for a function. | |||
<comment> |
" | " or " | [" and "] |
<program> ::= <program> ::= { <function_definition> }* <main_function> { <function> }*
<main_function> ::= "[ <data_type> ] "mainCrisp" "(" <parameter> ")" "{"
{ <statement> ";" }*
"}"
<function> ::= crisp [ <data_type> ] <variable> "(" <parameter> ") {"
{ <statement> ";" }*
"}"
<function_definition> ::= [ <data_type> ] <variable> "(" <parameter> ")
<fuction_call> ::= <variable> "(" [ <parameter> ] ")"
<parameter> ::= [ <variable_declaration> { "," <variable_declaration> }* ]
<comment> ::= <single_line_comment> | <multi_line_comment>
<single_line_comment> ::= "||"
<multi_line_comment> ::= "|[" { <characters> | <digits> }* "]|"
<statement> ::= <print_statement>
| <input_statement>
| <assignment_statement>
| <if_statement>
| <loop_statement>
| <return_statement>
<error_handling> ::= "burnt" "(" <expression> ")" | "catchFire" "(" <expression> ")" { <statement> }*
crisp spud mashPotato (spud x, spud y) {
serve x mash y
}
crisp mainCrisp () {
spud x, y
bite 'Give me two numbers, and press enter after each input: '
unearth x
unearth y
spud z = mashPotato (x,y)
bite "%s was the sum", z
}
Left here for further bnf language development
| Non-Terminal | Definition | Explanation | Symbol Syntax | Keyword Syntax |
|---|---|---|---|---|