JavaScript - EBNF and Railroad
EBNF
JavaScript - definitions
sign
"+" | "-"
letter
"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" | "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"
digit
"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
special character (including "space")
" " | "*" | "/" | "=" | "<" | ">" | "[" | "]" | "." | "," | "(" | ")" | ":" | "^" | "@" | "{" | "}" | "$" | "#" | "&" | "%"
string-character
any character or digit except quote | "''"
string
<string-character > { <string-character > }
Identifier (Identifiers are Variable names)
letter { letter | digit }
Declaration of variables:
integers float or real string
DataType = <Digit> {<Digit>} | <Digit> {<Digit>}.<Digit> {<Digit>} | <Character> {<Character>|<Digit>}
(no decimal point means Integer)
(decimal point means Float (Real) eg 0.0 or 1.5)
The six types are considered to be primitives. A primitive is not an object and has no methods of its own. All primitives are immutable.
· Boolean — true or false
· Null — no value
· Undefined — a declared variable but hasn’t been given a value
· Number — integers, floats, etc
· String — an array of characters i.e words
· Symbol — a unique value that's not equal to any other value
From <https://codeburst.io/javascript-essentials-types-data-structures-3ac039f9877b>
DimStatement = var <Identifier> = <DataType>{var <Identifier> = <DataType>};
JavaScript Variables
https://www.w3schools.com/js/js_variables.asp
Screen clipping taken: 8/10/2019 12:25 PM
Or if you want to read user inputs:
Identifier (Identifiers are Variable names)
Concatenation:
See above for digit, character, special character & identifier
Text block = " <string> "
Final statement = [<Text block> ] [+ {<identifier> | <Text block>}]
Message (print to screen) statements:
Message box = alert ( <final statement> )
Assignment:
<identifier> = <Text block> | <identifier> {<Text block> | <identifier>}] ;
or
<identifier> += <Text block> | <identifier> {<Text block> | <identifier>}] ;
Or any of these below:
JavaScript Assignment
https://www.w3schools.com/js/js_assignment.asp
Screen clipping taken: 8/10/2019 2:19 PM
JavaScript Assignment
https://www.w3schools.com/js/js_assignment.asp
Screen clipping taken: 8/10/2019 2:46 PM
Condition (evaluates to true or false):
(<identifier> ==|===|<|> <Text block> | <identifier> )
And you could have:
<condition> =(<condition> || <condition> AND <condition> )
( || means OR)
Statement - block of code to be executed
"IF" statement:
JavaScript if/else Statement
https://www.w3schools.com/jsref/jsref_if.asp
Screen clipping taken: 8/10/2019 2:59 PM
i. Railroad - definitions for all languages
JavaScript (JS)
String:
Declaration of variables:
Data Types - although there are six types, we will mainly need 3:
DimStatement=
Concatenation:
Message (print to screen) statements:
Assignment:
See any of these
JavaScript Assignment
https://www.w3schools.com/js/js_assignment.asp
Screen clipping taken: 8/10/2019 2:46 PM
Condition (evaluates to true or false):
(<identifier> ==|===|<|> <Text block> | <identifier> )
And you could have:
<condition> =(<condition> || <condition> AND <condition> )
( || means OR)
Statement - block of code to be executed
"IF" statement: