How to evaluate the production `SourceElements : SourceElements SourceElement` when parse tree only has one statement

StackOverflow https://stackoverflow.com/questions/20623825

سؤال

Regarding EcmaScript specification 5.1, specifically, the semantic explanation for the SourceElements production is:

SourceElements : SourceElements SourceElement

(in clause 14.0)

The semantic explanation for the above production has me confused.

Let's assume you have two statements (call it s1 and s2), then by the semantic explanation given by the above clause, I would set the result of s1 to headResult. If it's not an abrupt completion, I then set the result of s2 to tailResult. I either return the result with tailResult's value or headResult's value.

My question is, what do I do in the case when there's just one statement?

Do I just return the result of s1? Do I check it for an abrupt completion? What do I do with the value?

I guess I don't know how to translate the left recursion to the case when there's just one statement.

هل كانت مفيدة؟

المحلول

SourceElements has two productions:

SourceElements:
    SourceElement
    SourceElements SourceElement

When there's only one statement in the program, it matches the first production. When there's more than one statement, it matches the second production, and recurses.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top