1999-05-11 00:52:58 +04:00
|
|
|
;;;
|
1999-11-03 06:59:31 +03:00
|
|
|
;;; JavaScript 2.0 parser
|
1999-05-11 00:52:58 +04:00
|
|
|
;;;
|
1999-11-03 06:59:31 +03:00
|
|
|
;;; Waldemar Horwat (waldemar@acm.org)
|
1999-05-11 00:52:58 +04:00
|
|
|
;;;
|
|
|
|
|
|
|
|
(declaim (optimize (debug 3)))
|
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(defparameter *jw-source*
|
|
|
|
'((line-grammar code-grammar :lr-1 :program)
|
|
|
|
|
|
|
|
(%section "Expressions")
|
|
|
|
(grammar-argument :beta allow-in no-in)
|
|
|
|
|
|
|
|
(%subsection "Identifiers")
|
|
|
|
(production :identifier ($identifier) identifier-identifier)
|
|
|
|
(production :identifier (get) identifier-get)
|
|
|
|
(production :identifier (set) identifier-set)
|
2000-10-10 06:49:34 +04:00
|
|
|
(? js2
|
|
|
|
(production :identifier (include) identifier-include))
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :qualifier (:identifier) qualifier-identifier)
|
|
|
|
(production :qualifier (public) qualifier-public)
|
|
|
|
(production :qualifier (private) qualifier-private)
|
|
|
|
(production :qualifier (super) qualifier-super)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :qualifier (:qualifier \:\: :identifier) qualifier-identifier-qualifier)
|
|
|
|
|
|
|
|
(production :simple-qualified-identifier (:identifier) simple-qualified-identifier-identifier)
|
|
|
|
(production :simple-qualified-identifier (:qualifier \:\: :identifier) simple-qualified-identifier-qualifier)
|
|
|
|
|
|
|
|
(production :expression-qualified-identifier (:parenthesized-expression \:\: :identifier) expression-qualified-identifier-identifier)
|
|
|
|
|
|
|
|
(production :qualified-identifier (:simple-qualified-identifier) qualified-identifier-simple)
|
|
|
|
(production :qualified-identifier (:expression-qualified-identifier) qualified-identifier-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
2000-10-28 09:55:47 +04:00
|
|
|
(%subsection "Unit Expressions")
|
|
|
|
(production :unit-expression (:parenthesized-list-expression) unit-expression-parenthesized-list-expression)
|
|
|
|
(production :unit-expression ($number :no-line-break $string) unit-expression-number-with-unit)
|
|
|
|
(production :unit-expression (:unit-expression :no-line-break $string) unit-expression-unit-expression-with-unit)
|
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(%subsection "Primary Expressions")
|
|
|
|
(production :primary-expression (null) primary-expression-null)
|
|
|
|
(production :primary-expression (true) primary-expression-true)
|
|
|
|
(production :primary-expression (false) primary-expression-false)
|
|
|
|
(production :primary-expression (public) primary-expression-public)
|
|
|
|
(production :primary-expression ($number) primary-expression-number)
|
|
|
|
(production :primary-expression ($string) primary-expression-string)
|
|
|
|
(production :primary-expression (this) primary-expression-this)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :primary-expression (super) primary-expression-super)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :primary-expression ($regular-expression) primary-expression-regular-expression)
|
2000-10-28 09:55:47 +04:00
|
|
|
(production :primary-expression (:unit-expression) primary-expression-unit-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :primary-expression (:array-literal) primary-expression-array-literal)
|
|
|
|
(production :primary-expression (:object-literal) primary-expression-object-literal)
|
|
|
|
(production :primary-expression (:function-expression) primary-expression-function-expression)
|
2000-10-10 06:49:34 +04:00
|
|
|
;(production :primary-expression (eval :parenthesized-expression) primary-expression-eval)
|
2000-09-22 12:16:22 +04:00
|
|
|
|
|
|
|
(production :parenthesized-expression (\( (:assignment-expression allow-in) \)) parenthesized-expression-assignment-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :parenthesized-list-expression (:parenthesized-expression) parenthesized-list-expression-parenthesized-expression)
|
|
|
|
(production :parenthesized-list-expression (\( (:list-expression allow-in) \, (:assignment-expression allow-in) \)) parenthesized-list-expression-list-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Function Expressions")
|
|
|
|
(production :function-expression (function :function-signature :block) function-expression-anonymous)
|
|
|
|
(production :function-expression (function :identifier :function-signature :block) function-expression-named)
|
|
|
|
|
|
|
|
|
|
|
|
(%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 (:field-name \: (:assignment-expression allow-in)) literal-field-assignment-expression)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :field-name (:identifier) field-name-identifier)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :field-name ($string) field-name-string)
|
|
|
|
(production :field-name ($number) field-name-number)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :field-name (:parenthesized-expression) field-name-parenthesized-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Array Literals")
|
|
|
|
(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 () literal-element-none)
|
|
|
|
(production :literal-element ((:assignment-expression allow-in)) literal-element-assignment-expression)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Postfix Unary Operators")
|
|
|
|
(production :postfix-expression (:attribute-expression) postfix-expression-attribute-expression)
|
|
|
|
(production :postfix-expression (:full-postfix-expression) postfix-expression-full-postfix-expression)
|
|
|
|
(production :postfix-expression (:short-new-expression) postfix-expression-short-new-expression)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :attribute-expression (:simple-qualified-identifier) attribute-expression-simple-qualified-identifier)
|
|
|
|
(production :attribute-expression (:attribute-expression :dot-operator) attribute-expression-dot-operator)
|
|
|
|
(production :attribute-expression (:attribute-expression :brackets) attribute-expression-brackets)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :attribute-expression (:attribute-expression :arguments) attribute-expression-call1)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :full-postfix-expression (:const-dot-expression) full-postfix-expression-const-dot-expression)
|
|
|
|
(production :full-postfix-expression (:full-postfix-subexpression) full-postfix-expression-full-postfix-subexpression)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :full-postfix-subexpression (:primary-expression) full-postfix-subexpression-primary-expression)
|
|
|
|
(production :full-postfix-subexpression (:expression-qualified-identifier) full-postfix-subexpression-expression-qualified-identifier)
|
|
|
|
(production :full-postfix-subexpression (:full-new-expression) full-postfix-subexpression-full-new-expression)
|
|
|
|
(production :full-postfix-subexpression (:full-postfix-subexpression :dot-operator) full-postfix-subexpression-dot-operator)
|
|
|
|
(production :full-postfix-subexpression (:full-postfix-expression :brackets) full-postfix-subexpression-brackets)
|
|
|
|
(production :full-postfix-subexpression (:full-postfix-expression :arguments) full-postfix-subexpression-call)
|
|
|
|
(production :full-postfix-subexpression (:postfix-expression :no-line-break ++) full-postfix-subexpression-increment)
|
|
|
|
(production :full-postfix-subexpression (:postfix-expression :no-line-break --) full-postfix-subexpression-decrement)
|
2000-09-09 06:15:37 +04:00
|
|
|
(? js2
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :full-postfix-subexpression (:postfix-expression @ :qualified-identifier) full-postfix-subexpression-coerce)
|
|
|
|
(production :full-postfix-subexpression (:postfix-expression @ :parenthesized-expression) full-postfix-subexpression-indirect-coerce))
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :full-new-expression (new :bracket-expression :arguments) full-new-expression-new)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :short-new-expression (new :short-new-subexpression) short-new-expression-new)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :short-new-expression (const new :short-new-subexpression) short-new-expression-const-new)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :short-new-subexpression (:bracket-expression) short-new-subexpression-new-full)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :short-new-subexpression (:short-new-expression) short-new-subexpression-new-short)
|
|
|
|
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :bracket-expression (:const-expression) bracket-expression-const-expression)
|
|
|
|
(production :bracket-expression (:bracket-subexpression) bracket-expression-bracket-subexpression)
|
|
|
|
|
|
|
|
(production :bracket-subexpression (:bracket-expression :brackets) bracket-subexpression-brackets)
|
|
|
|
(production :bracket-subexpression (:bracket-subexpression :dot-operator) bracket-subexpression-dot-operator)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :const-expression (:dot-expression) const-expression-dot-expression)
|
|
|
|
(production :const-expression (:const-dot-expression) const-expression-const-dot-expression)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :const-dot-expression (const :dot-expression) const-dot-expression-dot-expression)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :dot-expression (:primary-expression) dot-expression-primary-expression)
|
|
|
|
(production :dot-expression (:qualified-identifier) dot-expression-qualified-identifier)
|
|
|
|
(production :dot-expression (:full-new-expression) dot-expression-full-new-expression)
|
|
|
|
(production :dot-expression (:dot-expression :dot-operator) dot-expression-dot-operator)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :dot-operator (\. :qualified-identifier) dot-operator-qualified-identifier)
|
2000-10-10 06:49:34 +04:00
|
|
|
(production :dot-operator (\. class) dot-operator-class)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :brackets ([ :argument-list ]) brackets-argument-list)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :arguments (\( :argument-list \)) arguments-argument-list)
|
|
|
|
|
|
|
|
(production :argument-list () argument-list-none)
|
|
|
|
(production :argument-list ((:list-expression allow-in)) argument-list-unnamed)
|
|
|
|
(production :argument-list (:named-argument-list) argument-list-named)
|
|
|
|
|
|
|
|
(production :named-argument-list (:literal-field) named-argument-list-one)
|
|
|
|
(production :named-argument-list ((:list-expression allow-in) \, :literal-field) named-argument-list-unnamed)
|
|
|
|
(production :named-argument-list (:named-argument-list \, :literal-field) named-argument-list-more)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Prefix Unary Operators")
|
|
|
|
(production :unary-expression (:postfix-expression) unary-expression-postfix)
|
|
|
|
(production :unary-expression (delete :postfix-expression) unary-expression-delete)
|
2000-09-24 10:08:53 +04:00
|
|
|
(production :unary-expression (void :unary-expression) unary-expression-void)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :unary-expression (typeof :unary-expression) unary-expression-typeof)
|
|
|
|
(production :unary-expression (++ :postfix-expression) unary-expression-increment)
|
|
|
|
(production :unary-expression (-- :postfix-expression) unary-expression-decrement)
|
|
|
|
(production :unary-expression (+ :unary-expression) unary-expression-plus)
|
|
|
|
(production :unary-expression (- :unary-expression) unary-expression-minus)
|
|
|
|
(production :unary-expression (~ :unary-expression) unary-expression-bitwise-not)
|
|
|
|
(production :unary-expression (! :unary-expression) unary-expression-logical-not)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Multiplicative Operators")
|
|
|
|
(production :multiplicative-expression (:unary-expression) multiplicative-expression-unary)
|
|
|
|
(production :multiplicative-expression (:multiplicative-expression * :unary-expression) multiplicative-expression-multiply)
|
|
|
|
(production :multiplicative-expression (:multiplicative-expression / :unary-expression) multiplicative-expression-divide)
|
|
|
|
(production :multiplicative-expression (:multiplicative-expression % :unary-expression) multiplicative-expression-remainder)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Additive Operators")
|
|
|
|
(production :additive-expression (:multiplicative-expression) additive-expression-multiplicative)
|
|
|
|
(production :additive-expression (:additive-expression + :multiplicative-expression) additive-expression-add)
|
|
|
|
(production :additive-expression (:additive-expression - :multiplicative-expression) additive-expression-subtract)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Bitwise Shift Operators")
|
|
|
|
(production :shift-expression (:additive-expression) shift-expression-additive)
|
|
|
|
(production :shift-expression (:shift-expression << :additive-expression) shift-expression-left)
|
|
|
|
(production :shift-expression (:shift-expression >> :additive-expression) shift-expression-right-signed)
|
|
|
|
(production :shift-expression (:shift-expression >>> :additive-expression) shift-expression-right-unsigned)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Relational Operators")
|
|
|
|
(production (:relational-expression :beta) (:shift-expression) relational-expression-shift)
|
|
|
|
(production (:relational-expression :beta) ((:relational-expression :beta) < :shift-expression) relational-expression-less)
|
|
|
|
(production (:relational-expression :beta) ((:relational-expression :beta) > :shift-expression) relational-expression-greater)
|
|
|
|
(production (:relational-expression :beta) ((:relational-expression :beta) <= :shift-expression) relational-expression-less-or-equal)
|
|
|
|
(production (:relational-expression :beta) ((:relational-expression :beta) >= :shift-expression) relational-expression-greater-or-equal)
|
|
|
|
(production (:relational-expression :beta) ((:relational-expression :beta) instanceof :shift-expression) relational-expression-instanceof)
|
|
|
|
(production (:relational-expression allow-in) ((:relational-expression allow-in) in :shift-expression) relational-expression-in)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Equality Operators")
|
|
|
|
(production (:equality-expression :beta) ((:relational-expression :beta)) equality-expression-relational)
|
|
|
|
(production (:equality-expression :beta) ((:equality-expression :beta) == (:relational-expression :beta)) equality-expression-equal)
|
|
|
|
(production (:equality-expression :beta) ((:equality-expression :beta) != (:relational-expression :beta)) equality-expression-not-equal)
|
|
|
|
(production (:equality-expression :beta) ((:equality-expression :beta) === (:relational-expression :beta)) equality-expression-strict-equal)
|
|
|
|
(production (:equality-expression :beta) ((:equality-expression :beta) !== (:relational-expression :beta)) equality-expression-strict-not-equal)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Binary Bitwise Operators")
|
|
|
|
(production (:bitwise-and-expression :beta) ((:equality-expression :beta)) bitwise-and-expression-equality)
|
|
|
|
(production (:bitwise-and-expression :beta) ((:bitwise-and-expression :beta) & (:equality-expression :beta)) bitwise-and-expression-and)
|
|
|
|
|
|
|
|
(production (:bitwise-xor-expression :beta) ((:bitwise-and-expression :beta)) bitwise-xor-expression-bitwise-and)
|
|
|
|
(production (:bitwise-xor-expression :beta) ((:bitwise-xor-expression :beta) ^ (:bitwise-and-expression :beta)) bitwise-xor-expression-xor)
|
|
|
|
|
|
|
|
(production (:bitwise-or-expression :beta) ((:bitwise-xor-expression :beta)) bitwise-or-expression-bitwise-xor)
|
|
|
|
(production (:bitwise-or-expression :beta) ((:bitwise-or-expression :beta) \| (:bitwise-xor-expression :beta)) bitwise-or-expression-or)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Binary Logical Operators")
|
|
|
|
(production (:logical-and-expression :beta) ((:bitwise-or-expression :beta)) logical-and-expression-bitwise-or)
|
|
|
|
(production (:logical-and-expression :beta) ((:logical-and-expression :beta) && (:bitwise-or-expression :beta)) logical-and-expression-and)
|
|
|
|
|
|
|
|
(production (:logical-xor-expression :beta) ((:logical-and-expression :beta)) logical-xor-expression-logical-and)
|
|
|
|
(production (:logical-xor-expression :beta) ((:logical-xor-expression :beta) ^^ (:logical-and-expression :beta)) logical-xor-expression-xor)
|
|
|
|
|
|
|
|
(production (:logical-or-expression :beta) ((:logical-xor-expression :beta)) logical-or-expression-logical-xor)
|
|
|
|
(production (:logical-or-expression :beta) ((:logical-or-expression :beta) \|\| (:logical-xor-expression :beta)) logical-or-expression-or)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Conditional Operator")
|
|
|
|
(production (:conditional-expression :beta) ((:logical-or-expression :beta)) conditional-expression-logical-or)
|
|
|
|
(production (:conditional-expression :beta) ((:logical-or-expression :beta) ? (:assignment-expression :beta) \: (:assignment-expression :beta)) conditional-expression-conditional)
|
|
|
|
|
|
|
|
(production (:non-assignment-expression :beta) ((:logical-or-expression :beta)) non-assignment-expression-logical-or)
|
|
|
|
(production (:non-assignment-expression :beta) ((:logical-or-expression :beta) ? (:non-assignment-expression :beta) \: (:non-assignment-expression :beta)) non-assignment-expression-conditional)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Assignment Operators")
|
|
|
|
(production (:assignment-expression :beta) ((:conditional-expression :beta)) assignment-expression-conditional)
|
|
|
|
(production (:assignment-expression :beta) (:postfix-expression = (:assignment-expression :beta)) assignment-expression-assignment)
|
|
|
|
(production (:assignment-expression :beta) (:postfix-expression :compound-assignment (:assignment-expression :beta)) assignment-expression-compound)
|
|
|
|
|
|
|
|
(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-bitwise-and)
|
|
|
|
(production :compound-assignment (^=) compound-assignment-bitwise-xor)
|
|
|
|
(production :compound-assignment (\|=) compound-assignment-bitwise-or)
|
|
|
|
(production :compound-assignment (&&=) compound-assignment-logical-and)
|
|
|
|
(production :compound-assignment (^^=) compound-assignment-logical-xor)
|
|
|
|
(production :compound-assignment (\|\|=) compound-assignment-logical-or)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Comma Expressions")
|
|
|
|
(production (:list-expression :beta) ((:assignment-expression :beta)) list-expression-assignment)
|
|
|
|
(production (:list-expression :beta) ((:list-expression :beta) \, (:assignment-expression :beta)) list-expression-comma)
|
|
|
|
|
|
|
|
(production :optional-expression ((:list-expression allow-in)) optional-expression-expression)
|
|
|
|
(production :optional-expression () optional-expression-empty)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Type Expressions")
|
|
|
|
(production (:type-expression :beta) ((:non-assignment-expression :beta)) type-expression-non-assignment-expression)
|
|
|
|
|
|
|
|
|
|
|
|
(%section "Statements")
|
|
|
|
|
|
|
|
(grammar-argument :omega
|
|
|
|
abbrev ;optional semicolon when followed by a '}', 'else', or 'while' in a do-while
|
|
|
|
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_2 abbrev full)
|
|
|
|
|
|
|
|
(production (:top-statement :omega_2) ((:statement :omega_2)) top-statement-statement)
|
|
|
|
(production (:top-statement :omega_2) (:language-declaration (:noninsertable-semicolon :omega_2)) top-statement-language-declaration)
|
|
|
|
(production (:top-statement :omega_2) (:package-definition) top-statement-package-definition)
|
|
|
|
|
|
|
|
(production (:statement :omega) ((:annotated-definition :omega)) statement-annotated-definition)
|
|
|
|
(production (:statement :omega) (:empty-statement) statement-empty-statement)
|
|
|
|
(production (:statement :omega) (:expression-statement (:semicolon :omega)) statement-expression-statement)
|
|
|
|
(production (:statement :omega) (:annotated-block) statement-annotated-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) ((:with-statement :omega)) statement-with-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 (:statement :omega) (:use-statement (:semicolon :omega)) statement-use-statement)
|
2000-09-22 12:16:22 +04:00
|
|
|
(? js2
|
|
|
|
(production (:statement :omega) (:include-statement (:semicolon :omega)) statement-include-statement))
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production (:semicolon :omega) (\;) semicolon-semicolon)
|
|
|
|
(production (:semicolon :omega) ($virtual-semicolon) semicolon-virtual-semicolon)
|
|
|
|
(production (:semicolon abbrev) () semicolon-abbrev)
|
|
|
|
(production (:semicolon abbrev-no-short-if) () semicolon-abbrev-no-short-if)
|
|
|
|
|
|
|
|
(production (:noninsertable-semicolon :omega_2) (\;) noninsertable-semicolon-semicolon)
|
|
|
|
(production (:noninsertable-semicolon abbrev) () noninsertable-semicolon-abbrev)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Empty Statement")
|
|
|
|
(production :empty-statement (\;) empty-statement-semicolon)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Expression Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :expression-statement ((:- function { const) (:list-expression allow-in)) expression-statement-list-expression)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Block")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :annotated-block (:attributes :block) annotated-block-attributes-and-block)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :block ({ :top-statements }) block-top-statements)
|
|
|
|
|
|
|
|
(production :top-statements () top-statements-none)
|
|
|
|
(production :top-statements (:top-statements-prefix (:top-statement abbrev)) top-statements-more)
|
|
|
|
|
|
|
|
(production :top-statements-prefix () top-statements-prefix-none)
|
|
|
|
(production :top-statements-prefix (:top-statements-prefix (:top-statement full)) top-statements-prefix-more)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Labeled Statements")
|
|
|
|
(production (:labeled-statement :omega) (:identifier \: (:statement :omega)) labeled-statement-label)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "If Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:if-statement abbrev) (if :parenthesized-list-expression (:statement abbrev)) if-statement-if-then-abbrev)
|
|
|
|
(production (:if-statement full) (if :parenthesized-list-expression (:statement full)) if-statement-if-then-full)
|
|
|
|
(production (:if-statement :omega) (if :parenthesized-list-expression (:statement abbrev-no-short-if)
|
2000-09-09 06:15:37 +04:00
|
|
|
else (:statement :omega)) if-statement-if-then-else)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Switch Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :switch-statement (switch :parenthesized-list-expression { :case-statements }) switch-statement-cases)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production (:case-statement :omega_2) ((:statement :omega_2)) case-statement-statement)
|
|
|
|
(production (:case-statement :omega_2) (:case-label) case-statement-case-label)
|
|
|
|
|
|
|
|
(production :case-label (case (:list-expression allow-in) \:) case-label-case)
|
|
|
|
(production :case-label (default \:) case-label-default)
|
|
|
|
|
|
|
|
(production :case-statements () case-statements-none)
|
|
|
|
(production :case-statements (:case-label) case-statements-one)
|
|
|
|
(production :case-statements (:case-label :case-statements-prefix (:case-statement abbrev)) case-statements-more)
|
|
|
|
|
|
|
|
(production :case-statements-prefix () case-statements-prefix-none)
|
|
|
|
(production :case-statements-prefix (:case-statements-prefix (:case-statement full)) case-statements-prefix-more)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Do-While Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :do-statement (do (:statement abbrev) while :parenthesized-list-expression) do-statement-do-while)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "While Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:while-statement :omega) (while :parenthesized-list-expression (:statement :omega)) while-statement-while)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%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 (:list-expression allow-in) \) (:statement :omega)) for-statement-in)
|
|
|
|
|
|
|
|
(production :for-initializer () for-initializer-empty)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :for-initializer ((:- const) (:list-expression no-in)) for-initializer-expression)
|
|
|
|
(production :for-initializer (:attributes :variable-definition-kind (:variable-binding-list no-in)) for-initializer-variable-definition)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :for-in-binding ((:- const) :postfix-expression) for-in-binding-expression)
|
|
|
|
(production :for-in-binding (:attributes :variable-definition-kind (:variable-binding no-in)) for-in-binding-variable-definition)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "With Statement")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:with-statement :omega) (with :parenthesized-list-expression (:statement :omega)) with-statement-with)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Continue and Break Statements")
|
|
|
|
(production :continue-statement (continue) continue-statement-unlabeled)
|
|
|
|
(production :continue-statement (continue :no-line-break :identifier) continue-statement-labeled)
|
|
|
|
|
|
|
|
(production :break-statement (break) break-statement-unlabeled)
|
|
|
|
(production :break-statement (break :no-line-break :identifier) break-statement-labeled)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Return Statement")
|
|
|
|
(production :return-statement (return) return-statement-default)
|
|
|
|
(production :return-statement (return :no-line-break (:list-expression allow-in)) return-statement-expression)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Throw Statement")
|
|
|
|
(production :throw-statement (throw :no-line-break (:list-expression allow-in)) throw-statement-throw)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Try Statement")
|
|
|
|
(production :try-statement (try :annotated-block :catch-clauses) try-statement-catch-clauses)
|
|
|
|
(production :try-statement (try :annotated-block :finally-clause) try-statement-finally-clause)
|
|
|
|
(production :try-statement (try :annotated-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)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :catch-clause (catch \( :parameter \) :annotated-block) catch-clause-block)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :finally-clause (finally :annotated-block) finally-clause-block)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Use Statement")
|
|
|
|
(production :use-statement (use :no-line-break namespace :nonassignment-expression-list) use-statement-normal)
|
|
|
|
|
|
|
|
(production :nonassignment-expression-list ((:non-assignment-expression allow-in)) nonassignment-expression-list-one)
|
|
|
|
(production :nonassignment-expression-list (:nonassignment-expression-list \, (:non-assignment-expression allow-in)) nonassignment-expression-list-more)
|
|
|
|
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(? js2
|
|
|
|
(%subsection "Include Statement")
|
2000-10-10 06:49:34 +04:00
|
|
|
(production :include-statement (include :no-line-break $string) include-statement-include))
|
2000-09-23 12:15:06 +04:00
|
|
|
|
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(%section "Definitions")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:annotated-definition :omega) (:attributes (:definition :omega)) annotated-definition-attribute-and-definition)
|
|
|
|
|
|
|
|
(production :attributes () attributes-none)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :attributes (:attribute :no-line-break :attributes) attributes-more)
|
|
|
|
|
|
|
|
(production :attribute (:attribute-expression) attribute-attribute-expression)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :attribute (abstract) attribute-abstract)
|
|
|
|
(production :attribute (final) attribute-final)
|
|
|
|
(production :attribute (private) attribute-private)
|
|
|
|
(production :attribute (public) attribute-public)
|
|
|
|
(production :attribute (static) attribute-static)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:definition :omega) (:import-definition (:semicolon :omega)) definition-import-definition)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production (:definition :omega) (:export-definition (:semicolon :omega)) definition-export-definition)
|
|
|
|
(production (:definition :omega) (:variable-definition (:semicolon :omega)) definition-variable-definition)
|
|
|
|
(production (:definition :omega) ((:function-definition :omega)) definition-function-definition)
|
|
|
|
(production (:definition :omega) ((:class-definition :omega)) definition-class-definition)
|
|
|
|
(production (:definition :omega) (:namespace-definition (:semicolon :omega)) definition-namespace-definition)
|
2000-09-22 12:16:22 +04:00
|
|
|
(? js2
|
|
|
|
(production (:definition :omega) ((:interface-definition :omega)) definition-interface-definition))
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Import Definition")
|
2000-10-10 06:49:34 +04:00
|
|
|
(production :import-definition (import :import-binding) import-definition-import)
|
|
|
|
(production :import-definition (import :import-binding \: :nonassignment-expression-list) import-definition-import-and-use)
|
2000-09-22 12:16:22 +04:00
|
|
|
|
|
|
|
(production :import-binding (:import-item) import-binding-import-item)
|
|
|
|
(production :import-binding (:identifier = :import-item) import-binding-named-import-item)
|
|
|
|
|
|
|
|
(production :import-item ($string) import-item-string)
|
|
|
|
(production :import-item (:package-name) import-item-package-name)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Export Definition")
|
|
|
|
(production :export-definition (export :export-binding-list) export-definition-definition)
|
|
|
|
|
|
|
|
(production :export-binding-list (:export-binding) export-binding-list-one)
|
|
|
|
(production :export-binding-list (:export-binding-list \, :export-binding) export-binding-list-more)
|
|
|
|
|
|
|
|
(production :export-binding (:function-name) export-binding-simple)
|
|
|
|
(production :export-binding (:function-name = :function-name) export-binding-initializer)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Variable Definition")
|
|
|
|
(production :variable-definition (:variable-definition-kind (:variable-binding-list allow-in)) variable-definition-definition)
|
|
|
|
|
|
|
|
(production :variable-definition-kind (var) variable-definition-kind-var)
|
|
|
|
(production :variable-definition-kind (const) variable-definition-kind-const)
|
|
|
|
|
|
|
|
(production (:variable-binding-list :beta) ((:variable-binding :beta)) variable-binding-list-one)
|
|
|
|
(production (:variable-binding-list :beta) ((:variable-binding-list :beta) \, (:variable-binding :beta)) variable-binding-list-more)
|
|
|
|
|
|
|
|
(production (:variable-binding :beta) ((:typed-variable :beta)) variable-binding-simple)
|
|
|
|
(production (:variable-binding :beta) ((:typed-variable :beta) = (:assignment-expression :beta)) variable-binding-initialized)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:variable-binding :beta) ((:typed-variable :beta) = :multiple-attributes) variable-binding-multiple-attributes)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :multiple-attributes (:attribute :no-line-break :attribute) multiple-attributes-two)
|
|
|
|
(production :multiple-attributes (:multiple-attributes :no-line-break :attribute) multiple-attributes-more)
|
|
|
|
|
|
|
|
(production (:typed-variable :beta) (:identifier) typed-variable-identifier)
|
|
|
|
(production (:typed-variable :beta) (:identifier \: (:type-expression :beta)) typed-variable-identifier-and-type)
|
|
|
|
;(production (:typed-variable :beta) ((:type-expression :beta) :identifier) typed-variable-type-and-identifier)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Function Definition")
|
|
|
|
(production (:function-definition :omega) (:function-declaration :block) function-definition-definition)
|
|
|
|
(production (:function-definition :omega) (:function-declaration (:semicolon :omega)) function-definition-declaration)
|
|
|
|
|
|
|
|
(production :function-declaration (function :function-name :function-signature) function-declaration-signature-and-body)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :function-name (:identifier) function-name-function)
|
|
|
|
(production :function-name (get :no-line-break :identifier) function-name-getter)
|
|
|
|
(production :function-name (set :no-line-break :identifier) function-name-setter)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :function-signature (:parameter-signature :result-signature) function-signature-parameter-and-result-signatures)
|
|
|
|
|
|
|
|
(production :parameter-signature (\( :parameters \)) parameter-signature-parameters)
|
|
|
|
|
|
|
|
(production :parameters () parameters-none)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :parameters (:all-parameters) parameters-all-parameters)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :all-parameters (:parameter) all-parameters-parameter)
|
|
|
|
(production :all-parameters (:parameter \, :all-parameters) all-parameters-parameter-and-more)
|
|
|
|
(production :all-parameters (:optional-named-rest-parameters) all-parameters-optional-named-rest-parameters)
|
2000-09-23 12:15:06 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :optional-named-rest-parameters (:optional-parameter) optional-named-rest-parameters-optional-parameter)
|
|
|
|
(production :optional-named-rest-parameters (:optional-parameter \, :optional-named-rest-parameters) optional-named-rest-parameters-optional-parameter-and-more)
|
|
|
|
(production :optional-named-rest-parameters (\| :named-rest-parameters) optional-named-rest-parameters-named-rest-parameters)
|
|
|
|
(production :optional-named-rest-parameters (:rest-parameter) optional-named-rest-parameters-rest-parameter)
|
|
|
|
(production :optional-named-rest-parameters (:rest-parameter \, \| :named-parameters) optional-named-rest-parameters-rest-and-named)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :named-rest-parameters (:named-parameter) named-rest-parameters-named-parameter)
|
|
|
|
(production :named-rest-parameters (:named-parameter \, :named-rest-parameters) named-rest-parameters-named-parameter-and-more)
|
|
|
|
(production :named-rest-parameters (:rest-parameter) named-rest-parameters-rest-parameter)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :named-parameters (:named-parameter) named-parameters-named-parameter)
|
|
|
|
(production :named-parameters (:named-parameter \, :named-parameters) named-parameters-named-parameter-and-more)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :rest-parameter (\.\.\.) rest-parameter-none)
|
|
|
|
(production :rest-parameter (\.\.\. :parameter) rest-parameter-parameter)
|
|
|
|
;(production :rest-parameter (\.\.\. :optional-parameter) rest-parameter-optional-parameter)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :parameter (:identifier) parameter-identifier)
|
|
|
|
(production :parameter (:identifier \: (:type-expression allow-in)) parameter-identifier-and-type)
|
|
|
|
;(production :parameter ((:- $string) (:type-expression allow-in) :identifier) parameter-type-and-identifier)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :optional-parameter (:parameter = (:assignment-expression allow-in)) optional-parameter-assignment-expression)
|
|
|
|
|
|
|
|
(production :named-parameter (:parameter) named-parameter-parameter)
|
|
|
|
(production :named-parameter (:optional-parameter) named-parameter-optional-parameter)
|
|
|
|
(production :named-parameter ($string :named-parameter) named-parameter-name)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(production :result-signature () result-signature-none)
|
|
|
|
(production :result-signature (\: (:type-expression allow-in)) result-signature-colon-and-type-expression)
|
|
|
|
;(production :result-signature ((:- {) (:type-expression allow-in)) result-signature-type-expression)
|
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Class Definition")
|
2000-09-23 12:15:06 +04:00
|
|
|
(production (:class-definition :omega) (class :identifier :inheritance :block) class-definition-definition)
|
2000-09-22 12:16:22 +04:00
|
|
|
(production (:class-definition :omega) (class :identifier (:semicolon :omega)) class-definition-declaration)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
2000-09-23 12:15:06 +04:00
|
|
|
(production :inheritance () inheritance-none)
|
|
|
|
(production :inheritance (extends (:type-expression allow-in)) inheritance-extends)
|
2000-09-22 12:16:22 +04:00
|
|
|
(? js2
|
2000-09-23 12:15:06 +04:00
|
|
|
(production :inheritance (implements :type-expression-list) inheritance-implements)
|
|
|
|
(production :inheritance (extends (:type-expression allow-in) implements :type-expression-list) inheritance-extends-implements)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(%subsection "Interface Definition")
|
|
|
|
(production (:interface-definition :omega) (interface :identifier :extends-list :block) interface-definition-definition)
|
|
|
|
(production (:interface-definition :omega) (interface :identifier (:semicolon :omega)) interface-definition-declaration))
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%subsection "Namespace Definition")
|
|
|
|
(production :namespace-definition (namespace :identifier :extends-list) namespace-definition-normal)
|
|
|
|
|
|
|
|
(production :extends-list () extends-list-none)
|
|
|
|
(production :extends-list (extends :type-expression-list) extends-list-one)
|
|
|
|
|
2000-09-23 12:15:06 +04:00
|
|
|
(production :type-expression-list ((:type-expression allow-in)) type-expression-list-one)
|
|
|
|
(production :type-expression-list (:type-expression-list \, (:type-expression allow-in)) type-expression-list-more)
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
(%section "Language Declaration")
|
|
|
|
(production :language-declaration (use :language-alternatives) language-declaration-language-alternatives)
|
|
|
|
|
|
|
|
(production :language-alternatives (:language-ids) language-alternatives-one)
|
|
|
|
(production :language-alternatives (:language-alternatives \| :language-ids) language-alternatives-more)
|
|
|
|
|
|
|
|
(production :language-ids () language-ids-none)
|
|
|
|
(production :language-ids (:language-id :language-ids) language-ids-more)
|
|
|
|
|
|
|
|
(production :language-id (:identifier) language-id-identifier)
|
|
|
|
(production :language-id ($number) language-id-number)
|
|
|
|
|
|
|
|
|
|
|
|
(%section "Package Definition")
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :package-definition (package :block) package-definition-anonymous)
|
2000-09-09 06:15:37 +04:00
|
|
|
(production :package-definition (package :package-name :block) package-definition-named)
|
|
|
|
|
2000-09-22 12:16:22 +04:00
|
|
|
(production :package-name (:identifier) package-name-one)
|
|
|
|
(production :package-name (:package-name \. :identifier) package-name-more)
|
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
|
|
|
|
(%section "Programs")
|
|
|
|
(production :program (:top-statements) program-top-statements)))
|
2000-05-01 10:21:39 +04:00
|
|
|
|
2000-08-22 08:31:37 +04:00
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(defparameter *jw* (generate-world "J" *jw-source* '((js2 . :js2) (es4 . :es4))))
|
|
|
|
(defparameter *jg* (world-grammar *jw* 'code-grammar))
|
|
|
|
(ensure-lf-subset *jg*)
|
|
|
|
(forward-parser-states *jg*)
|
|
|
|
#+allegro (clean-grammar *jg*) ;Remove this line if you wish to print the grammar's state tables.
|
2000-05-01 10:21:39 +04:00
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(defparameter *ew* nil)
|
|
|
|
(defparameter *eg* nil)
|
1999-05-11 00:52:58 +04:00
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(defun compute-ecma-subset ()
|
|
|
|
(unless *ew*
|
|
|
|
(setq *ew* (generate-world "E" *jw-source* '((js2 . delete) (es4 . nil))))
|
|
|
|
(setq *eg* (world-grammar *ew* 'code-grammar))
|
|
|
|
(ensure-lf-subset *eg*)
|
|
|
|
(forward-parser-states *eg*))
|
|
|
|
(length (grammar-states *eg*)))
|
1999-05-11 00:52:58 +04:00
|
|
|
|
|
|
|
|
1999-12-04 01:53:21 +03:00
|
|
|
; Print a list of states that have both $REGULAR-EXPRESSION and either / or /= as valid lookaheads.
|
|
|
|
(defun show-regexp-and-division-states (grammar)
|
|
|
|
(all-state-transitions
|
|
|
|
#'(lambda (state transitions-hash)
|
|
|
|
(when (and (gethash '$regular-expression transitions-hash)
|
|
|
|
(or (gethash '/ transitions-hash) (gethash '/= transitions-hash)))
|
|
|
|
(format *error-output* "State ~S~%" state)))
|
|
|
|
grammar))
|
|
|
|
|
|
|
|
|
|
|
|
; Return five values:
|
|
|
|
; A list of terminals that may precede a $regular-expression terminal;
|
|
|
|
; A list of terminals that may precede a $virtual-semicolon but not / or /= terminal;
|
|
|
|
; A list of terminals that may precede a / or /= terminal;
|
|
|
|
; The intersection of the $regular-expression and /|/= lists.
|
|
|
|
; The intersection of the $regular-expression|$virtual-semicolon and /|/= lists.
|
1999-12-04 08:04:08 +03:00
|
|
|
;
|
|
|
|
; USE ONLY ON canonical-lr-1 grammars.
|
|
|
|
; DON'T RUN THIS AFTER CALLING forward-parser-states.
|
1999-12-04 01:53:21 +03:00
|
|
|
(defun show-regexp-and-division-predecessors (grammar)
|
|
|
|
(let* ((nstates (length (grammar-states grammar)))
|
|
|
|
(state-predecessors (make-array nstates :element-type 'terminalset :initial-element *empty-terminalset*)))
|
|
|
|
(dolist (state (grammar-states grammar))
|
|
|
|
(dolist (transition-pair (state-transitions state))
|
|
|
|
(let ((transition (cdr transition-pair)))
|
|
|
|
(when (eq (transition-kind transition) :shift)
|
|
|
|
(terminalset-union-f (svref state-predecessors (state-number (transition-state transition)))
|
|
|
|
(make-terminalset grammar (car transition-pair)))))))
|
|
|
|
(let ((regexp-predecessors *empty-terminalset*)
|
|
|
|
(virtual-predecessors *empty-terminalset*)
|
|
|
|
(div-predecessors *empty-terminalset*))
|
|
|
|
(all-state-transitions
|
|
|
|
#'(lambda (state transitions-hash)
|
1999-12-04 08:04:08 +03:00
|
|
|
(let ((predecessors (svref state-predecessors (state-number state))))
|
|
|
|
(when (gethash '$regular-expression transitions-hash)
|
|
|
|
(terminalset-union-f regexp-predecessors predecessors))
|
|
|
|
(if (or (gethash '/ transitions-hash) (gethash '/= transitions-hash))
|
|
|
|
(terminalset-union-f div-predecessors predecessors)
|
|
|
|
(when (gethash '$virtual-semicolon transitions-hash)
|
|
|
|
(terminalset-union-f virtual-predecessors predecessors)))))
|
1999-12-04 01:53:21 +03:00
|
|
|
grammar)
|
|
|
|
(values
|
|
|
|
(terminalset-list grammar regexp-predecessors)
|
|
|
|
(terminalset-list grammar virtual-predecessors)
|
|
|
|
(terminalset-list grammar div-predecessors)
|
|
|
|
(terminalset-list grammar (terminalset-intersection regexp-predecessors div-predecessors))
|
|
|
|
(terminalset-list grammar (terminalset-intersection (terminalset-union regexp-predecessors virtual-predecessors) div-predecessors))))))
|
|
|
|
|
|
|
|
|
1999-05-11 00:52:58 +04:00
|
|
|
(defun depict-js-terminals (markup-stream grammar)
|
|
|
|
(labels
|
2000-05-01 10:21:39 +04:00
|
|
|
((production-first-terminal (production)
|
|
|
|
(first (production-rhs production)))
|
2000-08-22 08:31:37 +04:00
|
|
|
|
2000-05-01 10:21:39 +04:00
|
|
|
(terminal-bin (terminal)
|
1999-05-11 00:52:58 +04:00
|
|
|
(if (and terminal (symbolp terminal))
|
|
|
|
(let ((name (symbol-name terminal)))
|
|
|
|
(if (> (length name) 0)
|
|
|
|
(let ((first-char (char name 0)))
|
|
|
|
(cond
|
|
|
|
((char= first-char #\$) 0)
|
|
|
|
((not (or (char= first-char #\_) (alphanumericp first-char))) 1)
|
2000-08-22 08:31:37 +04:00
|
|
|
((member terminal (rule-productions (grammar-rule grammar ':identifier)) :key #'production-first-terminal) 5)
|
1999-05-11 00:52:58 +04:00
|
|
|
(t 3)))
|
|
|
|
1))
|
|
|
|
1))
|
|
|
|
|
|
|
|
(depict-terminal-bin (bin-name bin-terminals)
|
|
|
|
(when bin-terminals
|
|
|
|
(depict-paragraph (markup-stream ':body-text)
|
|
|
|
(depict markup-stream bin-name)
|
|
|
|
(depict-list markup-stream #'depict-terminal bin-terminals :separator '(" " :spc " "))))))
|
|
|
|
|
2000-04-28 06:34:14 +04:00
|
|
|
(let* ((bins (make-array 6 :initial-element nil))
|
|
|
|
(all-terminals (grammar-terminals grammar))
|
|
|
|
(terminals (remove-if #'lf-terminal? all-terminals)))
|
|
|
|
(assert-true (= (length all-terminals) (1- (* 2 (length terminals)))))
|
1999-05-11 00:52:58 +04:00
|
|
|
(setf (svref bins 2) (list '\# '&&= '-> '@ '^^ '^^= '\|\|=))
|
2000-10-10 06:49:34 +04:00
|
|
|
(setf (svref bins 4) (list 'abstract 'class 'const 'debugger 'enum 'export 'extends 'final 'goto 'implements 'import
|
2000-05-01 10:21:39 +04:00
|
|
|
'interface 'native 'package 'private 'protected 'public 'static 'super 'synchronized
|
1999-11-12 10:24:19 +03:00
|
|
|
'throws 'transient 'volatile))
|
2000-09-22 12:16:22 +04:00
|
|
|
; Used to be reserved in JavaScript 1.5: 'boolean 'byte 'char 'double 'float 'int 'long 'short
|
1999-05-11 00:52:58 +04:00
|
|
|
(do ((i (length terminals)))
|
|
|
|
((zerop i))
|
|
|
|
(let ((terminal (aref terminals (decf i))))
|
|
|
|
(unless (eq terminal *end-marker*)
|
|
|
|
(setf (svref bins 2) (delete terminal (svref bins 2)))
|
|
|
|
(setf (svref bins 4) (delete terminal (svref bins 4)))
|
|
|
|
(push terminal (svref bins (terminal-bin terminal))))))
|
|
|
|
(depict-paragraph (markup-stream ':section-heading)
|
|
|
|
(depict markup-stream "Terminals"))
|
|
|
|
(mapc #'depict-terminal-bin '("General tokens: " "Punctuation tokens: " "Future punctuation tokens: "
|
|
|
|
"Reserved words: " "Future reserved words: " "Non-reserved words: ")
|
|
|
|
(coerce bins 'list)))))
|
|
|
|
|
|
|
|
|
|
|
|
#|
|
2000-09-09 06:15:37 +04:00
|
|
|
(values
|
|
|
|
(length (grammar-states *jg*))
|
|
|
|
(depict-rtf-to-local-file
|
2000-09-12 03:49:53 +04:00
|
|
|
"JS20/ParserGrammarJS2.rtf"
|
2000-09-09 06:15:37 +04:00
|
|
|
"JavaScript 2.0 Parser Grammar"
|
|
|
|
#'(lambda (markup-stream)
|
|
|
|
(depict-js-terminals markup-stream *jg*)
|
|
|
|
(depict-world-commands markup-stream *jw* :visible-semantics nil)))
|
|
|
|
(compute-ecma-subset)
|
|
|
|
(depict-rtf-to-local-file
|
2000-09-12 03:49:53 +04:00
|
|
|
"JS20/ParserGrammarES4.rtf"
|
2000-09-09 06:15:37 +04:00
|
|
|
"ECMAScript Edition 4 Parser Grammar"
|
|
|
|
#'(lambda (markup-stream)
|
|
|
|
(depict-js-terminals markup-stream *eg*)
|
|
|
|
(depict-world-commands markup-stream *ew* :visible-semantics nil))))
|
1999-05-11 00:52:58 +04:00
|
|
|
|
2000-09-09 06:15:37 +04:00
|
|
|
(values
|
|
|
|
(length (grammar-states *jg*))
|
|
|
|
(depict-html-to-local-file
|
2000-09-12 03:49:53 +04:00
|
|
|
"JS20/ParserGrammarJS2.html"
|
2000-09-09 06:15:37 +04:00
|
|
|
"JavaScript 2.0 Parser Grammar"
|
|
|
|
t
|
|
|
|
#'(lambda (markup-stream)
|
|
|
|
(depict-js-terminals markup-stream *jg*)
|
|
|
|
(depict-world-commands markup-stream *jw* :visible-semantics nil)))
|
|
|
|
(compute-ecma-subset)
|
|
|
|
(depict-html-to-local-file
|
2000-09-12 03:49:53 +04:00
|
|
|
"JS20/ParserGrammarES4.html"
|
2000-09-09 06:15:37 +04:00
|
|
|
"ECMAScript Edition 4 Parser Grammar"
|
|
|
|
t
|
|
|
|
#'(lambda (markup-stream)
|
|
|
|
(depict-js-terminals markup-stream *eg*)
|
|
|
|
(depict-world-commands markup-stream *ew* :visible-semantics nil))))
|
1999-05-11 00:52:58 +04:00
|
|
|
|
2000-09-12 03:49:53 +04:00
|
|
|
(with-local-output (s "JS20/ParserGrammarJS2 states") (print-grammar *jg* s))
|
2000-09-09 06:15:37 +04:00
|
|
|
(compute-ecma-subset)
|
2000-09-12 03:49:53 +04:00
|
|
|
(with-local-output (s "JS20/ParserGrammarES4 states") (print-grammar *eg* s))
|
1999-05-11 00:52:58 +04:00
|
|
|
|#
|
|
|
|
|
|
|
|
(length (grammar-states *jg*))
|