This commit is contained in:
waldemar%netscape.com 1999-02-06 03:21:09 +00:00
Родитель 685711e0ef
Коммит 951d8be6cf
8 изменённых файлов: 1142 добавлений и 0 удалений

Просмотреть файл

Просмотреть файл

477
js/semantics/JS20.lisp Normal file
Просмотреть файл

@ -0,0 +1,477 @@
;;; The contents of this file are subject to the Netscape Public License
;;; Version 1.0 (the "NPL"); you may not use this file except in
;;; compliance with the NPL. You may obtain a copy of the NPL at
;;; http://www.mozilla.org/NPL/
;;;
;;; Software distributed under the NPL is distributed on an "AS IS" basis,
;;; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
;;; for the specific language governing rights and limitations under the
;;; NPL.
;;;
;;; The Initial Developer of this code under the NPL is Netscape
;;; Communications Corporation. Portions created by Netscape are
;;; Copyright (C) 1999 Netscape Communications Corporation. All Rights
;;; Reserved.
;;;
;;; Sample JavaScript 2.0 grammar
;;;
;;; Waldemar Horwat (waldemar@netscape.com)
;;;
(declaim (optimize (debug 3)))
(progn
(defparameter *jw*
(generate-world
"J"
'((grammar code-grammar :lr-1 :program)
(%section "Expressions")
(grammar-argument :alpha normal initial no-in)
(grammar-argument :alpha_2 normal initial)
(grammar-argument :alpha_e normal no-in)
(%subsection "Primary Expressions")
(production (:primary-expression :alpha_2) (:simple-expression) primary-expression-simple-expression)
(production (:primary-expression normal) (:function-expression) primary-expression-function-expression)
(production (:primary-expression normal) (:object-literal) primary-expression-object-literal)
(production :simple-expression (this) simple-expression-this)
(production :simple-expression (null) simple-expression-null)
(production :simple-expression (true) simple-expression-true)
(production :simple-expression (false) simple-expression-false)
(production :simple-expression ($number) simple-expression-number)
(production :simple-expression ($string) simple-expression-string)
(production :simple-expression ($identifier) simple-expression-identifier)
(production :simple-expression ($regular-expression) simple-expression-regular-expression)
(production :simple-expression (:parenthesized-expression) simple-expression-parenthesized-expression)
(production :simple-expression (:array-literal) simple-expression-array-literal)
(production :parenthesized-expression (\( (:expression normal) \)) parenthesized-expression-expression)
(%subsection "Function Expressions")
(production :function-expression (:anonymous-function) function-expression-anonymous-function)
(production :function-expression (:named-function) function-expression-named-function)
(%subsection "Object Literals")
(production :object-literal (\{ \}) object-literal-empty)
(production :object-literal (\{ :field-list \}) object-literal-list)
(production :field-list (:literal-field) field-list-one)
(production :field-list (:field-list \, :literal-field) field-list-more)
(production :literal-field ($identifier \: (:assignment-expression normal)) literal-field-assignment-expression)
(%subsection "Array Literals")
(production :array-literal ([ ]) array-literal-empty)
(production :array-literal ([ :element-list ]) array-literal-list)
(production :element-list (:literal-element) element-list-one)
(production :element-list (:element-list \, :literal-element) element-list-more)
(production :literal-element ((:assignment-expression normal)) literal-element-assignment-expression)
(%subsection "Left-Side Expressions")
(grammar-argument :chi allow-calls no-calls)
(production (:member-expression :alpha_2 no-calls) ((:primary-expression :alpha_2)) member-expression-primary-expression)
(production (:member-expression :alpha_2 allow-calls) ((:member-expression :alpha_2 no-calls) :arguments) call-expression-call-member-expression)
(production (:member-expression :alpha_2 allow-calls) ((:member-expression :alpha_2 allow-calls) :arguments) call-expression-call-call-expression)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) [ ]) member-expression-array-declaration)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) [ (:expression normal) ]) member-expression-array)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) \. $identifier) member-expression-property)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) \. :parenthesized-expression) member-expression-indirect-property)
(production (:member-expression :alpha_2 no-calls) (new (:member-expression normal no-calls) :arguments) member-expression-new)
(production (:new-expression :alpha_2) ((:member-expression :alpha_2 no-calls)) new-expression-member-expression)
(production (:new-expression :alpha_2) (new (:new-expression normal)) new-expression-new)
(production :arguments (\( \)) arguments-empty)
(production :arguments (\( :argument-list \)) arguments-list)
(production :argument-list ((:assignment-expression normal)) argument-list-one)
(production :argument-list (:argument-list \, (:assignment-expression normal)) argument-list-more)
(production (:left-side-expression :alpha_2) ((:new-expression :alpha_2)) left-side-expression-new-expression)
(production (:left-side-expression :alpha_2) ((:member-expression :alpha_2 allow-calls)) left-side-expression-call-expression)
(%subsection "Postfix Expressions")
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2)) postfix-expression-left-side-expression)
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2) ++) postfix-expression-increment)
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2) --) postfix-expression-decrement)
(%subsection "Unary Operators")
(production (:unary-expression :alpha_2) ((:postfix-expression :alpha_2)) unary-expression-postfix)
(production (:unary-expression :alpha_2) (delete (:left-side-expression normal)) unary-expression-delete)
(production (:unary-expression :alpha_2) (void (:unary-expression normal)) unary-expression-void)
(production (:unary-expression :alpha_2) (typeof (:unary-expression normal)) unary-expression-typeof)
(production (:unary-expression :alpha_2) (++ (:left-side-expression normal)) unary-expression-increment)
(production (:unary-expression :alpha_2) (-- (:left-side-expression normal)) unary-expression-decrement)
(production (:unary-expression :alpha_2) (+ (:unary-expression normal)) unary-expression-plus)
(production (:unary-expression :alpha_2) (- (:unary-expression normal)) unary-expression-minus)
(production (:unary-expression :alpha_2) (~ (:unary-expression normal)) unary-expression-bitwise-not)
(production (:unary-expression :alpha_2) (! (:unary-expression normal)) unary-expression-logical-not)
(%subsection "Multiplicative Operators")
(production (:multiplicative-expression :alpha_2) ((:unary-expression :alpha_2)) multiplicative-expression-unary)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) * (:unary-expression normal)) multiplicative-expression-multiply)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) / (:unary-expression normal)) multiplicative-expression-divide)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) % (:unary-expression normal)) multiplicative-expression-remainder)
(%subsection "Additive Operators")
(production (:additive-expression :alpha_2) ((:multiplicative-expression :alpha_2)) additive-expression-multiplicative)
(production (:additive-expression :alpha_2) ((:additive-expression :alpha_2) + (:multiplicative-expression normal)) additive-expression-add)
(production (:additive-expression :alpha_2) ((:additive-expression :alpha_2) - (:multiplicative-expression normal)) additive-expression-subtract)
(%subsection "Bitwise Shift Operators")
(production (:shift-expression :alpha_2) ((:additive-expression :alpha_2)) shift-expression-additive)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) << (:additive-expression normal)) shift-expression-left)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) >> (:additive-expression normal)) shift-expression-right-signed)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) >>> (:additive-expression normal)) shift-expression-right-unsigned)
(%subsection "Relational Operators")
(production (:relational-expression normal) ((:shift-expression normal)) relational-expression-shift-normal)
(production (:relational-expression initial) ((:shift-expression initial)) relational-expression-shift-initial)
(production (:relational-expression no-in) ((:shift-expression normal)) relational-expression-shift-no-in)
(production (:relational-expression :alpha) ((:relational-expression :alpha) < (:shift-expression normal)) relational-expression-less)
(production (:relational-expression :alpha) ((:relational-expression :alpha) > (:shift-expression normal)) relational-expression-greater)
(production (:relational-expression :alpha) ((:relational-expression :alpha) <= (:shift-expression normal)) relational-expression-less-or-equal)
(production (:relational-expression :alpha) ((:relational-expression :alpha) >= (:shift-expression normal)) relational-expression-greater-or-equal)
(production (:relational-expression :alpha) ((:relational-expression :alpha) instanceof (:shift-expression normal)) relational-expression-instanceof)
(production (:relational-expression normal) ((:relational-expression normal) in (:shift-expression normal)) relational-expression-in-normal)
(production (:relational-expression initial) ((:relational-expression initial) in (:shift-expression normal)) relational-expression-in-initial)
(%subsection "Equality Operators")
(production (:equality-expression :alpha) ((:relational-expression :alpha)) equality-expression-relational)
(production (:equality-expression :alpha) ((:equality-expression :alpha) == (:relational-expression :alpha)) equality-expression-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) != (:relational-expression :alpha)) equality-expression-not-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) === (:relational-expression :alpha)) equality-expression-strict-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) !== (:relational-expression :alpha)) equality-expression-strict-not-equal)
(%subsection "Binary Bitwise Operators")
(production (:bitwise-and-expression :alpha) ((:equality-expression :alpha)) bitwise-and-expression-equality)
(production (:bitwise-and-expression :alpha) ((:bitwise-and-expression :alpha) & (:equality-expression :alpha)) bitwise-and-expression-and)
(production (:bitwise-xor-expression :alpha) ((:bitwise-and-expression :alpha)) bitwise-xor-expression-bitwise-and)
(production (:bitwise-xor-expression :alpha) ((:bitwise-xor-expression :alpha) ^ (:bitwise-and-expression :alpha)) bitwise-xor-expression-xor)
(production (:bitwise-or-expression :alpha) ((:bitwise-xor-expression :alpha)) bitwise-or-expression-bitwise-xor)
(production (:bitwise-or-expression :alpha) ((:bitwise-or-expression :alpha) \| (:bitwise-xor-expression :alpha)) bitwise-or-expression-or)
(%subsection "Binary Logical Operators")
(production (:logical-and-expression :alpha) ((:bitwise-or-expression :alpha)) logical-and-expression-bitwise-or)
(production (:logical-and-expression :alpha) ((:logical-and-expression :alpha) && (:bitwise-or-expression :alpha)) logical-and-expression-and)
(production (:logical-or-expression :alpha) ((:logical-and-expression :alpha)) logical-or-expression-logical-and)
(production (:logical-or-expression :alpha) ((:logical-or-expression :alpha) \|\| (:logical-and-expression :alpha)) logical-or-expression-or)
(%subsection "Conditional Operator")
(production (:conditional-expression :alpha) ((:logical-or-expression :alpha)) conditional-expression-logical-or)
(production (:conditional-expression :alpha) ((:logical-or-expression :alpha) ? (:assignment-expression :alpha) \: (:assignment-expression :alpha)) conditional-expression-conditional)
(%subsection "Assignment Operators")
(production (:assignment-expression :alpha) ((:conditional-expression :alpha)) assignment-expression-conditional)
(production (:assignment-expression :alpha) ((:assignment-left-side :alpha) = (:assignment-expression :alpha)) assignment-expression-assignment)
(production (:assignment-expression :alpha) ((:assignment-left-side :alpha) :compound-assignment (:assignment-expression :alpha)) assignment-expression-compound)
(production (:assignment-left-side normal) ((:left-side-expression normal)) assignment-left-side-normal)
(production (:assignment-left-side initial) ((:left-side-expression initial)) assignment-left-side-initial)
(production (:assignment-left-side no-in) ((:left-side-expression normal)) assignment-left-side-no-in)
(production :compound-assignment (*=) compound-assignment-multiply)
(production :compound-assignment (/=) compound-assignment-divide)
(production :compound-assignment (%=) compound-assignment-remainder)
(production :compound-assignment (+=) compound-assignment-add)
(production :compound-assignment (-=) compound-assignment-subtract)
(production :compound-assignment (<<=) compound-assignment-shift-left)
(production :compound-assignment (>>=) compound-assignment-shift-right)
(production :compound-assignment (>>>=) compound-assignment-shift-right-unsigned)
(production :compound-assignment (&=) compound-assignment-and)
(production :compound-assignment (^=) compound-assignment-or)
(production :compound-assignment (\|=) compound-assignment-xor)
(%subsection "Expressions")
(production (:expression :alpha) ((:assignment-expression :alpha)) expression-assignment)
(production (:expression :alpha) ((:expression :alpha) \, (:assignment-expression :alpha)) expression-comma)
(production :optional-expression ((:expression normal)) optional-expression-expression)
(production :optional-expression () optional-expression-empty)
(%subsection "Type Expressions")
(production (:type-expression :alpha_e) ((:logical-or-expression :alpha_e)) type-expression-logical-or)
(production (:type-expression :alpha_e) ((:logical-or-expression :alpha_e) ? (:type-expression :alpha_e) \: (:type-expression :alpha_e)) type-expression-conditional)
;(production (:optional-type-expression :alpha_e) () optional-type-expression-empty)
;(production (:optional-type-expression :alpha_e) ((:type-expression :alpha_e)) optional-type-expression-type-expression)
(%section "Statements")
(grammar-argument :omega
abbrev ;optional semicolon when followed by a '}', 'else', or 'while' in a do-while
abbrev-non-empty ;optional semicolon as long as statement isn't empty
abbrev-no-short-if ;optional semicolon, but statement must not end with an if without an else
full) ;semicolon required at the end
(grammar-argument :omega_3 abbrev abbrev-non-empty full)
(production (:block-statement :omega_3) ((:statement :omega_3)) block-statement-statement)
(production (:block-statement :omega_3) ((:local-definition :omega_3)) block-statement-local-definition)
(production (:statement :omega) ((:empty-statement :omega)) statement-empty-statement)
(production (:statement :omega) (:expression-statement (:semicolon :omega)) statement-expression-statement)
(production (:statement :omega) (:block) statement-block)
(production (:statement :omega) ((:labeled-statement :omega)) statement-labeled-statement)
(production (:statement :omega) ((:if-statement :omega)) statement-if-statement)
(production (:statement :omega) (:switch-statement) statement-switch-statement)
(production (:statement :omega) (:do-statement (:semicolon :omega)) statement-do-statement)
(production (:statement :omega) ((:while-statement :omega)) statement-while-statement)
(production (:statement :omega) ((:for-statement :omega)) statement-for-statement)
(production (:statement :omega) (:continue-statement (:semicolon :omega)) statement-continue-statement)
(production (:statement :omega) (:break-statement (:semicolon :omega)) statement-break-statement)
(production (:statement :omega) (:return-statement (:semicolon :omega)) statement-return-statement)
(production (:statement :omega) (:throw-statement (:semicolon :omega)) statement-throw-statement)
(production (:statement :omega) (:try-statement) statement-try-statement)
(production (:semicolon :omega) (\;) semicolon-semicolon)
(production (:semicolon abbrev) () semicolon-abbrev)
(production (:semicolon abbrev-non-empty) () semicolon-abbrev-non-empty)
(production (:semicolon abbrev-no-short-if) () semicolon-abbrev-no-short-if)
(%subsection "Empty Statement")
(production (:empty-statement :omega) (\;) empty-statement-semicolon)
(production (:empty-statement abbrev) () empty-statement-abbrev)
(production (:empty-statement abbrev-no-short-if) () empty-statement-abbrev-no-short-if)
(%subsection "Expression Statement")
(production :expression-statement ((:expression initial)) expression-statement-expression)
(%subsection "Block")
(production :block ({ :block-statements }) block-block-statements)
(production :block-statements ((:block-statement abbrev)) block-statements-one)
(production :block-statements (:block-statements-prefix (:block-statement abbrev-non-empty)) block-statements-more)
(production :block-statements-prefix ((:block-statement full)) block-statements-prefix-one)
(production :block-statements-prefix (:block-statements-prefix (:block-statement full)) block-statements-prefix-more)
(%subsection "Labeled Statements")
(production (:labeled-statement :omega) ($identifier \: (:statement :omega)) labeled-statement-label)
(%subsection "If Statement")
(production (:if-statement abbrev) (if :parenthesized-expression (:statement abbrev)) if-statement-if-then-abbrev)
(production (:if-statement abbrev-non-empty) (if :parenthesized-expression (:statement abbrev-non-empty)) if-statement-if-then-abbrev-non-empty)
(production (:if-statement full) (if :parenthesized-expression (:statement full)) if-statement-if-then-full)
(production (:if-statement :omega) (if :parenthesized-expression (:statement abbrev-no-short-if)
else (:statement :omega)) if-statement-if-then-else)
(%subsection "Switch Statement")
(production :switch-statement (switch :parenthesized-expression { }) switch-statement-empty)
(production :switch-statement (switch :parenthesized-expression { :case-groups :last-case-group }) switch-statement-cases)
(production :case-groups () case-groups-empty)
(production :case-groups (:case-groups :case-group) case-groups-more)
(production :case-group (:case-guards :case-statements-prefix) case-group-case-statements-prefix)
(production :last-case-group (:case-guards :case-statements) last-case-group-case-statements)
(production :case-guards (:case-guard) case-guards-one)
(production :case-guards (:case-guards :case-guard) case-guards-more)
(production :case-guard (case (:expression normal) \:) case-guard-case)
(production :case-guard (default \:) case-guard-default)
(production :case-statements ((:statement abbrev)) case-statements-one)
(production :case-statements (:case-statements-prefix (:statement abbrev-non-empty)) case-statements-more)
(production :case-statements-prefix ((:statement full)) case-statements-prefix-one)
(production :case-statements-prefix (:case-statements-prefix (:statement full)) case-statements-prefix-more)
(%subsection "Do-While Statement")
(production :do-statement (do (:statement abbrev-non-empty) while :parenthesized-expression) do-statement-do-while)
(%subsection "While Statement")
(production (:while-statement :omega) (while :parenthesized-expression (:statement :omega)) while-statement-while)
(%subsection "For Statements")
(production (:for-statement :omega) (for \( :for-initializer \; :optional-expression \; :optional-expression \)
(:statement :omega)) for-statement-c-style)
(production (:for-statement :omega) (for \( :for-in-binding in (:expression normal) \) (:statement :omega)) for-statement-in)
(production :for-initializer () for-initializer-empty)
(production :for-initializer ((:expression no-in)) for-initializer-expression)
(production :for-initializer (:variable-declaration-kind (:variable-declaration-list no-in)) for-initializer-variable-declaration)
(production :for-in-binding ((:left-side-expression normal)) for-in-binding-expression)
(production :for-in-binding (:variable-declaration-kind (:variable-declaration no-in)) for-in-binding-variable-declaration)
(%subsection "Continue and Break Statements")
(production :continue-statement (continue :optional-label) continue-statement-optional-label)
(production :break-statement (break :optional-label) break-statement-optional-label)
(production :optional-label () optional-label-default)
(production :optional-label ($identifier) optional-label-identifier)
(%subsection "Return Statement")
(production :return-statement (return :optional-expression) return-statement-optional-expression)
(%subsection "Throw Statement")
(production :throw-statement (throw (:expression normal)) throw-statement-throw)
(%subsection "Try Statement")
(production :try-statement (try :block :catch-clauses) try-statement-catch-clauses)
(production :try-statement (try :block :finally-clause) try-statement-finally-clause)
(production :try-statement (try :block :catch-clauses :finally-clause) try-statement-catch-clauses-finally-clause)
(production :catch-clauses (:catch-clause) catch-clauses-one)
(production :catch-clauses (:catch-clauses :catch-clause) catch-clauses-more)
(production :catch-clause (catch \( $identifier (:type-declaration normal) \) :block) catch-clause-block)
(production :finally-clause (finally :block) finally-clause-block)
(%section "Local Definitions")
(production (:local-definition :omega_3) (:variable-definition (:semicolon :omega_3)) local-definition-variable-definition)
(production (:local-definition :omega_3) (:function-definition) local-definition-function-definition)
(%subsection "Variable Definition")
(production :variable-definition (:variable-declaration-kind (:variable-declaration-list normal)) variable-definition-declaration)
(production :variable-declaration-kind (var) variable-declaration-kind-var)
(production :variable-declaration-kind (const) variable-declaration-kind-const)
(production (:variable-declaration-list :alpha_e) ((:variable-declaration :alpha_e)) variable-declaration-list-one)
(production (:variable-declaration-list :alpha_e) ((:variable-declaration-list :alpha_e) \, (:variable-declaration :alpha_e)) variable-declaration-list-more)
(production (:variable-declaration :alpha_e) ($identifier (:type-declaration :alpha_e) (:variable-initializer :alpha_e)) variable-declaration-initializer)
(production (:type-declaration :alpha_e) () type-declaration-empty)
(production (:type-declaration :alpha_e) (\: (:type-expression :alpha_e)) type-declaration-type-expression)
(production (:variable-initializer :alpha_e) () variable-initializer-empty)
(production (:variable-initializer :alpha_e) (= (:assignment-expression :alpha_e)) variable-initializer-assignment-expression)
(%subsection "Function Definition")
(production :function-definition (:named-function) function-definition-named-function)
(production :anonymous-function (function :formal-parameters-and-body) anonymous-function-formal-parameters-and-body)
(production :named-function (function $identifier :formal-parameters-and-body) named-function-formal-parameters-and-body)
(production :formal-parameters-and-body (\( :formal-parameters \) (:type-declaration normal) :block) formal-parameters-and-body)
(production :formal-parameters () formal-parameters-none)
(production :formal-parameters (:formal-parameters-prefix) formal-parameters-some)
(production :formal-parameters-prefix (:formal-parameter) formal-parameters-prefix-one)
(production :formal-parameters-prefix (:formal-parameters-prefix \, :formal-parameter) formal-parameters-prefix-more)
(production :formal-parameter ($identifier (:type-declaration normal)) formal-parameter-identifier)
(%section "Classes")
(production (:member-definition :omega_3) (:accessibility (:local-definition :omega_3)) member-definition-local-definition)
(%subsection "Accessibility Specifications")
(production :accessibility (private) accessibility-private)
(production :accessibility () accessibility-package)
(production :accessibility (public :versions-and-renames) accessibility-public)
(production :versions-and-renames () versions-and-renames-default)
(production :versions-and-renames (< :version-ranges-and-aliases >) versions-and-renames-version-ranges-and-aliases)
(production :version-ranges-and-aliases () version-ranges-and-aliases-none)
(production :version-ranges-and-aliases (:version-ranges-and-aliases-prefix) version-ranges-and-aliases-some)
(production :version-ranges-and-aliases-prefix (:version-range-and-alias) version-ranges-and-aliases-prefix-one)
(production :version-ranges-and-aliases-prefix (:version-ranges-and-aliases-prefix \, :version-range-and-alias) version-ranges-and-aliases-prefix-more)
(production :version-range-and-alias (:version-range) version-range-and-alias-version-range)
(production :version-range-and-alias (:version-range \: $identifier) version-range-and-alias-version-range-and-alias)
(production :version-range (:version) version-range-singleton)
(production :version-range (:optional-version \.\. :optional-version) version-range-range)
(%subsection "Versions")
(production :optional-version (:version) optional-version-version)
(production :optional-version () optional-version-none)
(production :version ($number) version-number)
(production :version ($string) version-string)
(%section "Programs")
(production :program (:top-statements) program)
(production :top-statements ((:top-statement abbrev)) top-statements-one)
(production :top-statements (:top-statements-prefix (:top-statement abbrev-non-empty)) top-statements-more)
(production :top-statements-prefix ((:top-statement full)) top-statements-prefix-one)
(production :top-statements-prefix (:top-statements-prefix (:top-statement full)) top-statements-prefix-more)
(production (:top-statement :omega_3) ((:statement :omega_3)) top-statement-statement)
(production (:top-statement :omega_3) ((:member-definition :omega_3)) top-statement-member-definition)
)))
(defparameter *jg* (world-grammar *jw* 'code-grammar))
(length (grammar-states *jg*)))
#|
(let ((*visible-modes* nil))
(depict-rtf-to-local-file
"JS20.rtf"
#'(lambda (rtf-stream)
(depict-world-commands rtf-stream *jw*))))
(let ((*visible-modes* nil))
(depict-html-to-local-file
"JS20.html"
#'(lambda (rtf-stream)
(depict-world-commands rtf-stream *jw*))
"JavaScript 2.0 Grammar"))
(with-local-output (s "JS20.txt") (print-grammar *jg* s))
|#

Просмотреть файл

@ -0,0 +1,94 @@
// Most browsers don't support unicode mathematical symbols yet.
// As a workaround, this code maps them to the Symbol font using
// either the ISO-8859-1 or ISO-8859-1-to-MacRoman inverse mapping.
var mapping_Unicode = 0; // Output true unicode
var mapping_Win = 1; // Emulate using Windows Symbol font
var mapping_Mac = 2; // Emulate using Mac Symbol font
// CSS class names to use depending on the mapping
var cssClassNames = ["unicode", "symbol", "symbol"];
var mapping = mapping_Win;
if (navigator.platform.indexOf("Mac") != -1)
mapping = mapping_Mac;
else if (navigator.platform.indexOf("Win") != -1 && navigator.appVersion >= 5)
mapping = mapping_Unicode;
function defMap(unicode, win, mac) {
return '<SPAN class="' + cssClassNames[mapping] + '">&#' + arguments[mapping] + ';</SPAN>';
}
var U_times = defMap(0x00D7, 0xB4, 0xA5);
var U_alpha = defMap(0x03B1, 0x61, 0x61);
var U_beta = defMap(0x03B2, 0x62, 0x62);
var U_gamma = defMap(0x03B3, 0x67, 0x67);
var U_delta = defMap(0x03B4, 0x64, 0x64);
var U_epsilon = defMap(0x03B5, 0x65, 0x65);
var U_zeta = defMap(0x03B6, 0x7A, 0x7A);
var U_eta = defMap(0x03B7, 0x68, 0x68);
var U_theta = defMap(0x03B8, 0x71, 0x71);
var U_iota = defMap(0x03B9, 0x69, 0x69);
var U_kappa = defMap(0x03BA, 0x6B, 0x6B);
var U_lambda = defMap(0x03BB, 0x6C, 0x6C);
var U_mu = defMap(0x03BC, 0x6D, 0x6D);
var U_nu = defMap(0x03BD, 0x6E, 0x6E);
var U_xi = defMap(0x03BE, 0x78, 0x78);
var U_omicron = defMap(0x03BF, 0x6F, 0x6F);
var U_pi = defMap(0x03C0, 0x70, 0x70);
var U_rho = defMap(0x03C1, 0x72, 0x72);
var U_sigma = defMap(0x03C3, 0x73, 0x73);
var U_tau = defMap(0x03C4, 0x74, 0x74);
var U_upsilon = defMap(0x03C5, 0x75, 0x75);
var U_phi = defMap(0x03C6, 0x66, 0x66);
var U_chi = defMap(0x03C7, 0x63, 0x63);
var U_psi = defMap(0x03C8, 0x79, 0x79);
var U_omega = defMap(0x03C9, 0x77, 0x77);
var U_bull = defMap(0x2022, 0xB7, 0x2211);
var U_larr = defMap(0x2190, 0xAC, 0xA8);
var U_uarr = defMap(0x2191, 0xAD, 0x2260);
var U_rarr = defMap(0x2192, 0xAE, 0xC6);
var U_darr = defMap(0x2193, 0xAF, 0xD8);
var U_harr = defMap(0x2194, 0xAB, 0xB4);
var U_lArr = defMap(0x21D0, 0xDC, 0x2039);
var U_uArr = defMap(0x21D1, 0xDD, 0x203A);
var U_rArr = defMap(0x21D2, 0xDE, 0xFB01);
var U_dArr = defMap(0x21D3, 0xDF, 0xFB02);
var U_hArr = defMap(0x21D4, 0xDB, 0x20AC);
var U_forall = defMap(0x2200, 0x22, 0x22);
var U_exist = defMap(0x2203, 0x24, 0x24);
var U_empty = defMap(0x2205, 0xC6, 0x2206);
var U_isin = defMap(0x2208, 0xCE, 0x0152);
var U_notin = defMap(0x2209, 0xCF, 0x0153);
var U_infin = defMap(0x221E, 0xA5, 0x2022);
var U_and = defMap(0x2227, 0xD9, 0x0178);
var U_or = defMap(0x2228, 0xDA, 0x2044);
var U_cap = defMap(0x2229, 0xC7, 0xAB);
var U_cup = defMap(0x222A, 0xC8, 0xBB);
var U_cong = defMap(0x2245, 0x40, 0x40);
var U_asymp = defMap(0x2248, 0xBB, 0xAA);
var U_ne = defMap(0x2260, 0xB9, 0x03C0);
var U_equiv = defMap(0x2261, 0xBA, 0x222B);
var U_le = defMap(0x2264, 0xA3, 0xA3);
var U_ge = defMap(0x2265, 0xB3, 0x2265);
var U_sub = defMap(0x2282, 0xCC, 0xC3);
var U_sup = defMap(0x2283, 0xC9, 0x2026);
var U_nsub = defMap(0x2284, 0xCB, 0xC0);
var U_sube = defMap(0x2286, 0xCD, 0xD5);
var U_supe = defMap(0x2287, 0xCA, 0xA0); //Mac Navigator confuses it with nbsp
var U_oplus = defMap(0x2295, 0xC5, 0x2248);
var U_otimes = defMap(0x2297, 0xC4, 0x0192);
var U_perp = defMap(0x22A5, 0x5E, 0x5E);
var U_lceil = defMap(0x2308, 0xE9, 0xC8);
var U_rceil = defMap(0x2309, 0xF9, 0x02D8);
var U_lfloor = defMap(0x230A, 0xEB, 0xCE);
var U_rfloor = defMap(0x230B, 0xFB, 0x02DA);
var U_lang = defMap(0x2329, 0xE1, 0xB7);
var U_rang = defMap(0x232A, 0xF1, 0xD2);

