Monday, January 29, 2018

ECMA262_2017_ch5

5Notational Conventions

5.1Grammars

5.1.1Context-Free Grammars

A context-free grammar consists of a number of productions. Each production has an abstract symbol called a nonterminal as its left-hand side, and a sequence of zero or more nonterminal and terminal symbols as its right-hand side.

A chain production is a production that has exactly one nonterminal symbol on its right-hand side along with zero or more terminal symbols.

5.1.2The Lexical and RegExp Grammars

A lexical grammar defines a set of productions, starting from the goal symbol InputElementDiv, InputElementTemplateTail, or InputElementRegExp, or InputElementRegExpOrTemplateTail.

A example of InputElementRegExp can be /a_Pattern/flags , refer to A.8 for Pattern, the RegExp Grammars.

InputElementDiv can be spaces, comments, and so on.

An example of InputElementRegExpOrTemplateTail can be

`hello,${expr


  },it's funny, I like python's """multi_line_str"""`
 

In the example of InputElementRegExpOrTemplateTail, "}...`" is a InputElementTemplateTail, which terminates this goal symbol.

Input elements other than white space, line terminators, and comments form the terminal symbols for the syntactic grammar for ECMAScript and are called ECMAScript tokens.

A MultiLineComment is simply discarded if it contains no line terminator; but if a MultiLineComment contains one or more line terminators, then it is replaced by a single line terminator, which becomes part of the stream of input elements for the syntactic grammar. Simple white space and single-line comments are discarded and do not appear in the stream of input elements.

Productions of the lexical and RegExp grammars are distinguished by having two colons “::” as separating punctuation.

5.1.3The Numeric String Grammar

Another grammar is used for translating Strings into numeric values. This grammar is similar to the part of the lexical grammar having to do with numeric literals. When found strings literals( begins with '"' or "'" ), the parser enters Numeric String parsing state( when found /a_Pattern/, ecma parser enters RegExp parsing state).

Productions of the numeric string grammar are distinguished by having three colons “:::” as punctuation.

5.1.4The Syntactic Grammar

The syntactic grammar for ECMAScript is given in clauses 11(Lexical Grammar), 12, 13, 14(Functions and Classes), and 15(Scripts and Modules). This grammar has ECMAScript tokens defined by the lexical grammar as its terminal symbols. It defines a set of productions, starting from two alternative goal symbols Script and Module, that describe how sequences of tokens form syntactically correct independent components of ECMAScript programs.

When a stream of code points is to be parsed as an ECMAScript Script or Module, it is first converted to a stream of input elements by repeated application of the lexical grammar; this stream of input elements is then parsed by a single application of the syntactic grammar. The input stream is syntactically in error if the tokens in the stream of input elements cannot be parsed as a single instance of the goal nonterminal (Script or Module), with no tokens left over.

When a parse is successful, it constructs a parse tree, a rooted tree structure in which each node is a Parse Node. Each Parse Node is an instance of a symbol in the grammar; it represents a span of the source text that can be derived from that symbol. The root node of the parse tree, representing the whole of the source text, is an instance of the parser's goal symbol. When a Parse Node is an instance of a nonterminal, it is also an instance of some production that has that nonterminal as its left-hand side. Moreover, it has zero or more children, one for each symbol on the production's right-hand side: each child is a Parse Node that is an instance of the corresponding symbol.

Productions of the syntactic grammar are distinguished by having just one colon “:” as punctuation.

5.1.5Grammar Notation

A production may be parameterized by a subscripted annotation of the form “[parameters]”

StatementList[AliasSuffix1, AliasSuffix2]:
ReturnStatement
ExpressionStatement

is an abbreviation for:

StatementList:
ReturnStatement
ExpressionStatement
StatementList_AliasSuffix1:
ReturnStatement
ExpressionStatement
StatementList_AliasSuffix2:
ReturnStatement
ExpressionStatement
StatementList_AliasSuffix1_AliasSuffix2:
ReturnStatement
ExpressionStatement

References to nonterminals on the right-hand side of a production can also be parameterized. For example:

StatementList:
ReturnStatement
ExpressionStatement[+In]

is equivalent to saying:

StatementList:
ReturnStatement
ExpressionStatement_In


and:


StatementList:
ReturnStatement
ExpressionStatement[~In]

is equivalent to:

StatementList:
ReturnStatement
ExpressionStatement

Prefixing a parameter name with “?” on a right-hand side nonterminal reference makes that parameter value dependent upon the occurrence of the parameter name on the reference to the current production's left-hand side symbol. For example:


VariableDeclaration[In]:
BindingIdentifierInitializer[?In]
is an abbreviation for:

VariableDeclaration:
BindingIdentifierInitializer
VariableDeclaration_In:
BindingIdentifierInitializer_In

If a right-hand side alternative is prefixed with “[+parameter]” that alternative is only available if the named parameter was used in referencing the production's nonterminal symbol. If a right-hand side alternative is prefixed with “[~parameter]” that alternative is only available if the named parameter was not used in referencing the production's nonterminal symbol. This means that:

StatementList[Return]:
[+Return]ReturnStatement
ExpressionStatement
is an abbreviation for:

StatementList:
ExpressionStatement
StatementList_Return:
ReturnStatement
ExpressionStatement
and that:

StatementList[Return]:
[~Return]ReturnStatement
ExpressionStatement
is an abbreviation for:

StatementList:
ReturnStatement
ExpressionStatement
StatementList_Return:
ExpressionStatement

5.2Algorithm Conventions

some algorithms, called abstract operations, are named and written in parameterized functional form so that they may be referenced by name from within other algorithms. Calls to abstract operations return Completion Records.

Calls to abstract operations return Completion Records. Abstract operations referenced using the functional application style and the method application style that are prefixed by ? indicate that ReturnIfAbrupt should be applied to the resulting Completion Record. For example, ? operationName() is equivalent to ReturnIfAbrupt(operationName()). Similarly, ? someValue.operationName() is equivalent to ReturnIfAbrupt(someValue.operationName()).

The prefix ! is used to indicate that an abstract operation will never return an abrupt completion and that the resulting Completion Record's value field should be used in place of the return value of the operation. For example, “Let val be ! operationName()” is equivalent to the following algorithm steps:


Let val be operationName().

Assert: val is never an abrupt completion.

If val is a Completion Record, let val be val.[[Value]].

Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers, which unless otherwise noted do not include infinities and do not include a negative zero that is distinguished from positive zero. Algorithms in this standard that model floating-point arithmetic include explicit steps, where necessary, to handle infinities and signed zero and to perform rounding. If a mathematical operation or function is applied to a floating-point number, it should be understood as being applied to the exact mathematical value represented by that floating-point number; such a floating-point number must be finite, and if it is +0 or -0 then the corresponding mathematical value is simply 0.

When impl, it's a need to diff an mathematical operations from operations in this standard(modeling floating-point arithmetic).

The mathematical function floor(x) produces the largest integer (closest to positive infinity) that is not larger than x.

floor(x) = x-(x modulo 1).

5.3Static Semantic Rules

Context-free grammars are not sufficiently powerful to express all the rules that define whether a stream of input elements form a valid ECMAScript Script or Module. In some situations additional rules are needed that may be expressed using either ECMAScript algorithm conventions. Such rules are always associated with a production of a grammar and are called the static semantics of the production.

Static Semantic Rules have names and typically are defined using an algorithm. Named Static Semantic Rules are associated with grammar productions and a production that has multiple alternative definitions will typically have for each alternative a distinct algorithm for each applicable named static semantic rule.

A special kind of static semantic rule is an Early Error Rule. Early error rules define early error conditions (see clause 16) that are associated with specific grammar productions. Evaluation of most early error rules are not explicitly invoked within the algorithms of this specification. A conforming implementation must, prior to the first evaluation of a Script or Module, validate all of the early error rules of the productions used to parse that Script or Module. If any of the early error rules are violated the Script or Module is invalid and cannot be evaluated.

Windows_Protocols__2017_Dec_01_cfb

2 Structures

2.1 Compound File Sector Numbers and Types

Each sector, except for the header, is identified by a nonnegative, 32-bit sector number. The following sector numbers above 0xFFFFFFFA are reserved and MUST NOT be used to identify the location of a sector in a compound file.

Followings are definitions of SectIDs:

#define SID_MAXREG (0xfffffffa)

#define SID_FUTURE  ((SectID)(SID_MAXREG + 1))

#define SID_MSAT_SECTOR ((SectID)(SID_MAXREG + 2))

#define SID_SAT_SECTOR ((SectID)(SID_MAXREG + 3))

#define SID_END_OF_CHAIN    ((SectID)(SID_MAXREG + 4))

