root/misc/JavaScript-FrontEnd/Grammar.pm

Revision 8596, 26.6 kB (checked in by putter, 3 years ago)

misc/JavaScript-FrontEnd/Grammar?.pm - Corrected typo. The file now parses with current pugs and parrot 0.4.0. But being untested, it is, of course, very unlikely to actually work.

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1
2#
3#  This grammar was closely derived from
4#    ECMA-262, ECMAScript Language Specification, 3rd Edition
5#    Appendix A.
6#
7#  Changes to specification grammar.
8#   * RegularExpressionLiteral has been added to Literal.
9#     Since we dont have a separate tokenizer.
10#   * <SourceCharacter> removals.
11#     Several "SourceCharacter but not ..." have been expressed as
12#     complemented character sets.  <-[...]>  They are all tagged with
13#     #SourceCharacter but not ...
14#     But <SourceCharacter> isnt called for all characters anyway,
15#     so no great loss.
16#
17#  Other notes:
18#   * <ws> is redefined to be used, via :words, by A.3, A.4, and A.5.
19#     Note it is always an optional match.
20#   * Parts of the grammar, intended for a tokenizer, are not actually used.
21#   * Some rules, eg StringNumericLiteral, are not used in parsing JavaScript,
22#     but rather in implementing it (eg, by ToNumber).
23#   * Character sets are sometimes collapsed.
24#     Eg, <'0'> | <'1'> ... <'9'> changed to <[0..9]>
25#   * "Foo but not x" is expressed as
26#     <!before x> <Foo>
27#   * "lookahead is not an element of { x }" is expressed as
28#     <!before x>
29#     Such usage is tagged with #lookahead
30#     If rules taking arguments had any hope of working soon,
31#     I would have said <!lookahead x>.
32#   * "[no LineTerminator here]" is expressed as
33#     <no_LineTerminator_here>.
34#
35#  Resources:
36#   http://www.ecma-international.org/publications/standards/Ecma-262.htm
37#   http://bclary.com/2004/11/07/ecma-262
38#
39#  The SPEC grammar SHOULD NOT BE CHANGED to accommodate the characteristics
40#  of particular regex engines.  Its structure follows the spec.  If for
41#  instance, your engine cannot handle left recursive rules, you should
42#  create a new grammar, inherit from this one, and redefine just those
43#  rules.  See JavaScript::ECMAScript3::Grammar.
44#
45#  Bugs:
46#   * This grammar has never yet been run, so there no doubt are some.
47#
48#  Possible Bugs:
49#   * We are not using some of the tokenizer rules.
50#     So it isnt entirely clear we are doing an fully correct parse.
51#
52#  Todo:
53#   * Create a second grammar which actually runs, is efficient,
54#     and has captures for easy use of the resulting matches.
55#   * Perhaps define a macro gram ($name) { "rule $name :words" },
56#     rather than having the clutter of lots of explicit :words modifiers.
57#
58#  Thanks to Bob Clary, who created the HTML-ified ecma-262, without which
59#  this grammar would likely not have been written. - Mitchell N Charity
60#
61
62
63grammar JavaScript::ECMAScript3::Grammar::Spec;
64
65rule ws          {<?ws_input>*}
66rule ws_required {<?ws_input>+}
67rule ws_input {
68      <WhiteSpace>
69    | <LineTerminator>
70    | <Comment>
71
72rule no_LineTerminator_here {
73      [ <ws> & <-<LineTerminator>>*? ]
74}
75
76
77# 7.2 White Space
78
79rule TAB  { \x0009 }
80rule VT   { \x000B }
81rule FF   { \x000C }
82rule SP   { \x0020 }
83rule NBSP { \x00A0 }
84rule USP  { <<Zs>-<TAB>-<VT>-<FF>-<SP>-<NBSP>> }
85
86# 7.3 Line Terminators
87
88rule LF   { \x000A }
89rule CR   { \x000D }
90rule LS   { \x2028 }
91rule PS   { \x2029 }
92
93
94# A.1 Lexical Grammar
95
96rule SourceCharacter {  # see clause 6
97      . #dot
98}
99rule InputElementDiv {  # see clause 7
100      <WhiteSpace>
101    | <LineTerminator>
102    | <Comment>
103    | <Token> <DivPunctuator>
104}
105rule InputElementRegExp {  # see clause 7
106      <WhiteSpace>
107    | <LineTerminator>
108    | <Comment>
109    | <Token>
110    | <RegularExpressionLiteral>
111}
112rule WhiteSpace {  # see 7.2
113      <TAB>
114    | <VT>
115    | <FF>
116    | <SP>
117    | <NBSP>
118    | <USP>
119}
120rule LineTerminator {  # see 7.3
121      <LF>
122    | <CR>
123    | <LS>
124    | <PS>
125}
126rule Comment {  # see 7.4
127      <MultiLineComment>
128    | <SingleLineComment>
129}
130rule MultiLineComment {  # see 7.4
131      <'/*'> <MultiLineCommentChars>? <'*/'>
132}
133rule MultiLineCommentChars {  # see 7.4
134      <MultiLineNotAsteriskChar> <MultiLineCommentChars>?
135    | <'*'> <PostAsteriskCommentChars>?
136}
137rule PostAsteriskCommentChars {  # see 7.4
138      <MultiLineNotForwardSlashOrAsteriskChar> <MultiLineCommentChars>?
139    | <'*'> <PostAsteriskCommentChars>?
140}
141rule MultiLineNotAsteriskChar {  # see 7.4
142      <-[*]> #SourceCharacter but not ...
143}
144rule MultiLineNotForwardSlashOrAsteriskChar {  # see 7.4
145      <-[/*]> #SourceCharacter but not ...
146}
147rule SingleLineComment {  # see 7.4
148      <'//'> <SingleLineCommentChars>?
149}
150rule SingleLineCommentChars {  # see 7.4
151      <SingleLineCommentChar> <SingleLineCommentChars>?
152}
153rule SingleLineCommentChar {  # see 7.4
154      <!before <LineTerminator>> <SourceCharacter>
155}
156rule Token {  # see 7.5
157      <ReservedWord>
158    | <Identifier>
159    | <Punctuator>
160    | <NumericLiteral>
161    | <StringLiteral>
162}
163rule ReservedWord {  # see 7.5.1
164      <Keyword>
165    | <FutureReservedWord>
166    | <NullLiteral>
167    | <BooleanLiteral>
168}
169rule Keyword {  # see 7.5.2
170      <'break'>
171    | <'else'>
172    | <'new'>
173    | <'var'>
174    | <'case'>
175    | <'finally'>
176    | <'return'>
177    | <'void'>
178    | <'catch'>
179    | <'for'>
180    | <'switch'>
181    | <'while'>
182    | <'continue'>
183    | <'function'>
184    | <'this'>
185    | <'with'>
186    | <'default'>
187    | <'if'>
188    | <'throw'>
189    | <'delete'>
190    | <'in'>
191    | <'try'>
192    | <'do'>
193    | <'instanceof'>
194    | <'typeof'>
195}
196rule FutureReservedWord {  # see 7.5.3
197      <'abstract'>
198    | <'enum'>
199    | <'int'>
200    | <'short'>
201    | <'boolean'>
202    | <'export'>
203    | <'interface'>
204    | <'static'>
205    | <'byte'>
206    | <'extends'>
207    | <'long'>
208    | <'super'>
209    | <'char'>
210    | <'final'>
211    | <'native'>
212    | <'synchronized'>
213    | <'class'>
214    | <'float'>
215    | <'package'>
216    | <'throws'>
217    | <'const'>
218    | <'goto'>
219    | <'private'>
220    | <'transient'>
221    | <'debugger'>
222    | <'implements'>
223    | <'protected'>
224    | <'volatile'>
225    | <'double'>
226    | <'import'>
227    | <'public'>
228}
229rule Identifier {  # see 7.6
230      <!before <ReservedWord>> <IdentifierName>
231}
232rule IdentifierName {  # see 7.6
233      <IdentifierStart>
234    | <IdentifierName> <IdentifierPart>
235}
236rule IdentifierStart {  # see 7.6
237      <UnicodeLetter>
238    | <'$'>
239    | <'_'>
240    | <'\\'> <UnicodeEscapeSequence>
241}
242rule IdentifierPart {  # see 7.6
243      <IdentifierStart>
244    | <UnicodeCombiningMark>
245    | <UnicodeDigit>
246    | <UnicodeConnectorPunctuation>
247    | <'\\'> <UnicodeEscapeSequence>
248}
249rule UnicodeLetter {  # see 7.6
250      # any character in the Unicode categories "Uppercase letter (Lu)",
251      # "Lowercase letter (Ll)", "Titlecase letter (Lt)",
252      # "Modifier letter (Lm)", "Other letter (Lo)", or "Letter number (Nl)".
253      <Lu> | <Ll> | <Lt> | <Lm> | <Lo> | <Nl>
254}
255rule UnicodeCombiningMark {  # see 7.6
256      # any character in the Unicode categories "Non-spacing mark (Mn)"
257      # or "Combining spacing mark (Mc)"
258      <Mn> | <Mc>
259}
260rule UnicodeDigit {  # see 7.6
261      # any character in the Unicode category "Decimal number (Nd)"
262      <Nd>
263}
264rule UnicodeConnectorPunctuation {  # see 7.6
265      # any character in the Unicode category "Connector punctuation (Pc)"
266      <Pc>
267}
268rule HexDigit {  # see 7.6
269      <[0..9a..fA..F]>
270}
271rule Punctuator {  # see 7.7
272      <'{'>
273    | <'}'>
274    | <'('>
275    | <')'>
276    | <'['>
277    | <']'>
278    | <'.'>
279    | <';'>
280    | <','>
281    | <'<'>
282    | <'>'>
283    | <'<='>
284    | <'>='>
285    | <'=='>
286    | <'!='>
287    | <'==='>
288    | <'!=='>
289    | <'+'>
290    | <'-'>
291    | <'*'>
292    | <'%'>
293    | <'++'>
294    | <'--'>
295    | <'<<'>
296    | <'>>'>
297    | <'>>>'>
298    | <'&'>
299    | <'|'>
300    | <'^'>
301    | <'!'>
302    | <'~'>
303    | <'&&'>
304    | <'||'>
305    | <'?'>
306    | <':'>
307    | <'='>
308    | <'+='>
309    | <'-='>
310    | <'*='>
311    | <'%='>
312    | <'<<='>
313    | <'>>='>
314    | <'>>>='>
315    | <'&='>
316    | <'|='>
317    | <'^='>
318}
319rule DivPunctuator {  # see 7.7
320      <'/'>
321    | <'/='>
322}
323rule Literal {  # see 7.8
324      <NullLiteral>
325    | <BooleanLiteral>
326    | <NumericLiteral>
327    | <StringLiteral>
328    | <RegularExpressionLiteral> # ADDED - this is not in the spec.
329}
330rule NullLiteral {  # see 7.8.1
331      <'null'>
332}
333rule BooleanLiteral {  # see 7.8.2
334      <'true'>
335    | <'false'>
336}
337rule NumericLiteral {  # see 7.8.3
338      <DecimalLiteral>
339    | <HexIntegerLiteral>
340}
341rule DecimalLiteral {  # see 7.8.3
342      <DecimalIntegerLiteral> <'.'> <DecimalDigits>? <ExponentPart>?
343    | <'.'> <DecimalDigits> <ExponentPart>?
344    | <DecimalIntegerLiteral> <ExponentPart>?
345}
346rule DecimalIntegerLiteral {  # see 7.8.3
347      <'0'>
348    | <NonZeroDigit> <DecimalDigits>?
349}
350rule DecimalDigits {  # see 7.8.3
351      <DecimalDigit>
352    | <DecimalDigits> <DecimalDigit>
353}
354rule DecimalDigit {  # see 7.8.3
355      <[0..9]>
356}
357rule ExponentIndicator {  # see 7.8.3
358      <'e'>
359    | <'E'>
360}
361rule SignedInteger {  # see 7.8.3
362      <DecimalDigits>
363    | <'+'> <DecimalDigits>
364    | <'-'> <DecimalDigits>
365}
366rule HexIntegerLiteral {  # see 7.8.3
367      <'0x'> <HexDigit>
368    | <'0X'> <HexDigit>
369    | <HexIntegerLiteral> <HexDigit>
370}
371rule StringLiteral {  # see 7.8.4
372      <'"'> <DoubleStringCharacters>? <'"'>
373    | <'\''> <SingleStringCharacters>? <'\''>
374}
375rule DoubleStringCharacters {  # see 7.8.4
376      <DoubleStringCharacter> <DoubleStringCharacters>?
377}
378rule SingleStringCharacters {  # see 7.8.4
379      <SingleStringCharacter> <SingleStringCharacters>?
380}
381rule DoubleStringCharacter {  # see 7.8.4
382      <!before <LineTerminator>> <-[\"\\]> #SourceCharacter but not ...
383    | <'\\'> <EscapeSequence>
384}
385rule SingleStringCharacter {  # see 7.8.4
386      <!before <LineTerminator>> <-[\'\\]> #SourceCharacter but not ...
387    | <'\\'> <EscapeSequence>
388}
389rule EscapeSequence {  # see 7.8.4
390      <CharacterEscapeSequence>
391    | <'0'> <!before <DecimalDigit>> #lookahead
392    | <HexEscapeSequence>
393    | <UnicodeEscapeSequence>
394}
395rule CharacterEscapeSequence {  # see 7.8.4
396      <SingleEscapeCharacter>
397    | <NonEscapeCharacter>
398}
399rule SingleEscapeCharacter {  # see 7.8.4
400      <'\''>
401    | <'"'>
402    | <'\\'>
403    | <'b'>
404    | <'f'>
405    | <'n'>
406    | <'r'>
407    | <'t'>
408    | <'v'>
409}
410rule EscapeCharacter {  # see 7.8.4
411      <SingleEscapeCharacter>
412    | <DecimalDigit>
413    | <'x'>
414    | <'u'>
415}
416rule HexEscapeSequence {  # see 7.8.4
417      <'x'> <HexDigit> <HexDigit>
418}
419rule UnicodeEscapeSequence {  # see 7.8.4
420      <'u'> <HexDigit> <HexDigit> <HexDigit> <HexDigit>
421}
422rule RegularExpressionLiteral {  # see 7.8.5
423      <'/'> <RegularExpressionBody> <'/'> <RegularExpressionFlags>
424}
425rule RegularExpressionBody {  # see 7.8.5
426      <RegularExpressionFirstChar> <RegularExpressionChars>
427}
428rule RegularExpressionChars {  # see 7.8.5
429      <null>
430    | <RegularExpressionChars> <RegularExpressionChar>
431}
432rule RegularExpressionFirstChar {  # see 7.8.5
433      <!before <[*\\\/]>> <NonTerminator>
434    | <BackslashSequence>
435}
436rule RegularExpressionChar {  # see 7.8.5
437      <!before <[\\\/]>> <NonTerminator>
438    | <BackslashSequence>
439}
440rule BackslashSequence {  # see 7.8.5
441      <'\\'> <NonTerminator>
442}
443rule NonTerminator {  # see 7.8.5
444      <!before <LineTerminator>> <SourceCharacter>
445}
446rule RegularExpressionFlags {  # see 7.8.5
447      <null>
448    | <RegularExpressionFlags> <IdentifierPart>
449}
450
451# A.2 Number Conversions
452
453rule StringNumericLiteral {  # see 9.3.1
454      <StrWhiteSpace>?
455    | <StrWhiteSpace>? <StrNumericLiteral> <StrWhiteSpace>?
456}
457rule StrWhiteSpace {  # see 9.3.1
458      <StrWhiteSpaceChar> <StrWhiteSpace>?
459}
460rule StrWhiteSpaceChar {  # see 9.3.1
461      <TAB>
462    | <SP>
463    | <NBSP>
464    | <FF>
465    | <VT>
466    | <CR>
467    | <LF>
468    | <LS>
469    | <PS>
470    | <USP>
471}
472rule StrNumericLiteral {  # see 9.3.1
473      <StrDecimalLiteral>
474    | <HexIntegerLiteral>
475}
476rule StrDecimalLiteral {  # see 9.3.1
477      <StrUnsignedDecimalLiteral>
478    | <'+'> <StrUnsignedDecimalLiteral>
479    | <'-'> <StrUnsignedDecimalLiteral>
480}
481rule StrUnsignedDecimalLiteral {  # see 9.3.1
482      <'Infinity'>
483    | <DecimalDigits> <'.'> <DecimalDigits>? <ExponentPart>?
484    | <'.'> <DecimalDigits> <ExponentPart>?
485    | <DecimalDigits> <ExponentPart>?
486}
487rule DecimalDigits {  # see 9.3.1
488      <DecimalDigit>
489    | <DecimalDigits> <DecimalDigit>
490}
491rule DecimalDigit {  # see 9.3.1
492      <[0..9]>
493}
494rule ExponentPart {  # see 9.3.1
495      <ExponentIndicator> <SignedInteger>
496}
497rule ExponentIndicator {  # see 9.3.1
498      <'e'>
499    | <'E'>
500}
501rule SignedInteger {  # see 9.3.1
502      <DecimalDigits>
503    | <'+'> <DecimalDigits>
504    | <'-'> <DecimalDigits>
505}
506rule HexIntegerLiteral {  # see 9.3.1
507      <'0x'> <HexDigit>
508    | <'0X'> <HexDigit>
509    | <HexIntegerLiteral> <HexDigit>
510}
511rule HexDigit {  # see 9.3.1
512      <[0..9a..fA..F]>
513}
514
515# A.3 Expressions
516
517rule PrimaryExpression :words {  # see 11.1
518      <'this'>
519    | <Identifier>
520    | <Literal>
521    | <ArrayLiteral>
522    | <ObjectLiteral>
523    | <'('> <Expression> <')'>
524}
525rule ArrayLiteral :words {  # see 11.1.4
526      <'['> <Elision>? <']'>
527    | <'['> <ElementList> <']'>
528    | <'['> <ElementList> <','> <Elision>? <']'>
529}
530rule ElementList :words {  # see 11.1.4
531      <Elision>? <AssignmentExpression>
532    | <ElementList> <','> <Elision>? <AssignmentExpression>
533}
534rule Elision :words {  # see 11.1.4
535      <','>
536    | <Elision> <','>
537}
538rule ObjectLiteral :words {  # see 11.1.5
539      <'{'> <'}'>
540    | <'{'> <PropertyNameAndValueList> <'}'>
541}
542rule PropertyNameAndValueList :words {  # see 11.1.5
543      <PropertyName> <':'> <AssignmentExpression>
544    | <PropertyNameAndValueList> <','> <PropertyName> <':'> <AssignmentExpression>
545}
546rule PropertyName :words {  # see 11.1.5
547      <Identifier>
548    | <StringLiteral>
549    | <NumericLiteral>
550}
551rule MemberExpression :words {  # see 11.2
552      <PrimaryExpression>
553    | <FunctionExpression>
554    | <MemberExpression> <'['> <Expression> <']'>
555    | <MemberExpression> <'.'> <Identifier>
556    | <'new'> <?ws_required> <MemberExpression> <Arguments>
557}
558rule NewExpression :words  {  # see 11.2
559      <MemberExpression>
560    | <'new'> <?ws_required> <NewExpression>
561}
562rule CallExpression :words {  # see 11.2
563      <MemberExpression> <Arguments>
564    | <CallExpression> <Arguments>
565    | <CallExpression> <'['> <Expression> <']'>
566    | <CallExpression> <'.'> <Identifier>
567}
568rule Arguments :words {  # see 11.2
569      <'('> <')'>
570    | <'('> <ArgumentList> <')'>
571}
572rule ArgumentList :words {  # see 11.2
573      <AssignmentExpression>
574    | <ArgumentList> <','> <AssignmentExpression>
575}
576rule LeftHandSideExpression :words {  # see 11.2
577      <NewExpression>
578    | <CallExpression>
579}
580rule PostfixExpression :words {  # see 11.3
581      <LeftHandSideExpression>
582    | <LeftHandSideExpression><no_LineTerminator_here><'++'>
583    | <LeftHandSideExpression><no_LineTerminator_here><'--'>
584}
585rule UnaryExpression :words {  # see 11.4
586      <PostfixExpression>
587    | <'delete'> <UnaryExpression>
588    | <'void'> <UnaryExpression>
589    | <'typeof'> <UnaryExpression>
590    | <'++'> <UnaryExpression>
591    | <'--'> <UnaryExpression>
592    | <'+'> <UnaryExpression>
593    | <'-'> <UnaryExpression>
594    | <'~'> <UnaryExpression>
595    | <'!'> <UnaryExpression>
596}
597rule MultiplicativeExpression :words {  # see 11.5
598      <UnaryExpression>
599    | <MultiplicativeExpression> <'*'> <UnaryExpression>
600    | <MultiplicativeExpression> <'/'> <UnaryExpression>
601    | <MultiplicativeExpression> <'%'> <UnaryExpression>
602}
603rule AdditiveExpression :words {  # see 11.6
604      <MultiplicativeExpression>
605    | <AdditiveExpression> <'+'> <MultiplicativeExpression>
606    | <AdditiveExpression> <'-'> <MultiplicativeExpression>
607}
608rule ShiftExpression :words {  # see 11.7
609      <AdditiveExpression>
610    | <ShiftExpression> <'<<'> <AdditiveExpression>
611    | <ShiftExpression> <'>>'> <AdditiveExpression>
612    | <ShiftExpression> <'>>>'> <AdditiveExpression>
613}
614rule RelationalExpression :words {  # see 11.8
615      <ShiftExpression>
616    | <RelationalExpression> <'<'> <ShiftExpression>
617    | <RelationalExpression> <'>'> <ShiftExpression>
618    | <RelationalExpression> <'<='> <ShiftExpression>
619    | <RelationalExpression> <'>='> <ShiftExpression>
620    | <RelationalExpression> <'instanceof'> <ShiftExpression>
621    | <RelationalExpression> <'in'> <ShiftExpression>
622}
623rule RelationalExpressionNoIn :words {  # see 11.8
624      <ShiftExpression>
625    | <RelationalExpressionNoIn> <'<'> <ShiftExpression>
626    | <RelationalExpressionNoIn> <'>'> <ShiftExpression>
627    | <RelationalExpressionNoIn> <'<='> <ShiftExpression>
628    | <RelationalExpressionNoIn> <'>='> <ShiftExpression>
629    | <RelationalExpressionNoIn> <'instanceof'> <ShiftExpression>
630}
631rule EqualityExpression :words {  # see 11.9
632      <RelationalExpression>
633    | <EqualityExpression> <'=='> <RelationalExpression>
634    | <EqualityExpression> <'!='> <RelationalExpression>
635    | <EqualityExpression> <'==='> <RelationalExpression>
636    | <EqualityExpression> <'!=='> <RelationalExpression>
637}
638rule EqualityExpressionNoIn :words {  # see 11.9
639      <RelationalExpressionNoIn>
640    | <EqualityExpressionNoIn> <'=='> <RelationalExpressionNoIn>
641    | <EqualityExpressionNoIn> <'!='> <RelationalExpressionNoIn>
642    | <EqualityExpressionNoIn> <'==='> <RelationalExpressionNoIn>
643    | <EqualityExpressionNoIn> <'!=='> <RelationalExpressionNoIn>
644}
645rule BitwiseANDExpression :words {  # see 11.10
646      <EqualityExpression>
647    | <BitwiseANDExpression> <'&'> <EqualityExpression>
648}
649rule BitwiseANDExpressionNoIn :words {  # see 11.10
650      <EqualityExpressionNoIn>
651    | <BitwiseANDExpressionNoIn> <'&'> <EqualityExpressionNoIn>
652}
653rule BitwiseXORExpression :words {  # see 11.10
654      <BitwiseANDExpression>
655    | <BitwiseXORExpression> <'^'> <BitwiseANDExpression>
656}
657rule BitwiseXORExpressionNoIn :words {  # see 11.10
658      <BitwiseANDExpressionNoIn>
659    | <BitwiseXORExpressionNoIn> <'^'> <BitwiseANDExpressionNoIn>
660}
661rule BitwiseORExpression :words {  # see 11.10
662      <BitwiseXORExpression>
663    | <BitwiseORExpression> <'|'> <BitwiseXORExpression>
664}
665rule BitwiseORExpressionNoIn :words {  # see 11.10
666      <BitwiseXORExpressionNoIn>
667    | <BitwiseORExpressionNoIn> <'|'> <BitwiseXORExpressionNoIn>
668}
669rule LogicalANDExpression :words {  # see 11.11
670      <BitwiseORExpression>
671    | <LogicalANDExpression> <'&&'> <BitwiseORExpression>
672}
673rule LogicalANDExpressionNoIn :words {  # see 11.11
674      <BitwiseORExpressionNoIn>
675    | <LogicalANDExpressionNoIn> <'&&'> <BitwiseORExpressionNoIn>
676}
677rule LogicalORExpression :words {  # see 11.11
678      <LogicalANDExpression>
679    | <LogicalORExpression> <'||'> <LogicalANDExpression>
680}
681rule LogicalORExpressionNoIn :words {  # see 11.11
682      <LogicalANDExpressionNoIn>
683    | <LogicalORExpressionNoIn> <'||'> <LogicalANDExpressionNoIn>
684}
685rule ConditionalExpression :words {  # see 11.12
686      <LogicalORExpression>
687    | <LogicalORExpression> <'?'> <AssignmentExpression> <':'> <AssignmentExpression>
688}
689rule ConditionalExpressionNoIn :words {  # see 11.12
690      <LogicalORExpressionNoIn>
691    | <LogicalORExpressionNoIn> <'?'> <AssignmentExpressionNoIn> <':'> <AssignmentExpressionNoIn>
692}
693rule AssignmentExpression :words {  # see 11.13
694      <ConditionalExpression>
695    | <LeftHandSideExpression> <AssignmentOperator> <AssignmentExpression>
696}
697rule AssignmentExpressionNoIn :words {  # see 11.13
698      <ConditionalExpressionNoIn>
699    | <LeftHandSideExpression> <AssignmentOperator> <AssignmentExpressionNoIn>
700}
701rule AssignmentOperator :words {  # see 11.13
702      <'='>
703    | <'*='>
704    | <'/='>
705    | <'%='>
706    | <'+='>
707    | <'-='>
708    | <'<<='>
709    | <'>>='>
710    | <'>>>='>
711    | <'&='>
712    | <'^='>
713    | <'|='>
714}
715rule Expression :words {  # see 11.14
716      <AssignmentExpression>
717    | <Expression> <','> <AssignmentExpression>
718}
719rule ExpressionNoIn :words {  # see 11.14
720      <AssignmentExpressionNoIn>
721    | <ExpressionNoIn> <','> <AssignmentExpressionNoIn>
722}
723
724# A.4 Statements
725
726rule Statement :words {  # see clause 12
727      <Block>
728    | <VariableStatement>
729    | <EmptyStatement>
730    | <ExpressionStatement>
731    | <IfStatement>
732    | <IterationStatement>
733    | <ContinueStatement>
734    | <BreakStatement>
735    | <ReturnStatement>
736    | <WithStatement>
737    | <LabelledStatement>
738    | <SwitchStatement>
739    | <ThrowStatement>
740    | <TryStatement>
741}
742rule Block :words {  # see 12.1
743      <'{'> <StatementList>? <'}'>
744}
745rule StatementList :words {  # see 12.1
746      <Statement>
747    | <StatementList> <Statement>
748}
749rule VariableStatement :words {  # see 12.2
750      <'var'> <?ws_required> <VariableDeclarationList> <';'>
751}
752rule VariableDeclarationList :words {  # see 12.2
753      <VariableDeclaration>
754    | <VariableDeclarationList> <','> <VariableDeclaration>
755}
756rule VariableDeclarationListNoIn :words {  # see 12.2
757      <VariableDeclarationNoIn>
758    | <VariableDeclarationListNoIn> <','> <VariableDeclarationNoIn>
759}
760rule VariableDeclaration :words {  # see 12.2
761      <Identifier> <Initialiser>?
762}
763rule VariableDeclarationNoIn :words {  # see 12.2
764      <Identifier> <InitialiserNoIn>?
765}
766rule Initialiser :words {  # see 12.2
767      <'='> <AssignmentExpression>
768}
769rule InitialiserNoIn :words {  # see 12.2
770      <'='> <AssignmentExpressionNoIn>
771}
772rule EmptyStatement :words {  # see 12.3
773      <';'>
774}
775rule ExpressionStatement :words {  # see 12.4
776      <!before <'function'>><Expression> <';'> #lookahead
777}
778rule IfStatement :words {  # see 12.5
779      <'if'> <'('> <Expression> <')'> <Statement> <'else'> <Statement>
780    | <'if'> <'('> <Expression> <')'> <Statement>
781}
782rule IterationStatement :words {  # see 12.6
783      <'do'> <Statement> <'while'> <'('> <Expression> <');'>
784    | <'while'> <'('> <Expression> <')'> <Statement>
785    | <'for'> <'('> <ExpressionNoIn>? <';'> <Expression>? <';'> <Expression>? <')'> <Statement>
786    | <'for'> <'('> <'var'> <VariableDeclarationListNoIn> <';'> <Expression>? <';'> <Expression>? <')'> <Statement>
787    | <'for'> <'('> <LeftHandSideExpression> <'in'> <Expression> <')'> <Statement>
788    | <'for'> <'('> <'var'> <VariableDeclarationNoIn> <'in'> <Expression> <')'> <Statement>
789}
790rule ContinueStatement :words {  # see 12.7
791      <'continue'><no_LineTerminator_here><Identifier>? <';'>
792}
793rule BreakStatement :words {  # see 12.8
794      <'break'><no_LineTerminator_here><Identifier>? <';'>
795}
796rule ReturnStatement :words {  # see 12.9
797      <'return'><no_LineTerminator_here><Expression>? <';'>
798}
799rule WithStatement :words {  # see 12.10
800      <'with'> <'('> <Expression> <')'> <Statement>
801}
802rule SwitchStatement :words {  # see 12.11
803      <'switch'> <'('> <Expression> <')'> <CaseBlock>
804}
805rule CaseBlock :words {  # see 12.11
806      <'{'> <CaseClauses>? <'}'>
807    | <'{'> <CaseClauses>? <DefaultClause> <CaseClauses>? <'}'>
808}
809rule CaseClauses :words {  # see 12.11
810      <CaseClause>
811    | <CaseClauses> <CaseClause>
812}
813rule CaseClause :words {  # see 12.11
814      <'case'> <Expression> <':'> <StatementList>?
815}
816rule DefaultClause :words {  # see 12.11
817      <'default'> <':'> <StatementList>?
818}
819rule LabelledStatement :words {  # see 12.12
820      <Identifier> <':'> <Statement>
821}
822rule ThrowStatement :words {  # see 12.13
823      <'throw'><no_LineTerminator_here><Expression> <';'>
824}
825rule TryStatement :words {  # see 12.14
826      <'try'> <Block> <Catch>
827    | <'try'> <Block> <Finally>
828    | <'try'> <Block> <Catch> <Finally>
829}
830rule Catch :words {  # see 12.14
831      <'catch'> <'('> <Identifier> <')'> <Block>
832}
833rule Finally :words {  # see 12.14
834      <'finally'> <Block>
835}
836
837# A.5 Functions and Programs
838
839rule FunctionDeclaration :words {  # see clause 13
840      <'function'> <Identifier> <'('> <FormalParameterList>? <')'. <'{'> <FunctionBody> <'}'>
841}
842rule FunctionExpression :words {  # see clause 13
843      <'function'> <Identifier>? <'('> <FormalParameterList>? <')'> <'{'> <FunctionBody> <'}'>
844}
845rule FormalParameterList :words {  # see clause 13
846      <Identifier>
847    | <FormalParameterList> <','> <Identifier>
848}
849rule FunctionBody :words {  # see clause 13
850      <SourceElements>
851}
852rule Program :words {  # see clause 14
853      <SourceElements>
854}
855rule SourceElements :words {  # see clause 14
856      <SourceElement>
857    | <SourceElements> <SourceElement>
858}
859rule SourceElement :words {  # see clause 14
860      <Statement> <FunctionDeclaration>
861}
862
863# A.6 Universal Resource Identifier Character Classes
864
865rule uri {  # see 15.1.3
866      <uriCharacters>?
867}
868rule uriCharacters {  # see 15.1.3
869      <uriCharacter> <uriCharacters>?
870}
871rule uriCharacter {  # see 15.1.3
872      <uriReserved>
873    | <uriUnescaped>
874    | <uriEscaped>
875}
876rule uriReserved {  # see 15.1.3
877      <';'>
878    | <'/'>
879    | <'?'>
880    | <':'>
881    | <'@'>
882    | <'&'>
883    | <'='>
884    | <'+'>
885    | <'$'>
886    | <','>
887}
888rule uriUnescaped {  # see 15.1.3
889      <uriAlpha>
890    | <DecimalDigit>
891    | <uriMark>
892}
893rule uriEscaped {  # see 15.1.3
894      <'%'> <HexDigit> <HexDigit>
895}
896rule uriAlpha {  # see 15.1.3
897      <[a..zA..Z]>
898}
899rule uriMark {  # see 15.1.3
900      <'-'>
901    | <'_'>
902    | <'.'>
903    | <'!'>
904    | <'~'>
905    | <'*'>
906    | <'\''>
907    | <'('>
908    | <')'>
909}
910
911# A.7 Regular Expressions
912
913rule Pattern {  # see 15.10.1
914      <Disjunction>
915}
916rule Disjunction {  # see 15.10.1
917      <Alternative>
918    | <Alternative> <'|'> <Disjunction>
919}
920rule Alternative {  # see 15.10.1
921      <null>
922    | <Alternative> <Term>
923}
924rule Term {  # see 15.10.1
925      <Assertion>
926    | <Atom>
927    | <Atom> <Quantifier>
928}
929rule Assertion {  # see 15.10.1
930      <'^'>
931    | <'$'>
932    | <'\\'> <'b'>
933    | <'\\'> <'B'>
934}
935rule Quantifier {  # see 15.10.1
936      <QuantifierPrefix>
937    | <QuantifierPrefix> <'?'>
938}
939rule QuantifierPrefix {  # see 15.10.1
940      <'*'>
941    | <'+'>
942    | <'?'>
943    | <'{'> <DecimalDigits> <'}'>
944    | <'{'> <DecimalDigits> <',}'>
945    | <'{'> <DecimalDigits> <','> <DecimalDigits> <'}'>
946}
947rule Atom {  # see 15.10.1
948      <PatternCharacter>
949    | <'.'>
950    | <'\\'> <AtomEscape>
951    | <CharacterClass>
952    | <'('> <Disjunction> <')'>
953    | <'(?:'> <Disjunction> <')'>
954    | <'(?='> <Disjunction> <')'>
955    | <'(?!'> <Disjunction> <')'>
956}
957rule PatternCharacter {  # see 15.10.1
958      <-[^$\\.*+?()[\]{}|]> #SourceCharacter but not ...
959}
960rule AtomEscape {  # see 15.10.1
961      <DecimalEscape>
962    | <CharacterEscape>
963    | <CharacterClassEscape>
964}
965rule CharacterEscape {  # see 15.10.1
966      <ControlEscape>
967    | <'c'> <ControlLetter>
968    | <HexEscapeSequence>
969    | <UnicodeEscapeSequence>
970    | <IdentityEscape>
971}
972rule ControlEscape {  # see 15.10.1
973      <'f'>
974    | <'n'>
975    | <'r'>
976    | <'t'>
977    | <'v'>
978}
979rule ControlLetter {  # see 15.10.1
980      <[a..zA..Z]>
981}
982rule IdentityEscape {  # see 15.10.1
983      <!before <IdentifierPart>> <SourceCharacter>
984}
985rule DecimalEscape {  # see 15.10.1
986      <DecimalIntegerLiteral> <!before <DecimalDigit>> #lookahead
987}
988rule CharacterClass {  # see 15.10.1
989      <'['> <!before <'^'>> <ClassRanges> <']'> #lookahead
990    | <'[^'> <ClassRanges> <']'>
991}
992rule ClassRanges {  # see 15.10.1
993      <null>
994    | <NonemptyClassRanges>
995}
996rule NonemptyClassRanges {  # see 15.10.1
997      <ClassAtom>
998    | <ClassAtom> <NonemptyClassRangesNoDash>
999    | <ClassAtom> <'-'> <ClassAtom> <ClassRanges>
1000}
1001rule NonemptyClassRangesNoDash {  # see 15.10.1
1002      <ClassAtom>
1003    | <ClassAtomNoDash> <NonemptyClassRangesNoDash>
1004    | <ClassAtomNoDash> <'-'> <ClassAtom> <ClassRanges>
1005}
1006rule ClassAtom {  # see 15.10.1
1007      <'-'>
1008    | <ClassAtomNoDash>
1009}
1010rule ClassAtomNoDash {  # see 15.10.1
1011      <-[\\\]\-]> #SourceCharacter but not ...
1012    | <'\\'>
1013    | <ClassEscape>
1014}
1015rule ClassEscape {  # see 15.10.1
1016      <DecimalEscape>
1017    | <'b'>
1018    | <CharacterEscape>
1019    | <CharacterClassEscape>
1020}
1021
1022
1023
1024grammar JavaScript::ECMAScript3::Grammar is JavaScript::ECMAScript3::Grammar::Spec;
1025
1026# Intended to be a working, usable grammar.
1027# Unimplemented.
Note: See TracBrowser for help on using the browser.