Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

bnf - Is a JavaScript function call a LeftHandSideExpression, thus an ExpressionStatement?

I'm trying to prove that a simple function call such as

window.alert();

is valid EcmaScript 2016 (7th Edition) grammar. Working backward, with the expectation this is an ExpressionStatement, I see that it fits the pattern MemberExpression Arguments which is a CallExpression. And, section 12.3 defines LeftHandSideExpression as possibly a CallExpression. Now, my problem is that section 12.15 AssignmentExpression seems to require that LeftHandSideExpression be followed by either an AssignmentExpression or an AssignmentOperator and AssignmentExpression cannot be ;

I'm probably missing something simple. Direction will be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

An AssignmentExpression does not necessarily need to be an assignment, it only means "an assignment could stand here". It can also consist of solely a ConditionalExpression. And now we need to go down the whole chain of associativity rules:
A ConditionalExpression can contain a ternary operator or consist solely of a LogicalORExpression. A LogicalORExpression can contain an || operator or consist solely of a LogicalANDExpression. And so on: A LogicalANDExpression can consist solely of a BitwiseORExpression which can consist of solely a BitwiseXORExpression which can consist of solely a BitwiseANDExpression which can consist of solely an EqualityExpression which can consist of solely a RelationalExpression which can consist of solely a ShiftExpression which can consist of solely an AdditiveExpression which can consist of solely a MultiplicativeExpression which can consist of solely an ExponentiationExpression which can consist of solely a UnaryExpression which can consist of solely an UpdateExpression.

Which finally can consist of the LeftHandSideExpression that we were looking after.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...