#define SID_UNUSED_SECTOR ((SectID)(SID_MAXREG + 5))

/*
[MS-CFB] or [MS-CFB] errata 2.9 Compound File Size Limits:
...4,096 bytes/sector x MAXREGSECT (0xFFFFFFFA) sectors...
so SID_MAXREG is also a special ID.
*/
#define SID_IS_SPECIAL(sid) ((SectID)(sid) >= SID_MAXREG)

The following list contains the types of sectors that are allowed in a compound file:

Header: A single sector with fields that are needed to read the other structures of the compound file.For version 4 compound files, the header size (512 bytes) is less than the sector size (4,096 bytes), so the remaining part of the header (3,584 bytes) MUST be filled with all zeroes. We can take head_size as equals with sect_size.

FAT: Sector Allocation Table(OpenOffice: SAT).

DIFAT: Used to locate FAT sectors in the compound file(OpenOffice: MSAT).

Mini FAT: FAT for short streams(OpenOffice: SSAT).

Directory:
User-defined Data:
Unallocated Free:

Range Lock:A single sector that is used to manage concurrent access to the compound file. This sector must cover file offset 0x7FFFFFFF(OpenOffice:Not used).

2.6 Compound File Directory Sectors

2.6.1 Compound File Directory Entry

The valid values for a stream ID, which are used in the Child ID, Right Sibling ID, and Left Sibling ID fields, are 0 through MAXREGSID (excluding).
Directory Entry Name (64 bytes):
storage and stream names are limited to 32 UTF-16 code points, including the terminating null character. When locating an object in the compound file except for the root storage, the directory entry name is compared by using a special case-insensitive uppercase mapping, described in Red-Black Tree. The following characters are illegal and MUST NOT be part of the name: '/', '\', ':', '!'.

Directory Entry Name Length (2 bytes):
This field MUST match the length of the Directory Entry Name Unicode string in bytes. The length MUST be a multiple of 2 and include the terminating null character in the count.
A secured parser shall not use this field.

Object Type (offset 66, 0x42): This field MUST be 0x00, 0x01, 0x02, or 0x05, depending on the actual type of object. All other values are not valid: 0 for Unknown or unallocated; 1 for Storage Object; 2 for Stream Object; 5 for Root Storage Object. 

Color Flag (offset 67, 0x43): This field MUST be 0x00 (red) or 0x01 (black). 

Left Sibling ID(offset 68, 0x44): This field contains the stream ID of the left sibling. If there is no left sibling, the field MUST be set to NOSTREAM (0xFFFFFFFF).

Right Sibling ID (offset 72, 0x48): 

Child ID (offset 76, 0x4C): This field contains the stream ID of a child object. If there is no child object, the field MUST be set to NOSTREAM (0xFFFFFFFF). 

CLSID (offset 80, 0x50): This field contains an object class GUID(can be used as a parameter to start applications.), if this entry is a storage or root storage. If no object class GUID is set on this object, the field MUST be set to all zeroes. 

State Bits (offset 96, 0x60): This field contains the user-defined flags if this entry is a storage object or root storage object. If no state bits are set on the object, this field MUST be set to all zeroes. 

Creation Time(8 bytes):Modified Time (8 bytes): 

Starting Sector Location (offset 116, 0x74): This field contains the first sector location if this is a stream object. For a root storage object, this field MUST contain the first sector of the mini stream, if the mini stream exists.

Stream Size (8 bytes): Streams whose size is less than the Cutoff value exist in the mini stream. Parsers must trust Stream Size to decide it's mini or standard stream,
while maintains a size telling the size figured out through sector chain of this stream.

2.6.4 Red-Black Tree

