JavaScript - EBNF and Railroad

 

Home

 

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>};   

 

Machine generated alternative text:
va r 
va r 
va r 
3.14 
— "John Doe"; 
person 
— 'Yes I am!' ; 
answer

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:

Machine generated alternative text:
Nol 
d—t. getEl

 

Identifier                                                    (Identifiers are Variable names)

Machine generated alternative text:

letter 
letter 
( digit

 

Concatenation:

See above for digit, character, special character & identifier

Text block = " <string> "

Final statement =  [<Text block> ]  [+ {<identifier> | <Text block>}]

 

Example below:

Machine generated alternative text:

 

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 Operators 
Assignment operators assign values to JavaScript variables. 
Operator 
Example 
Same As 
x 
x 
x 
x 
x 
x 
x 
x 
x 
x

 

JavaScript Assignment

https://www.w3schools.com/js/js_assignment.asp

Screen clipping taken: 8/10/2019 2:19 PM

 

 

Machine generated alternative text:

 

Machine generated alternative text:
swapped = false; 
cycle = 
cycle + I 
txtPasses = txtPasses 
"Cycle 
cycle

 

Machine generated alternative text:
var x

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)

 

Machine generated alternative text:

 

Statement - block of code to be executed

Machine generated alternative text:
e ßlNT

 

 

 

"IF" statement: 

 

 

Machine generated alternative text:
new Date() . getHours() 
var time 
if (time < 10) { 
greeting 
"Good morning" 
} else if (time < 20) { 
greeting 
} else { 
greeting 
"Good day" 
"Good evening

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

N 人 X ^ C ↓ 0 日 0 Z 1 ) 「 
く P 「 い C95 代 
′ ・ つ 物 当 っ ー 物 ・ つ ・ J 
ノ つ テ つ ′ つ 
X 9 ョ ョ 0 つ 日 > 
4 ! 6 ℃

 

 

JavaScript (JS)

String:

Machine generated alternative text:

 

Declaration of variables:

Data Types - although there are six types, we will mainly need 3:

Machine generated alternative text:

Data type

 

DimStatement=

Machine generated alternative text:
0

 

Concatenation:

Machine generated alternative text:

 

Machine generated alternative text:

 

Message (print to screen) statements:

Machine generated alternative text:

Assignment:

See any of these

Machine generated alternative text:

 

Machine generated alternative text:

 

var x

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)

 

Machine generated alternative text:

 

Statement - block of code to be executed

Machine generated alternative text:
e ßlNT

 

 

 

 

"IF" statement: