1 ;;; javascript-jv.wy -- LALR grammar for Javascript
3 ;; Copyright (C) 2005-2014 Free Software Foundation, Inc.
4 ;; Copyright (C) 1998-2011 Ecma International.
6 ;; Author: Joakim Verona
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; The grammar itself is transcribed from the ECMAScript Language
26 ;; Specification published at
28 ;; http://www.ecma-international.org/publications/standards/Ecma-262.htm
30 ;; and redistributed under the following license:
32 ;; Redistribution and use in source and binary forms, with or without
33 ;; modification, are permitted provided that the following conditions
36 ;; 1. Redistributions of source code must retain the above copyright
37 ;; notice, this list of conditions and the following disclaimer.
39 ;; 2. Redistributions in binary form must reproduce the above
40 ;; copyright notice, this list of conditions and the following
41 ;; disclaimer in the documentation and/or other materials provided
42 ;; with the distribution.
44 ;; 3. Neither the name of the authors nor Ecma International may be
45 ;; used to endorse or promote products derived from this software
46 ;; without specific prior written permission. THIS SOFTWARE IS
47 ;; PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR
48 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
49 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 ;; ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR
51 ;; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
53 ;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
54 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
55 ;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
57 ;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
60 %package wisent-javascript-jv-wy
61 %provide semantic/wisent/js-wy
64 (declare-function semantic-parse-region "semantic"
65 (start end &optional nonterminal depth returnonerror))
68 ;; JAVE I preferred ecmascript-mode.
69 %languagemode ecmascript-mode javascript-mode
74 %start FormalParameterList
76 ;; with the terminals stuff, I used the javascript.y names,
77 ;; but the semantic/wisent/java-tags.wy types
83 ;;define-lex-string-type-analyzer gets called with the "syntax" comment
84 %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
86 %token <punctuation> ASSIGN_SYMBOL "="
87 %token <punctuation> BITWISE_AND "&"
88 %token <punctuation> BITWISE_AND_EQUALS "&="
89 %token <punctuation> BITWISE_EXCLUSIVE_OR "^"
90 %token <punctuation> BITWISE_EXCLUSIVE_OR_EQUALS "^="
91 %token <punctuation> BITWISE_OR "|"
92 %token <punctuation> BITWISE_OR_EQUALS "|="
93 %token <punctuation> BITWISE_SHIFT_LEFT "<<"
94 %token <punctuation> BITWISE_SHIFT_LEFT_EQUALS "<<="
95 %token <punctuation> BITWISE_SHIFT_RIGHT ">>"
96 %token <punctuation> BITWISE_SHIFT_RIGHT_EQUALS ">>="
97 %token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL ">>>"
98 %token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS ">>>="
99 %token <punctuation> NOT_EQUAL "!="
100 %token <punctuation> DIV_EQUALS "/="
101 %token <punctuation> EQUALS "=="
102 %token <punctuation> GREATER_THAN ">"
103 %token <punctuation> GT_EQUAL ">="
104 %token <punctuation> LOGICAL_AND "&&"
105 %token <punctuation> LOGICAL_OR "||"
106 %token <punctuation> LOGICAL_NOT "!!"
107 %token <punctuation> LS_EQUAL "<="
108 %token <punctuation> MINUS "-"
109 %token <punctuation> MINUS_EQUALS "-="
110 %token <punctuation> MOD "%"
111 %token <punctuation> MOD_EQUALS "%="
112 %token <punctuation> MULTIPLY "*"
113 %token <punctuation> MULTIPLY_EQUALS "*="
114 %token <punctuation> PLUS "+"
115 %token <punctuation> PLUS_EQUALS "+="
116 %token <punctuation> INCREMENT "++"
117 %token <punctuation> DECREMENT "--"
118 %token <punctuation> DIV "/"
119 %token <punctuation> COLON ":"
120 %token <punctuation> COMMA ","
121 %token <punctuation> DOT "."
122 %token <punctuation> LESS_THAN "<"
123 %token <punctuation> LINE_TERMINATOR "\n"
124 %token <punctuation> SEMICOLON ";"
125 %token <punctuation> ONES_COMPLIMENT "~"
128 ;; -----------------------------
129 ;; Block & Parenthesis terminals
130 ;; -----------------------------
131 %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
132 %token <block> PAREN_BLOCK "(OPEN_PARENTHESIS CLOSE_PARENTHESIS)"
133 %token <block> BRACE_BLOCK "(START_BLOCK END_BLOCK)"
134 %token <block> BRACK_BLOCK "(OPEN_SQ_BRACKETS CLOSE_SQ_BRACKETS)"
136 %token <open-paren> OPEN_PARENTHESIS "("
137 %token <close-paren> CLOSE_PARENTHESIS ")"
139 %token <open-paren> START_BLOCK "{"
140 %token <close-paren> END_BLOCK "}"
142 %token <open-paren> OPEN_SQ_BRACKETS "["
143 %token <close-paren> CLOSE_SQ_BRACKETS "]"
150 ;; Generate a keyword analyzer
151 %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
155 "if (<expr>) <stmt> [else <stmt>] (jv)"
157 %keyword BREAK "break"
161 %keyword CONTINUE "continue"
162 %put CONTINUE summary
163 "continue [<label>] ;"
167 "if (<expr>) <stmt> else <stmt>"
172 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
175 %keyword FUNCTION "function"
176 %put FUNCTION summary
177 "function declaration blah blah"
184 %keyword RETURN "return"
188 %keyword WHILE "while"
190 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
192 %keyword VOID_SYMBOL "void"
193 %put VOID_SYMBOL summary
194 "Method return type: void <name> ..."
200 "new <objecttype> - Creates a new object."
202 %keyword DELETE "delete"
204 "delete(<objectreference>) - Deletes the object."
208 "var <variablename> [= value];"
214 %keyword TYPEOF "typeof"
227 ;;the .y file uses VARIABLE as IDENTIFIER, which seems a bit evil
228 ;; it think the normal .wy convention is better than this
229 %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
230 %token <symbol> VARIABLE
232 %type <string> ;;syntax "\\s\"" matchdatatype sexp
233 %token <string> STRING
235 %type <number> ;;syntax semantic-lex-number-expression
236 %token <number> NUMBER
246 ;;%token UNDEFINED_TOKEN
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250 ;; associativity and stuff
252 %left MULTIPLY DIV MOD
255 %nonassoc HIGHER_THAN_FALSE
257 %nonassoc LOWER_THAN_CLOSE_PARENTHESIS
258 %nonassoc CLOSE_PARENTHESIS
262 Program : SourceElement
265 SourceElement : Statement
266 | FunctionDeclaration
272 | ExpressionStatement
274 | IterationExpression
281 FunctionDeclaration : FUNCTION VARIABLE FormalParameterListBlock Block
282 (FUNCTION-TAG $2 nil $3)
285 FormalParameterListBlock : PAREN_BLOCK
286 (EXPANDFULL $1 FormalParameterList)
289 FormalParameterList: OPEN_PARENTHESIS
292 (VARIABLE-TAG $1 nil nil)
299 StatementList : Statement
300 | StatementList Statement
304 ;; If you want to parse the body of the function
305 ;; ( EXPANDFULL $1 BlockExpand )
308 BlockExpand: START_BLOCK StatementList END_BLOCK
309 | START_BLOCK END_BLOCK
312 VariableStatement : VAR VariableDeclarationList SEMICOLON
313 (VARIABLE-TAG $2 nil nil)
316 VariableDeclarationList : VariableDeclaration
318 | VariableDeclarationList COMMA VariableDeclaration
319 (append $1 (list $3))
322 VariableDeclaration : VARIABLE
323 (append (list $1 nil) $region)
324 | VARIABLE Initializer
325 (append (cons $1 $2) $region)
328 Initializer : ASSIGN_SYMBOL AssignmentExpression
332 EmptyStatement : SEMICOLON
335 ExpressionStatement : Expression SEMICOLON
338 IfStatement : IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
339 | IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement ELSE Statement
340 | IF OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
341 | IF OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
344 IterationExpression : WHILE OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
345 | WHILE OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
346 | WHILE OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
347 | FOR OPEN_PARENTHESIS OptionalExpression SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
348 | FOR OPEN_PARENTHESIS VAR VariableDeclarationList SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
349 | FOR OPEN_PARENTHESIS LeftHandSideExpression IN Expression CLOSE_PARENTHESIS Statement
350 | FOR OPEN_PARENTHESIS VAR VARIABLE OptionalInitializer IN Expression CLOSE_PARENTHESIS Statement
353 ContinueStatement : CONTINUE SEMICOLON
356 ;;JAVE break needs labels
357 BreakStatement : BREAK SEMICOLON
358 ;; | BREAK identifier SEMICOLON
361 ReturnStatement : RETURN Expression SEMICOLON
365 WithStatement : WITH OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement
368 OptionalInitializer : Initializer
372 PrimaryExpression : THIS
379 | OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS
382 MemberExpression : PrimaryExpression
383 | MemberExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
384 | MemberExpression DOT VARIABLE
385 | NEW MemberExpression Arguments
388 NewExpression : MemberExpression
392 CallExpression : MemberExpression Arguments
393 | CallExpression Arguments
394 | CallExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
395 | CallExpression DOT VARIABLE
398 Arguments : OPEN_PARENTHESIS CLOSE_PARENTHESIS
399 | OPEN_PARENTHESIS ArgumentList CLOSE_PARENTHESIS
402 ArgumentList : AssignmentExpression
403 | ArgumentList COMMA AssignmentExpression
406 LeftHandSideExpression : NewExpression
410 PostfixExpression : LeftHandSideExpression
411 | LeftHandSideExpression INCREMENT
412 | LeftHandSideExpression DECREMENT
415 UnaryExpression : PostfixExpression
416 | DELETE UnaryExpression
417 | VOID_SYMBOL UnaryExpression
418 | TYPEOF UnaryExpression
419 | INCREMENT UnaryExpression
420 | DECREMENT UnaryExpression
421 | PLUS UnaryExpression
422 | MINUS UnaryExpression
423 | ONES_COMPLIMENT UnaryExpression
424 | LOGICAL_NOT UnaryExpression
427 MultiplicativeExpression : UnaryExpression
428 | MultiplicativeExpression MULTIPLY UnaryExpression
429 | MultiplicativeExpression DIV UnaryExpression
430 | MultiplicativeExpression MOD UnaryExpression
433 AdditiveExpression : MultiplicativeExpression
434 | AdditiveExpression PLUS MultiplicativeExpression
435 | AdditiveExpression MINUS MultiplicativeExpression
438 ShiftExpression : AdditiveExpression
439 | ShiftExpression BITWISE_SHIFT_LEFT AdditiveExpression
440 | ShiftExpression BITWISE_SHIFT_RIGHT AdditiveExpression
441 | ShiftExpression BITWISE_SHIFT_RIGHT_ZERO_FILL AdditiveExpression
444 RelationalExpression : ShiftExpression
445 | RelationalExpression LESS_THAN ShiftExpression
446 | RelationalExpression GREATER_THAN ShiftExpression
447 | RelationalExpression LS_EQUAL ShiftExpression
448 | RelationalExpression GT_EQUAL ShiftExpression
451 EqualityExpression : RelationalExpression
452 | EqualityExpression EQUALS RelationalExpression
453 | EqualityExpression NOT_EQUAL RelationalExpression
456 BitwiseANDExpression : EqualityExpression
457 | BitwiseANDExpression BITWISE_AND EqualityExpression
460 BitwiseXORExpression : BitwiseANDExpression
461 | BitwiseXORExpression BITWISE_EXCLUSIVE_OR BitwiseANDExpression
464 BitwiseORExpression : BitwiseXORExpression
465 | BitwiseORExpression BITWISE_OR BitwiseXORExpression
468 LogicalANDExpression : BitwiseORExpression
469 | LogicalANDExpression LOGICAL_AND BitwiseORExpression
472 LogicalORExpression : LogicalANDExpression
473 | LogicalORExpression LOGICAL_OR LogicalANDExpression
476 ConditionalExpression : LogicalORExpression
477 | LogicalORExpression QUERY AssignmentExpression COLON AssignmentExpression
480 AssignmentExpression : ConditionalExpression
481 | LeftHandSideExpression AssignmentOperator AssignmentExpression %prec LOWER_THAN_CLOSE_PARENTHESIS
484 AssignmentOperator : ASSIGN_SYMBOL
490 | BITWISE_SHIFT_LEFT_EQUALS
491 | BITWISE_SHIFT_RIGHT_EQUALS
492 | BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS
494 | BITWISE_EXCLUSIVE_OR_EQUALS
498 Expression : AssignmentExpression
499 | Expression COMMA AssignmentExpression
502 OptionalExpression : Expression
508 ;;here something like:
509 ;;(define-lex wisent-java-tags-lexer
511 (define-lex javascript-lexer-jv
514 semantic-lex-ignore-whitespace
515 semantic-lex-ignore-newline
516 semantic-lex-ignore-comments
518 ;;stuff generated from the wy file(one for each "type" declaration)
519 wisent-javascript-jv-wy--<number>-regexp-analyzer
520 wisent-javascript-jv-wy--<string>-sexp-analyzer
522 wisent-javascript-jv-wy--<keyword>-keyword-analyzer
524 wisent-javascript-jv-wy--<symbol>-regexp-analyzer
525 wisent-javascript-jv-wy--<punctuation>-string-analyzer
526 wisent-javascript-jv-wy--<block>-block-analyzer
530 semantic-lex-default-action
533 ;;; javascript-jv.wy ends here