Просмотреть файл

Просмотреть файл

477
js2/semantics/JS20.lisp Normal file
Просмотреть файл

@ -0,0 +1,477 @@
;;; The contents of this file are subject to the Netscape Public License
;;; Version 1.0 (the "NPL"); you may not use this file except in
;;; compliance with the NPL. You may obtain a copy of the NPL at
;;; http://www.mozilla.org/NPL/
;;;
;;; Software distributed under the NPL is distributed on an "AS IS" basis,
;;; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
;;; for the specific language governing rights and limitations under the
;;; NPL.
;;;
;;; The Initial Developer of this code under the NPL is Netscape
;;; Communications Corporation. Portions created by Netscape are
;;; Copyright (C) 1999 Netscape Communications Corporation. All Rights
;;; Reserved.
;;;
;;; Sample JavaScript 2.0 grammar
;;;
;;; Waldemar Horwat (waldemar@netscape.com)
;;;
(declaim (optimize (debug 3)))
(progn
(defparameter *jw*
(generate-world
"J"
'((grammar code-grammar :lr-1 :program)
(%section "Expressions")
(grammar-argument :alpha normal initial no-in)
(grammar-argument :alpha_2 normal initial)
(grammar-argument :alpha_e normal no-in)
(%subsection "Primary Expressions")
(production (:primary-expression :alpha_2) (:simple-expression) primary-expression-simple-expression)
(production (:primary-expression normal) (:function-expression) primary-expression-function-expression)
(production (:primary-expression normal) (:object-literal) primary-expression-object-literal)
(production :simple-expression (this) simple-expression-this)
(production :simple-expression (null) simple-expression-null)
(production :simple-expression (true) simple-expression-true)
(production :simple-expression (false) simple-expression-false)
(production :simple-expression ($number) simple-expression-number)
(production :simple-expression ($string) simple-expression-string)
(production :simple-expression ($identifier) simple-expression-identifier)
(production :simple-expression ($regular-expression) simple-expression-regular-expression)
(production :simple-expression (:parenthesized-expression) simple-expression-parenthesized-expression)
(production :simple-expression (:array-literal) simple-expression-array-literal)
(production :parenthesized-expression (\( (:expression normal) \)) parenthesized-expression-expression)
(%subsection "Function Expressions")
(production :function-expression (:anonymous-function) function-expression-anonymous-function)
(production :function-expression (:named-function) function-expression-named-function)
(%subsection "Object Literals")
(production :object-literal (\{ \}) object-literal-empty)
(production :object-literal (\{ :field-list \}) object-literal-list)
(production :field-list (:literal-field) field-list-one)
(production :field-list (:field-list \, :literal-field) field-list-more)
(production :literal-field ($identifier \: (:assignment-expression normal)) literal-field-assignment-expression)
(%subsection "Array Literals")
(production :array-literal ([ ]) array-literal-empty)
(production :array-literal ([ :element-list ]) array-literal-list)
(production :element-list (:literal-element) element-list-one)
(production :element-list (:element-list \, :literal-element) element-list-more)
(production :literal-element ((:assignment-expression normal)) literal-element-assignment-expression)
(%subsection "Left-Side Expressions")
(grammar-argument :chi allow-calls no-calls)
(production (:member-expression :alpha_2 no-calls) ((:primary-expression :alpha_2)) member-expression-primary-expression)
(production (:member-expression :alpha_2 allow-calls) ((:member-expression :alpha_2 no-calls) :arguments) call-expression-call-member-expression)
(production (:member-expression :alpha_2 allow-calls) ((:member-expression :alpha_2 allow-calls) :arguments) call-expression-call-call-expression)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) [ ]) member-expression-array-declaration)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) [ (:expression normal) ]) member-expression-array)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) \. $identifier) member-expression-property)
(production (:member-expression :alpha_2 :chi) ((:member-expression :alpha_2 :chi) \. :parenthesized-expression) member-expression-indirect-property)
(production (:member-expression :alpha_2 no-calls) (new (:member-expression normal no-calls) :arguments) member-expression-new)
(production (:new-expression :alpha_2) ((:member-expression :alpha_2 no-calls)) new-expression-member-expression)
(production (:new-expression :alpha_2) (new (:new-expression normal)) new-expression-new)
(production :arguments (\( \)) arguments-empty)
(production :arguments (\( :argument-list \)) arguments-list)
(production :argument-list ((:assignment-expression normal)) argument-list-one)
(production :argument-list (:argument-list \, (:assignment-expression normal)) argument-list-more)
(production (:left-side-expression :alpha_2) ((:new-expression :alpha_2)) left-side-expression-new-expression)
(production (:left-side-expression :alpha_2) ((:member-expression :alpha_2 allow-calls)) left-side-expression-call-expression)
(%subsection "Postfix Expressions")
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2)) postfix-expression-left-side-expression)
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2) ++) postfix-expression-increment)
(production (:postfix-expression :alpha_2) ((:left-side-expression :alpha_2) --) postfix-expression-decrement)
(%subsection "Unary Operators")
(production (:unary-expression :alpha_2) ((:postfix-expression :alpha_2)) unary-expression-postfix)
(production (:unary-expression :alpha_2) (delete (:left-side-expression normal)) unary-expression-delete)
(production (:unary-expression :alpha_2) (void (:unary-expression normal)) unary-expression-void)
(production (:unary-expression :alpha_2) (typeof (:unary-expression normal)) unary-expression-typeof)
(production (:unary-expression :alpha_2) (++ (:left-side-expression normal)) unary-expression-increment)
(production (:unary-expression :alpha_2) (-- (:left-side-expression normal)) unary-expression-decrement)
(production (:unary-expression :alpha_2) (+ (:unary-expression normal)) unary-expression-plus)
(production (:unary-expression :alpha_2) (- (:unary-expression normal)) unary-expression-minus)
(production (:unary-expression :alpha_2) (~ (:unary-expression normal)) unary-expression-bitwise-not)
(production (:unary-expression :alpha_2) (! (:unary-expression normal)) unary-expression-logical-not)
(%subsection "Multiplicative Operators")
(production (:multiplicative-expression :alpha_2) ((:unary-expression :alpha_2)) multiplicative-expression-unary)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) * (:unary-expression normal)) multiplicative-expression-multiply)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) / (:unary-expression normal)) multiplicative-expression-divide)
(production (:multiplicative-expression :alpha_2) ((:multiplicative-expression :alpha_2) % (:unary-expression normal)) multiplicative-expression-remainder)
(%subsection "Additive Operators")
(production (:additive-expression :alpha_2) ((:multiplicative-expression :alpha_2)) additive-expression-multiplicative)
(production (:additive-expression :alpha_2) ((:additive-expression :alpha_2) + (:multiplicative-expression normal)) additive-expression-add)
(production (:additive-expression :alpha_2) ((:additive-expression :alpha_2) - (:multiplicative-expression normal)) additive-expression-subtract)
(%subsection "Bitwise Shift Operators")
(production (:shift-expression :alpha_2) ((:additive-expression :alpha_2)) shift-expression-additive)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) << (:additive-expression normal)) shift-expression-left)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) >> (:additive-expression normal)) shift-expression-right-signed)
(production (:shift-expression :alpha_2) ((:shift-expression :alpha_2) >>> (:additive-expression normal)) shift-expression-right-unsigned)
(%subsection "Relational Operators")
(production (:relational-expression normal) ((:shift-expression normal)) relational-expression-shift-normal)
(production (:relational-expression initial) ((:shift-expression initial)) relational-expression-shift-initial)
(production (:relational-expression no-in) ((:shift-expression normal)) relational-expression-shift-no-in)
(production (:relational-expression :alpha) ((:relational-expression :alpha) < (:shift-expression normal)) relational-expression-less)
(production (:relational-expression :alpha) ((:relational-expression :alpha) > (:shift-expression normal)) relational-expression-greater)
(production (:relational-expression :alpha) ((:relational-expression :alpha) <= (:shift-expression normal)) relational-expression-less-or-equal)
(production (:relational-expression :alpha) ((:relational-expression :alpha) >= (:shift-expression normal)) relational-expression-greater-or-equal)
(production (:relational-expression :alpha) ((:relational-expression :alpha) instanceof (:shift-expression normal)) relational-expression-instanceof)
(production (:relational-expression normal) ((:relational-expression normal) in (:shift-expression normal)) relational-expression-in-normal)
(production (:relational-expression initial) ((:relational-expression initial) in (:shift-expression normal)) relational-expression-in-initial)
(%subsection "Equality Operators")
(production (:equality-expression :alpha) ((:relational-expression :alpha)) equality-expression-relational)
(production (:equality-expression :alpha) ((:equality-expression :alpha) == (:relational-expression :alpha)) equality-expression-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) != (:relational-expression :alpha)) equality-expression-not-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) === (:relational-expression :alpha)) equality-expression-strict-equal)
(production (:equality-expression :alpha) ((:equality-expression :alpha) !== (:relational-expression :alpha)) equality-expression-strict-not-equal)
(%subsection "Binary Bitwise Operators")
(production (:bitwise-and-expression :alpha) ((:equality-expression :alpha)) bitwise-and-expression-equality)
(production (:bitwise-and-expression :alpha) ((:bitwise-and-expression :alpha) & (:equality-expression :alpha)) bitwise-and-expression-and)
(production (:bitwise-xor-expression :alpha) ((:bitwise-and-expression :alpha)) bitwise-xor-expression-bitwise-and)
(production (:bitwise-xor-expression :alpha) ((:bitwise-xor-expression :alpha) ^ (:bitwise-and-expression :alpha)) bitwise-xor-expression-xor)
(production (:bitwise-or-expression :alpha) ((:bitwise-xor-expression :alpha)) bitwise-or-expression-bitwise-xor)
(production (:bitwise-or-expression :alpha) ((:bitwise-or-expression :alpha) \| (:bitwise-xor-expression :alpha)) bitwise-or-expression-or)
(%subsection "Binary Logical Operators")
(production (:logical-and-expression :alpha) ((:bitwise-or-expression :alpha)) logical-and-expression-bitwise-or)
(production (:logical-and-expression :alpha) ((:logical-and-expression :alpha) && (:bitwise-or-expression :alpha)) logical-and-expression-and)
(production (:logical-or-expression :alpha) ((:logical-and-expression :alpha)) logical-or-expression-logical-and)
(production (:logical-or-expression :alpha) ((:logical-or-expression :alpha) \|\| (:logical-and-expression :alpha)) logical-or-expression-or)
(%subsection "Conditional Operator")
(production (:conditional-expression :alpha) ((:logical-or-expression :alpha)) conditional-expression-logical-or)
(production (:conditional-expression :alpha) ((:logical-or-expression :alpha) ? (:assignment-expression :alpha) \: (:assignment-expression :alpha)) conditional-expression-conditional)
(%subsection "Assignment Operators")
(production (:assignment-expression :alpha) ((:conditional-expression :alpha)) assignment-expression-conditional)
(production (:assignment-expression :alpha) ((:assignment-left-side :alpha) = (:assignment-expression :alpha)) assignment-expression-assignment)
(production (:assignment-expression :alpha) ((:assignment-left-side :alpha) :compound-assignment (:assignment-expression :alpha)) assignment-expression-compound)
(production (:assignment-left-side normal) ((:left-side-expression normal)) assignment-left-side-normal)
(production (:assignment-left-side initial) ((:left-side-expression initial)) assignment-left-side-initial)
(production (:assignment-left-side no-in) ((:left-side-expression normal)) assignment-left-side-no-in)
(production :compound-assignment (*=) compound-assignment-multiply)
(production :compound-assignment (/=) compound-assignment-divide)
(production :compound-assignment (%=) compound-assignment-remainder)
(production :compound-assignment (+=) compound-assignment-add)
(production :compound-assignment (-=) compound-assignment-subtract)
(production :compound-assignment (<<=) compound-assignment-shift-left)
(production :compound-assignment (>>=) compound-assignment-shift-right)
(production :compound-assignment (>>>=) compound-assignment-shift-right-unsigned)
(production :compound-assignment (&=) compound-assignment-and)
(production :compound-assignment (^=) compound-assignment-or)
(production :compound-assignment (\|=) compound-assignment-xor)
(%subsection "Expressions")
(production (:expression :alpha) ((:assignment-expression :alpha)) expression-assignment)
(production (:expression :alpha) ((:expression :alpha) \, (:assignment-expression :alpha)) expression-comma)
(production :optional-expression ((:expression normal)) optional-expression-expression)
(production :optional-expression () optional-expression-empty)
(%subsection "Type Expressions")
(production (:type-expression :alpha_e) ((:logical-or-expression :alpha_e)) type-expression-logical-or)
(production (:type-expression :alpha_e) ((:logical-or-expression :alpha_e) ? (:type-expression :alpha_e) \: (:type-expression :alpha_e)) type-expression-conditional)
;(production (:optional-type-expression :alpha_e) () optional-type-expression-empty)
;(production (:optional-type-expression :alpha_e) ((:type-expression :alpha_e)) optional-type-expression-type-expression)
(%section "Statements")
(grammar-argument :omega
abbrev ;optional semicolon when followed by a '}', 'else', or 'while' in a do-while
abbrev-non-empty ;optional semicolon as long as statement isn't empty
abbrev-no-short-if ;optional semicolon, but statement must not end with an if without an else
full) ;semicolon required at the end
(grammar-argument :omega_3 abbrev abbrev-non-empty full)
(production (:block-statement :omega_3) ((:statement :omega_3)) block-statement-statement)
(production (:block-statement :omega_3) ((:local-definition :omega_3)) block-statement-local-definition)
(production (:statement :omega) ((:empty-statement :omega)) statement-empty-statement)
(production (:statement :omega) (:expression-statement (:semicolon :omega)) statement-expression-statement)
(production (:statement :omega) (:block) statement-block)
(production (:statement :omega) ((:labeled-statement :omega)) statement-labeled-statement)
(production (:statement :omega) ((:if-statement :omega)) statement-if-statement)
(production (:statement :omega) (:switch-statement) statement-switch-statement)
(production (:statement :omega) (:do-statement (:semicolon :omega)) statement-do-statement)
(production (:statement :omega) ((:while-statement :omega)) statement-while-statement)
(production (:statement :omega) ((:for-statement :omega)) statement-for-statement)
(production (:statement :omega) (:continue-statement (:semicolon :omega)) statement-continue-statement)
(production (:statement :omega) (:break-statement (:semicolon :omega)) statement-break-statement)
(production (:statement :omega) (:return-statement (:semicolon :omega)) statement-return-statement)
(production (:statement :omega) (:throw-statement (:semicolon :omega)) statement-throw-statement)
(production (:statement :omega) (:try-statement) statement-try-statement)
(production (:semicolon :omega) (\;) semicolon-semicolon)
(production (:semicolon abbrev) () semicolon-abbrev)
(production (:semicolon abbrev-non-empty) () semicolon-abbrev-non-empty)
(production (:semicolon abbrev-no-short-if) () semicolon-abbrev-no-short-if)
(%subsection "Empty Statement")
(production (:empty-statement :omega) (\;) empty-statement-semicolon)
(production (:empty-statement abbrev) () empty-statement-abbrev)
(production (:empty-statement abbrev-no-short-if) () empty-statement-abbrev-no-short-if)
(%subsection "Expression Statement")
(production :expression-statement ((:expression initial)) expression-statement-expression)
(%subsection "Block")
(production :block ({ :block-statements }) block-block-statements)
(production :block-statements ((:block-statement abbrev)) block-statements-one)
(production :block-statements (:block-statements-prefix (:block-statement abbrev-non-empty)) block-statements-more)
(production :block-statements-prefix ((:block-statement full)) block-statements-prefix-one)
(production :block-statements-prefix (:block-statements-prefix (:block-statement full)) block-statements-prefix-more)
(%subsection "Labeled Statements")
(production (:labeled-statement :omega) ($identifier \: (:statement :omega)) labeled-statement-label)
(%subsection "If Statement")
(production (:if-statement abbrev) (if :parenthesized-expression (:statement abbrev)) if-statement-if-then-abbrev)
(production (:if-statement abbrev-non-empty) (if :parenthesized-expression (:statement abbrev-non-empty)) if-statement-if-then-abbrev-non-empty)
(production (:if-statement full) (if :parenthesized-expression (:statement full)) if-statement-if-then-full)
(production (:if-statement :omega) (if :parenthesized-expression (:statement abbrev-no-short-if)
else (:statement :omega)) if-statement-if-then-else)
(%subsection "Switch Statement")
(production :switch-statement (switch :parenthesized-expression { }) switch-statement-empty)
(production :switch-statement (switch :parenthesized-expression { :case-groups :last-case-group }) switch-statement-cases)
(production :case-groups () case-groups-empty)
(production :case-groups (:case-groups :case-group) case-groups-more)
(production :case-group (:case-guards :case-statements-prefix) case-group-case-statements-prefix)
(production :last-case-group (:case-guards :case-statements) last-case-group-case-statements)
(production :case-guards (:case-guard) case-guards-one)
(production :case-guards (:case-guards :case-guard) case-guards-more)
(production :case-guard (case (:expression normal) \:) case-guard-case)
(production :case-guard (default \:) case-guard-default)
(production :case-statements ((:statement abbrev)) case-statements-one)
(production :case-statements (:case-statements-prefix (:statement abbrev-non-empty)) case-statements-more)
(production :case-statements-prefix ((:statement full)) case-statements-prefix-one)
(production :case-statements-prefix (:case-statements-prefix (:statement full)) case-statements-prefix-more)
(%subsection "Do-While Statement")
(production :do-statement (do (:statement abbrev-non-empty) while :parenthesized-expression) do-statement-do-while)
(%subsection "While Statement")
(production (:while-statement :omega) (while :parenthesized-expression (:statement :omega)) while-statement-while)
(%subsection "For Statements")
(production (:for-statement :omega) (for \( :for-initializer \; :optional-expression \; :optional-expression \)
(:statement :omega)) for-statement-c-style)
(production (:for-statement :omega) (for \( :for-in-binding in (:expression normal) \) (:statement :omega)) for-statement-in)
(production :for-initializer () for-initializer-empty)
(production :for-initializer ((:expression no-in)) for-initializer-expression)
(production :for-initializer (:variable-declaration-kind (:variable-declaration-list no-in)) for-initializer-variable-declaration)
(production :for-in-binding ((:left-side-expression normal)) for-in-binding-expression)
(production :for-in-binding (:variable-declaration-kind (:variable-declaration no-in)) for-in-binding-variable-declaration)
(%subsection "Continue and Break Statements")
(production :continue-statement (continue :optional-label) continue-statement-optional-label)
(production :break-statement (break :optional-label) break-statement-optional-label)
(production :optional-label () optional-label-default)
(production :optional-label ($identifier) optional-label-identifier)
(%subsection "Return Statement")
(production :return-statement (return :optional-expression) return-statement-optional-expression)
(%subsection "Throw Statement")
(production :throw-statement (throw (:expression normal)) throw-statement-throw)
(%subsection "Try Statement")
(production :try-statement (try :block :catch-clauses) try-statement-catch-clauses)
(production :try-statement (try :block :finally-clause) try-statement-finally-clause)
(production :try-statement (try :block :catch-clauses :finally-clause) try-statement-catch-clauses-finally-clause)
(production :catch-clauses (:catch-clause) catch-clauses-one)
(production :catch-clauses (:catch-clauses :catch-clause) catch-clauses-more)
(production :catch-clause (catch \( $identifier (:type-declaration normal) \) :block) catch-clause-block)
(production :finally-clause (finally :block) finally-clause-block)
(%section "Local Definitions")
(production (:local-definition :omega_3) (:variable-definition (:semicolon :omega_3)) local-definition-variable-definition)
(production (:local-definition :omega_3) (:function-definition) local-definition-function-definition)
(%subsection "Variable Definition")
(production :variable-definition (:variable-declaration-kind (:variable-declaration-list normal)) variable-definition-declaration)
(production :variable-declaration-kind (var) variable-declaration-kind-var)
(production :variable-declaration-kind (const) variable-declaration-kind-const)
(production (:variable-declaration-list :alpha_e) ((:variable-declaration :alpha_e)) variable-declaration-list-one)
(production (:variable-declaration-list :alpha_e) ((:variable-declaration-list :alpha_e) \, (:variable-declaration :alpha_e)) variable-declaration-list-more)
(production (:variable-declaration :alpha_e) ($identifier (:type-declaration :alpha_e) (:variable-initializer :alpha_e)) variable-declaration-initializer)
(production (:type-declaration :alpha_e) () type-declaration-empty)
(production (:type-declaration :alpha_e) (\: (:type-expression :alpha_e)) type-declaration-type-expression)
(production (:variable-initializer :alpha_e) () variable-initializer-empty)
(production (:variable-initializer :alpha_e) (= (:assignment-expression :alpha_e)) variable-initializer-assignment-expression)
(%subsection "Function Definition")
(production :function-definition (:named-function) function-definition-named-function)
(production :anonymous-function (function :formal-parameters-and-body) anonymous-function-formal-parameters-and-body)
(production :named-function (function $identifier :formal-parameters-and-body) named-function-formal-parameters-and-body)
(production :formal-parameters-and-body (\( :formal-parameters \) (:type-declaration normal) :block) formal-parameters-and-body)
(production :formal-parameters () formal-parameters-none)
(production :formal-parameters (:formal-parameters-prefix) formal-parameters-some)
(production :formal-parameters-prefix (:formal-parameter) formal-parameters-prefix-one)
(production :formal-parameters-prefix (:formal-parameters-prefix \, :formal-parameter) formal-parameters-prefix-more)
(production :formal-parameter ($identifier (:type-declaration normal)) formal-parameter-identifier)
(%section "Classes")
(production (:member-definition :omega_3) (:accessibility (:local-definition :omega_3)) member-definition-local-definition)
(%subsection "Accessibility Specifications")
(production :accessibility (private) accessibility-private)
(production :accessibility () accessibility-package)
(production :accessibility (public :versions-and-renames) accessibility-public)
(production :versions-and-renames () versions-and-renames-default)
(production :versions-and-renames (< :version-ranges-and-aliases >) versions-and-renames-version-ranges-and-aliases)
(production :version-ranges-and-aliases () version-ranges-and-aliases-none)
(production :version-ranges-and-aliases (:version-ranges-and-aliases-prefix) version-ranges-and-aliases-some)
(production :version-ranges-and-aliases-prefix (:version-range-and-alias) version-ranges-and-aliases-prefix-one)
(production :version-ranges-and-aliases-prefix (:version-ranges-and-aliases-prefix \, :version-range-and-alias) version-ranges-and-aliases-prefix-more)
(production :version-range-and-alias (:version-range) version-range-and-alias-version-range)
(production :version-range-and-alias (:version-range \: $identifier) version-range-and-alias-version-range-and-alias)
(production :version-range (:version) version-range-singleton)
(production :version-range (:optional-version \.\. :optional-version) version-range-range)
(%subsection "Versions")
(production :optional-version (:version) optional-version-version)
(production :optional-version () optional-version-none)
(production :version ($number) version-number)
(production :version ($string) version-string)
(%section "Programs")
(production :program (:top-statements) program)
(production :top-statements ((:top-statement abbrev)) top-statements-one)
(production :top-statements (:top-statements-prefix (:top-statement abbrev-non-empty)) top-statements-more)
(production :top-statements-prefix ((:top-statement full)) top-statements-prefix-one)
(production :top-statements-prefix (:top-statements-prefix (:top-statement full)) top-statements-prefix-more)
(production (:top-statement :omega_3) ((:statement :omega_3)) top-statement-statement)
(production (:top-statement :omega_3) ((:member-definition :omega_3)) top-statement-member-definition)
)))
(defparameter *jg* (world-grammar *jw* 'code-grammar))
(length (grammar-states *jg*)))
#|
(let ((*visible-modes* nil))
(depict-rtf-to-local-file
"JS20.rtf"
#'(lambda (rtf-stream)
(depict-world-commands rtf-stream *jw*))))
(let ((*visible-modes* nil))
(depict-html-to-local-file
"JS20.html"
#'(lambda (rtf-stream)
(depict-world-commands rtf-stream *jw*))
"JavaScript 2.0 Grammar"))
(with-local-output (s "JS20.txt") (print-grammar *jg* s))
|#

