This time, I'll talk about programming languages and their elements with javascript.
I referenced it on this page.
Lexical grammar
All programming languages we use are included "context-free grammar". This rule has an important role in the compiler. It can be represented through the format called BNF. The BNF consists of tokens, and tokens have some different types.
Control characters
Control characters have no visual representation but are used to control the interpretation of the text. We'll never use it directly, so let's go over to next.
White space
White space characters improve the readability of source text and separate tokens from each other. These characters are usually unnecessary for the functionality of the code.
We generally use normal space(U+0020), but there are more characters than that. For example, Javascript has about 16 white space characters.
This capture shows some differences between the two JSON data. Sometimes, A difference invisible with the eyes may cause errors.
Line terminators
In addition to white space characters, line terminator characters are used to improve the readability of the source text. However, in some cases, line terminators can influence the execution of JavaScript code as there are a few places where they are forbidden.
Comments
Comments are used to add hints, notes, suggestions, or warnings to JavaScript code. This can make it easier to read and understand. They can also be used to disable code to prevent it from being executed.
Keywords
Keywords are specified words recognized as a token. For example, javascript has class, function, and others.
Literals
Literals are representations of value in the smallest unit. For example, javascript recognizes express of string through 3 types, double quote, single quote, and backtick. We can't represent more minor.
We've seen 6 types of tokens that consist of programming languages.
From now on, we'll see language elements that can make by these tokens.
Language elements
The basic language frame of javascript consists of expressions and statements as algol60 children.
Expressions
Expressions will be one value. Here, the value contains the default value as well as the reference value, such as the object. There are some examples.
Value Expression
3 //number ok!
'test' //string ok!
{a:3} //object ok!
undefined //undefined ok!
null //null ok!
JavaScript
Operators Expression
If operators are included, it will absolutely be a value, so finally it will be value expressions.
1+3 //4 ok!
5 > 3 // true ok!
JavaScript
Literal
{} // object literal
function(){} // function literal
[] // array literal
/abc/ // regex literal
JavaScript
Function call
The result called function is a value. In Java, returning a void can not be a value, but Javascript would be returned the undefined if you don't return value.
(function(){})() // undefined
JavaScript
Actually, All expressions exist by value expressions. All difference expressions are value expressions through converging one value, so you can also understand "expression == value"
Statements
The Statements are elements that changed command after by translate compiler.
Generally, It works executable minimum individual code blocks or commands to control flows.
Control Statements
Control Statements are commands to control the orders that execute code blocks.
Typically, there are the following:
if( expression ) statement;
if( expression ) statement1; else statement2;
switch( expression ){
case expression:
default:
}
for( expression ; expression ; expression ) statement;
while( expression ) statement;
do statement while( expression )
return;
return expression;
var identifier, identifier = expression,..
label:
break;
break label;
continue;
continue label;
JavaScript
Empty Statement
Empty Statement consists of only semi-colons and, It works nothing.
;;;;;
if(true);
JavaScript
Single Statement
Single Statement has one expression and semi-colons.
if( 3 ) 5;
x++;
a = b;
JavaScript
Compound Statement
Compound Statement includes { , } and variety of statement between {}.
if( a > 3 ) {
b = 5; // Single Statement
c = 8; // Single Statement
}; // Compound Statement
JavaScript
Expression Statement
All Expression also can be a statement.
3;
'aaa';
func();
{a:'test'};
3+5;
JavaScript
Runtime
We've looked at the expression and statement
These are interpreted by the compiler as a command and a value in the runtime.
The interpreted commands and values are separated and loaded in the memory. This process says the program is loading.
The command is sequentially executed by the CPU through the external bus.
Commands execute using a value through the register if necessary.
If there is no command to execute anymore, the program is terminated.
Diagram
Javascript runs like this. That's it.