According rbtree, followings are true:
The root storage object MUST always be black. 
wo consecutive nodes MUST NOT both be red.(if one node is red, it's left/right must be black)
The left sibling MUST always be less than the right sibling. (root object has const name, its name don't compare; root object has no left and right)

This sorting relationship is defined as follows:

A node that has a shorter name is less than a node that has a longer name. 

For each UTF-16 code point, convert to uppercase by using the Unicode Default 
Case Conversion Algorithm

Saturday, January 27, 2018

股票投资

股票选股
https://wallstreetcn.com/articles/3052005

++++++++++++++++++++++++ 电动汽车 ++++++++++++++++++++++++ 谷歌旗下Waymo和Lyft 联手开发自动驾驶汽车技术 601777 力帆股份 特斯拉 腾讯一季度总收入495.52亿元人民币(71.82亿美元 ),同比增长55%;网络游戏收入增长34% 腾讯向美国游戏公司Pocket Gems追加9000万美元投资

Friday, January 26, 2018

Double Precision Floating's Encodings

double's Encodings are as fllowing

+Infinity  0   11..11 (1)  00..00
+Normals  0   11..10 (1)  11..11  the max is less than 1 SHL (2046-1023) * 2 = 1 SHL 1024 = 2 ^ 1024; intel manual says it's less than 2 ^ 1023, which is proved to be in-correct
+Normals  0   00..01 (1)  00..00  the min is 2^-1022;  checked with javascript's normal min and normal max
+Denormals  0   00..00 (0)  11..11  the max is less than 1 SHL (1-1023) = 2 ^ -1022; Will explain later
+Denormals  0   00..00 (0)  00..01  the min is 1 SHL (1-1023)  SHR 52 = 2 ^ -1074; 

as Denormals.min's minimal  Fraction is 00..01, not 00..00(00..00 is left for zero), so if assume  Denormals.min's integer|J bit as 1, then it's Significand is 1.00..01.

processing 1.00..01 is not convinient, so we let Denormals.min's Exponent to be -1022 instead of -1023,
by doing this, Denormals.min can be caculated in above way; so does Denormals.max.

+0: all zeros;
-0   1   00..00 (0)  00..00

-Denormals  1   00..00 (0)  00..01  the max is (-1) * (+Denormals min)
-Denormals  1   00..00 (0)  11..11  the min is (-1) * (+Denormals max)
-Normals  1   the max is (-1) * (+Normals.min)
-Normals  1   the min is (-1) * (+Normals.max)
-Infinity

NaNs are not detailed here, but Numbers of NaNs is easy to get:

NaNs's Exponent parts are the same with Infinitys, so 
 Numbers of NaNs = 2^53 - 2

CreateGoogleCloudPlatformProject

Login Google Cloud Platform, tt "Manage resources" page, select create project( one can create at most 12 free projects at the cloud )

Project name example: LilyJohnGoogle

Project ID(Project ID can have lowercase letters, digits or hyphens and must start with a lowercase letter): lily-trade-com-rev01

Wait for google to finish, if the right-upper-corner icon stop from waiting state and you still can't see the project, use F5 to refresh.

done, now you can use the project( I use it for a static website )

Thursday, January 18, 2018

ECMA404_Dec2017_JSON

JSON shares a small subset of ECMAScript’s syntax with all other programming languages.

A JSON value can be an object, array, number, string, true, false, or null. Note, ECMA value undefined is not a JSON value.

8 Numbers

Following is grammar for Numbers:

image_not_loaded

Note, Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted.

Monday, January 15, 2018

Stop Out level

What is Stop Out
A certain required margin level (in percentage) at which your trading positions will start to automatically close in order to prevent further account losses into the negative territory.
For example:
Your balance is $10,000.
You open a trading position with $1,000 margin.
If the loss on this position reaches $9,500, your account equity becomes:
$10,000 — $9,500 = $500
(50% of your used margin)
At that time, a Stop Out will be issued and your positions will start closing.( 
AvaTrade has Stop Out level as 50%)

Sunday, January 7, 2018

BC省公平药物计划

BC省Fair PharmaCare

介绍

Fair PharmaCare即传说中的公平药物计划,就是药费报销。

就好像车保险, Fair PharmaCare同样有一个Deductible, 不同收入的家庭, 这个扣除额不一样, 零收入家庭这一项为0 。过了扣除额的部分,FairPharma Care可以报销70%, 数额更高一点之后, 报销额度就是100%。

需要注意Fair PharmaCare也有不报的药物或医疗器械,即使是报的项目,也有一个限定,酱紫如果医生如果给你开很贵的药的时候,你就要小心了。

申请

第一步: 在 https://pharmacare.moh.hnet.bc.ca/ 注册。

第二步: Health Insurance BC 给回信 Re: Confirmation of FairPharma Care Assistance. 告诉你Reg Num(注册号格式是“大写字母-三个数字-三个数字-两个数字”).如果你有extended health benefits plan, 它可能要求你在报销的时候提供FairPharma Care信息(记得Manulife就要求客户填这一项信息)。

第三步: 填同意书. 因为HIBC 需要知道你的收入以决定报销额度,所以取得你的申请先, 尽快把这个同意书寄过去就行了。