Просмотреть файл

@ -0,0 +1,94 @@
// Most browsers don't support unicode mathematical symbols yet.
// As a workaround, this code maps them to the Symbol font using
// either the ISO-8859-1 or ISO-8859-1-to-MacRoman inverse mapping.
var mapping_Unicode = 0; // Output true unicode
var mapping_Win = 1; // Emulate using Windows Symbol font
var mapping_Mac = 2; // Emulate using Mac Symbol font
// CSS class names to use depending on the mapping
var cssClassNames = ["unicode", "symbol", "symbol"];
var mapping = mapping_Win;
if (navigator.platform.indexOf("Mac") != -1)
mapping = mapping_Mac;
else if (navigator.platform.indexOf("Win") != -1 && navigator.appVersion >= 5)
mapping = mapping_Unicode;
function defMap(unicode, win, mac) {
return '<SPAN class="' + cssClassNames[mapping] + '">&#' + arguments[mapping] + ';</SPAN>';
}
var U_times = defMap(0x00D7, 0xB4, 0xA5);
var U_alpha = defMap(0x03B1, 0x61, 0x61);
var U_beta = defMap(0x03B2, 0x62, 0x62);
var U_gamma = defMap(0x03B3, 0x67, 0x67);
var U_delta = defMap(0x03B4, 0x64, 0x64);
var U_epsilon = defMap(0x03B5, 0x65, 0x65);
var U_zeta = defMap(0x03B6, 0x7A, 0x7A);
var U_eta = defMap(0x03B7, 0x68, 0x68);
var U_theta = defMap(0x03B8, 0x71, 0x71);
var U_iota = defMap(0x03B9, 0x69, 0x69);
var U_kappa = defMap(0x03BA, 0x6B, 0x6B);
var U_lambda = defMap(0x03BB, 0x6C, 0x6C);
var U_mu = defMap(0x03BC, 0x6D, 0x6D);
var U_nu = defMap(0x03BD, 0x6E, 0x6E);
var U_xi = defMap(0x03BE, 0x78, 0x78);
var U_omicron = defMap(0x03BF, 0x6F, 0x6F);
var U_pi = defMap(0x03C0, 0x70, 0x70);
var U_rho = defMap(0x03C1, 0x72, 0x72);
var U_sigma = defMap(0x03C3, 0x73, 0x73);
var U_tau = defMap(0x03C4, 0x74, 0x74);
var U_upsilon = defMap(0x03C5, 0x75, 0x75);
var U_phi = defMap(0x03C6, 0x66, 0x66);
var U_chi = defMap(0x03C7, 0x63, 0x63);
var U_psi = defMap(0x03C8, 0x79, 0x79);
var U_omega = defMap(0x03C9, 0x77, 0x77);
var U_bull = defMap(0x2022, 0xB7, 0x2211);
var U_larr = defMap(0x2190, 0xAC, 0xA8);
var U_uarr = defMap(0x2191, 0xAD, 0x2260);
var U_rarr = defMap(0x2192, 0xAE, 0xC6);
var U_darr = defMap(0x2193, 0xAF, 0xD8);
var U_harr = defMap(0x2194, 0xAB, 0xB4);
var U_lArr = defMap(0x21D0, 0xDC, 0x2039);
var U_uArr = defMap(0x21D1, 0xDD, 0x203A);
var U_rArr = defMap(0x21D2, 0xDE, 0xFB01);
var U_dArr = defMap(0x21D3, 0xDF, 0xFB02);
var U_hArr = defMap(0x21D4, 0xDB, 0x20AC);
var U_forall = defMap(0x2200, 0x22, 0x22);
var U_exist = defMap(0x2203, 0x24, 0x24);
var U_empty = defMap(0x2205, 0xC6, 0x2206);
var U_isin = defMap(0x2208, 0xCE, 0x0152);
var U_notin = defMap(0x2209, 0xCF, 0x0153);
var U_infin = defMap(0x221E, 0xA5, 0x2022);
var U_and = defMap(0x2227, 0xD9, 0x0178);
var U_or = defMap(0x2228, 0xDA, 0x2044);
var U_cap = defMap(0x2229, 0xC7, 0xAB);
var U_cup = defMap(0x222A, 0xC8, 0xBB);
var U_cong = defMap(0x2245, 0x40, 0x40);
var U_asymp = defMap(0x2248, 0xBB, 0xAA);
var U_ne = defMap(0x2260, 0xB9, 0x03C0);
var U_equiv = defMap(0x2261, 0xBA, 0x222B);
var U_le = defMap(0x2264, 0xA3, 0xA3);
var U_ge = defMap(0x2265, 0xB3, 0x2265);
var U_sub = defMap(0x2282, 0xCC, 0xC3);
var U_sup = defMap(0x2283, 0xC9, 0x2026);
var U_nsub = defMap(0x2284, 0xCB, 0xC0);
var U_sube = defMap(0x2286, 0xCD, 0xD5);
var U_supe = defMap(0x2287, 0xCA, 0xA0); //Mac Navigator confuses it with nbsp
var U_oplus = defMap(0x2295, 0xC5, 0x2248);
var U_otimes = defMap(0x2297, 0xC4, 0x0192);
var U_perp = defMap(0x22A5, 0x5E, 0x5E);
var U_lceil = defMap(0x2308, 0xE9, 0xC8);
var U_rceil = defMap(0x2309, 0xF9, 0x02D8);
var U_lfloor = defMap(0x230A, 0xEB, 0xCE);
var U_rfloor = defMap(0x230B, 0xFB, 0x02DA);
var U_lang = defMap(0x2329, 0xE1, 0xB7);
var U_rang = defMap(0x232A, 0xF1, 0xD2);