1 ;;; javascript-jv.wy -- LALR grammar for Javascript
3 ;; Copyright (C) 2005-2011 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 ;; JAVE I prefere ecmascript-mode
62 %languagemode ecmascript-mode javascript-mode
67 %start FormalParameterList
69 ;; with the terminals stuff, I used the javacript.y names,
70 ;; but the semantic/wisent/java-tags.wy types
76 ;;define-lex-string-type-analyzer gets called with the "syntax" comment
77 %type <punctuation> ;;syntax "\\(\\s.\\|\\s$\\|\\s'\\)+" matchdatatype string
79 %token <punctuation> ASSIGN_SYMBOL "="
80 %token <punctuation> BITWISE_AND "&"
81 %token <punctuation> BITWISE_AND_EQUALS "&="
82 %token <punctuation> BITWISE_EXCLUSIVE_OR "^"
83 %token <punctuation> BITWISE_EXCLUSIVE_OR_EQUALS "^="
84 %token <punctuation> BITWISE_OR "|"
85 %token <punctuation> BITWISE_OR_EQUALS "|="
86 %token <punctuation> BITWISE_SHIFT_LEFT "<<"
87 %token <punctuation> BITWISE_SHIFT_LEFT_EQUALS "<<="
88 %token <punctuation> BITWISE_SHIFT_RIGHT ">>"
89 %token <punctuation> BITWISE_SHIFT_RIGHT_EQUALS ">>="
90 %token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL ">>>"
91 %token <punctuation> BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS ">>>="
92 %token <punctuation> NOT_EQUAL "!="
93 %token <punctuation> DIV_EQUALS "/="
94 %token <punctuation> EQUALS "=="
95 %token <punctuation> GREATER_THAN ">"
96 %token <punctuation> GT_EQUAL ">="
97 %token <punctuation> LOGICAL_AND "&&"
98 %token <punctuation> LOGICAL_OR "||"
99 %token <punctuation> LOGICAL_NOT "!!"
100 %token <punctuation> LS_EQUAL "<="
101 %token <punctuation> MINUS "-"
102 %token <punctuation> MINUS_EQUALS "-="
103 %token <punctuation> MOD "%"
104 %token <punctuation> MOD_EQUALS "%="
105 %token <punctuation> MULTIPLY "*"
106 %token <punctuation> MULTIPLY_EQUALS "*="
107 %token <punctuation> PLUS "+"
108 %token <punctuation> PLUS_EQUALS "+="
109 %token <punctuation> INCREMENT "++"
110 %token <punctuation> DECREMENT "--"
111 %token <punctuation> DIV "/"
112 %token <punctuation> COLON ":"
113 %token <punctuation> COMMA ","
114 %token <punctuation> DOT "."
115 %token <punctuation> LESS_THAN "<"
116 %token <punctuation> LINE_TERMINATOR "\n"
117 %token <punctuation> SEMICOLON ";"
118 %token <punctuation> ONES_COMPLIMENT "~"
121 ;; -----------------------------
122 ;; Block & Parenthesis terminals
123 ;; -----------------------------
124 %type <block> ;;syntax "\\s(\\|\\s)" matchdatatype block
125 %token <block> PAREN_BLOCK "(OPEN_PARENTHESIS CLOSE_PARENTHESIS)"
126 %token <block> BRACE_BLOCK "(START_BLOCK END_BLOCK)"
127 %token <block> BRACK_BLOCK "(OPEN_SQ_BRACKETS CLOSE_SQ_BRACKETS)"
129 %token <open-paren> OPEN_PARENTHESIS "("
130 %token <close-paren> CLOSE_PARENTHESIS ")"
132 %token <open-paren> START_BLOCK "{"
133 %token <close-paren> END_BLOCK "}"
135 %token <open-paren> OPEN_SQ_BRACKETS "["
136 %token <close-paren> CLOSE_SQ_BRACKETS "]"
143 ;; Generate a keyword analyzer
144 %type <keyword> ;;syntax "\\(\\sw\\|\\s_\\)+" matchdatatype keyword
148 "if (<expr>) <stmt> [else <stmt>] (jv)"
150 %keyword BREAK "break"
154 %keyword CONTINUE "continue"
155 %put CONTINUE summary
156 "continue [<label>] ;"
160 "if (<expr>) <stmt> else <stmt>"
165 "for ([<init-expr>]; [<expr>]; [<update-expr>]) <stmt>"
168 %keyword FUNCTION "function"
169 %put FUNCTION summary
170 "function declaration blah blah"
177 %keyword RETURN "return"
181 %keyword WHILE "while"
183 "while (<expr>) <stmt> | do <stmt> while (<expr>);"
185 %keyword VOID_SYMBOL "void"
186 %put VOID_SYMBOL summary
187 "Method return type: void <name> ..."
193 "new <objecttype> - Creates a new object."
195 %keyword DELETE "delete"
197 "delete(<objectreference>) - Deletes the object."
201 "var <variablename> [= value];"
207 %keyword TYPEOF "typeof"
220 ;;the .y file uses VARIABLE as IDENTIFIER, which seems a bit evil
221 ;; it think the normal .wy convention is better than this
222 %type <symbol> ;;syntax "\\(\\sw\\|\\s_\\)+"
223 %token <symbol> VARIABLE
225 %type <string> ;;syntax "\\s\"" matchdatatype sexp
226 %token <string> STRING
228 %type <number> ;;syntax semantic-lex-number-expression
229 %token <number> NUMBER
239 ;;%token UNDEFINED_TOKEN
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243 ;; associativity and stuff
245 %left MULTIPLY DIV MOD
248 %nonassoc HIGHER_THAN_FALSE
250 %nonassoc LOWER_THAN_CLOSE_PARENTHESIS
251 %nonassoc CLOSE_PARENTHESIS
255 Program : SourceElement
258 SourceElement : Statement
259 | FunctionDeclaration
265 | ExpressionStatement
267 | IterationExpression
274 FunctionDeclaration : FUNCTION VARIABLE FormalParameterListBlock Block
275 (FUNCTION-TAG $2 nil $3)
278 FormalParameterListBlock : PAREN_BLOCK
279 (EXPANDFULL $1 FormalParameterList)
282 FormalParameterList: OPEN_PARENTHESIS
285 (VARIABLE-TAG $1 nil nil)
292 StatementList : Statement
293 | StatementList Statement
297 ;; If you want to parse the body of the function
298 ;; ( EXPANDFULL $1 BlockExpand )
301 BlockExpand: START_BLOCK StatementList END_BLOCK
302 | START_BLOCK END_BLOCK
305 VariableStatement : VAR VariableDeclarationList SEMICOLON
306 (VARIABLE-TAG $2 nil nil)
309 VariableDeclarationList : VariableDeclaration
311 | VariableDeclarationList COMMA VariableDeclaration
312 (append $1 (list $3))
315 VariableDeclaration : VARIABLE
316 (append (list $1 nil) $region)
317 | VARIABLE Initializer
318 (append (cons $1 $2) $region)
321 Initializer : ASSIGN_SYMBOL AssignmentExpression
325 EmptyStatement : SEMICOLON
328 ExpressionStatement : Expression SEMICOLON
331 IfStatement : IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
332 | IF OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement ELSE Statement
333 | IF OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
334 | IF OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
337 IterationExpression : WHILE OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement %prec HIGHER_THAN_FALSE
338 | WHILE OPEN_PARENTHESIS FALSE CLOSE_PARENTHESIS Statement
339 | WHILE OPEN_PARENTHESIS LeftHandSideExpression AssignmentOperator AssignmentExpression CLOSE_PARENTHESIS Statement
340 | FOR OPEN_PARENTHESIS OptionalExpression SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
341 | FOR OPEN_PARENTHESIS VAR VariableDeclarationList SEMICOLON OptionalExpression SEMICOLON OptionalExpression CLOSE_PARENTHESIS Statement
342 | FOR OPEN_PARENTHESIS LeftHandSideExpression IN Expression CLOSE_PARENTHESIS Statement
343 | FOR OPEN_PARENTHESIS VAR VARIABLE OptionalInitializer IN Expression CLOSE_PARENTHESIS Statement
346 ContinueStatement : CONTINUE SEMICOLON
349 ;;JAVE break needs labels
350 BreakStatement : BREAK SEMICOLON
351 ;; | BREAK identifier SEMICOLON
354 ReturnStatement : RETURN Expression SEMICOLON
358 WithStatement : WITH OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS Statement
361 OptionalInitializer : Initializer
365 PrimaryExpression : THIS
372 | OPEN_PARENTHESIS Expression CLOSE_PARENTHESIS
375 MemberExpression : PrimaryExpression
376 | MemberExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
377 | MemberExpression DOT VARIABLE
378 | NEW MemberExpression Arguments
381 NewExpression : MemberExpression
385 CallExpression : MemberExpression Arguments
386 | CallExpression Arguments
387 | CallExpression OPEN_SQ_BRACKETS Expression CLOSE_SQ_BRACKETS
388 | CallExpression DOT VARIABLE
391 Arguments : OPEN_PARENTHESIS CLOSE_PARENTHESIS
392 | OPEN_PARENTHESIS ArgumentList CLOSE_PARENTHESIS
395 ArgumentList : AssignmentExpression
396 | ArgumentList COMMA AssignmentExpression
399 LeftHandSideExpression : NewExpression
403 PostfixExpression : LeftHandSideExpression
404 | LeftHandSideExpression INCREMENT
405 | LeftHandSideExpression DECREMENT
408 UnaryExpression : PostfixExpression
409 | DELETE UnaryExpression
410 | VOID_SYMBOL UnaryExpression
411 | TYPEOF UnaryExpression
412 | INCREMENT UnaryExpression
413 | DECREMENT UnaryExpression
414 | PLUS UnaryExpression
415 | MINUS UnaryExpression
416 | ONES_COMPLIMENT UnaryExpression
417 | LOGICAL_NOT UnaryExpression
420 MultiplicativeExpression : UnaryExpression
421 | MultiplicativeExpression MULTIPLY UnaryExpression
422 | MultiplicativeExpression DIV UnaryExpression
423 | MultiplicativeExpression MOD UnaryExpression
426 AdditiveExpression : MultiplicativeExpression
427 | AdditiveExpression PLUS MultiplicativeExpression
428 | AdditiveExpression MINUS MultiplicativeExpression
431 ShiftExpression : AdditiveExpression
432 | ShiftExpression BITWISE_SHIFT_LEFT AdditiveExpression
433 | ShiftExpression BITWISE_SHIFT_RIGHT AdditiveExpression
434 | ShiftExpression BITWISE_SHIFT_RIGHT_ZERO_FILL AdditiveExpression
437 RelationalExpression : ShiftExpression
438 | RelationalExpression LESS_THAN ShiftExpression
439 | RelationalExpression GREATER_THAN ShiftExpression
440 | RelationalExpression LS_EQUAL ShiftExpression
441 | RelationalExpression GT_EQUAL ShiftExpression
444 EqualityExpression : RelationalExpression
445 | EqualityExpression EQUALS RelationalExpression
446 | EqualityExpression NOT_EQUAL RelationalExpression
449 BitwiseANDExpression : EqualityExpression
450 | BitwiseANDExpression BITWISE_AND EqualityExpression
453 BitwiseXORExpression : BitwiseANDExpression
454 | BitwiseXORExpression BITWISE_EXCLUSIVE_OR BitwiseANDExpression
457 BitwiseORExpression : BitwiseXORExpression
458 | BitwiseORExpression BITWISE_OR BitwiseXORExpression
461 LogicalANDExpression : BitwiseORExpression
462 | LogicalANDExpression LOGICAL_AND BitwiseORExpression
465 LogicalORExpression : LogicalANDExpression
466 | LogicalORExpression LOGICAL_OR LogicalANDExpression
469 ConditionalExpression : LogicalORExpression
470 | LogicalORExpression QUERY AssignmentExpression COLON AssignmentExpression
473 AssignmentExpression : ConditionalExpression
474 | LeftHandSideExpression AssignmentOperator AssignmentExpression %prec LOWER_THAN_CLOSE_PARENTHESIS
477 AssignmentOperator : ASSIGN_SYMBOL
483 | BITWISE_SHIFT_LEFT_EQUALS
484 | BITWISE_SHIFT_RIGHT_EQUALS
485 | BITWISE_SHIFT_RIGHT_ZERO_FILL_EQUALS
487 | BITWISE_EXCLUSIVE_OR_EQUALS
491 Expression : AssignmentExpression
492 | Expression COMMA AssignmentExpression
495 OptionalExpression : Expression
501 ;;here something like:
502 ;;(define-lex wisent-java-tags-lexer
504 (define-lex javascript-lexer-jv
507 semantic-lex-ignore-whitespace
508 semantic-lex-ignore-newline
509 semantic-lex-ignore-comments
511 ;;stuff generated from the wy file(one for each "type" declaration)
512 wisent-javascript-jv-wy--<number>-regexp-analyzer
513 wisent-javascript-jv-wy--<string>-sexp-analyzer
515 wisent-javascript-jv-wy--<keyword>-keyword-analyzer
517 wisent-javascript-jv-wy--<symbol>-regexp-analyzer
518 wisent-javascript-jv-wy--<punctuation>-string-analyzer
519 wisent-javascript-jv-wy--<block>-block-analyzer
523 semantic-lex-default-action
526 ;;; javascript-jv.wy ends here