pjs/js2/semantics/JS20/Parser.lisp

1883 строки
98 KiB
Common Lisp
Исходник Обычный вид История

1999-05-11 00:52:58 +04:00
;;;
;;; JavaScript 2.0 parser
1999-05-11 00:52:58 +04:00
;;;
;;; Waldemar Horwat (waldemar@acm.org)
1999-05-11 00:52:58 +04:00
;;;
(declaim (optimize (debug 3)))
(defparameter *jw-source*
'((line-grammar code-grammar :lr-1 :program)
2001-03-01 08:31:28 +03:00
(%subsection :semantics "Errors")
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(deftag syntax-error)
(deftag reference-error)
(deftag type-error)
(deftag method-not-found-error)
(deftype semantic-error (tag syntax-error reference-error type-error method-not-found-error))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(deftag go-break (value object) (label string))
(deftag go-continue (value object) (label string))
(deftag go-return (value object))
(deftag go-throw (value object))
(deftype early-exit (tag go-break go-continue go-return go-throw))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(deftype semantic-exception (union early-exit semantic-error))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(%subsection :semantics "Undefined")
(deftag undefined)
(deftype undefined (tag undefined))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(%subsection :semantics "Null")
(deftag null)
(deftype null (tag null))
2001-03-01 08:31:28 +03:00
2001-02-07 08:08:44 +03:00
(%subsection :semantics "Namespaces")
2001-04-12 08:31:46 +04:00
(defrecord namespace)
(deftype namespace (tag namespace))
2001-04-12 08:31:46 +04:00
(define public-namespace namespace (tag namespace))
2001-02-07 08:08:44 +03:00
(%subsection :semantics "Classes")
2001-04-12 08:31:46 +04:00
(defrecord class
(superclass class-opt)
(globals (vector property) :var)
(prototype object :var)
(primitive boolean))
(deftype class (tag class))
(deftype class-opt (union null class))
(define object-class class (tag class null (vector-of property) null true))
(define undefined-class class (tag class object-class (vector-of property) null true))
(define null-class class (tag class object-class (vector-of property) null true))
(define boolean-class class (tag class object-class (vector-of property) null true))
(define number-class class (tag class object-class (vector-of property) null true))
(define string-class class (tag class object-class (vector-of property) null false))
(define namespace-class class (tag class object-class (vector-of property) null false))
(define class-class class (tag class object-class (vector-of property) null false))
(%text :comment "Return " (:tag true) " if " (:local c) " is " (:local d) " or a subclass of " (:local d) ".")
(define (is-subclass (c class) (d class)) boolean
2001-04-12 08:31:46 +04:00
(cond
((= c d class) (return true))
(nil (const b class-opt (& superclass c))
(rwhen (:narrow-false (in (tag null) b))
(return false))
(return (is-subclass b d)))))
(%text :comment "Return " (:tag true) " if " (:local c) " is a subclass of " (:local d) " other than " (:local d) " itself.")
2001-03-01 08:31:28 +03:00
(define (is-proper-subclass (c class) (d class)) boolean
2001-04-12 08:31:46 +04:00
(const b class-opt (& superclass c))
(rwhen (:narrow-false (in (tag null) b))
(return false))
(return (is-subclass b d)))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(%subsection :semantics "Structures")
(defrecord structure
(type class)
(slots (vector slot) :var)
(properties (vector property) :var))
(deftype structure (tag structure))
(%subsection :semantics "Objects")
(deftype object (union undefined null boolean float64 string namespace class structure))
(%text :comment "Return " (:local o) :apostrophe "s most specific type.")
(define (object-type (o object)) class
(case o
(:select undefined (return undefined-class))
(:select null (return null-class))
(:select boolean (return boolean-class))
(:select float64 (return number-class))
(:select string (return string-class))
(:select namespace (return namespace-class))
(:select class (return class-class))
(:narrow structure (return (& type o)))))
(%text :comment "Return " (:tag true) " if " (:local o) " is an instance of class " (:local c) ". Consider "
(:tag null) " to be an instance of the classes " (:character-literal "Null") " and "
2001-02-07 08:08:44 +03:00
(:character-literal "Object") " only.")
2001-04-12 08:31:46 +04:00
(define (instance-of (o object) (c class)) boolean
(return (is-subclass (object-type o) c)))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "Return " (:tag true) " if " (:local o) " is an instance of class " (:local c) ". Consider "
(:tag null) " to be an instance of the classes " (:character-literal "Null") ", "
2001-02-07 08:08:44 +03:00
(:character-literal "Object") ", and all other non-primitive classes.")
2001-04-12 08:31:46 +04:00
(define (member-of (o object) (c class)) boolean
(const t class (object-type o))
(return (or (is-subclass t c)
(and (= o null object) (not (& primitive c))))))
(define (to-boolean (o object)) boolean
(case o
(:select (union undefined null) (return false))
(:narrow boolean (return o))
(:narrow float64 (return (not-in (tag +zero -zero nan) o)))
(:narrow string (return (/= o "" string)))
(:select (union namespace class) (return true))
(:select structure (todo))))
(define (to-number (o object)) float64
(case o
(:select undefined (return nan))
(:select (union null false) (return +zero))
(:select true (return 1.0))
(:narrow float64 (return o))
(:select string (todo))
(:select (union namespace class) (throw type-error))
(:select structure (todo))))
(define (to-string (o object)) string
(case o
(:select undefined (return "undefined"))
(:select null (return "null"))
(:select false (return "false"))
(:select true (return "true"))
(:select float64 (todo))
(:narrow string (return o))
(:select namespace (todo))
(:select class (todo))
(:select structure (todo))))
(define (to-primitive (o object) (hint object :unused)) object
(case o
(:select (union undefined null boolean float64 string) (return o))
(:select (union namespace class structure) (return (to-string o)))))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(define (u-int32-to-int32 (i integer)) integer
(if (< i (expt 2 31))
(return i)
(return (- i (expt 2 32)))))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(define (to-u-int32 (x float64)) integer
(rwhen (:narrow-false (in (tag +infinity -infinity nan) x))
(return 0))
(return (mod (truncate-float64 x) (expt 2 32))))
(define (to-int32 (x float64)) integer
(return (u-int32-to-int32 (to-u-int32 x))))
2001-04-12 08:31:46 +04:00
(define (float64-equal (x float64) (y float64)) boolean
(return (float64-compare x y false true false false)))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(%subsection :semantics "References")
(deftag ref)
(deftype ref (tag ref))
(deftype reference (union object ref))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "Read the " (:type reference) ".")
(define (read-reference (r reference)) object
(case r
(:narrow object (return r))
(:select ref (todo))))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "Write " (:local v) " into the " (:type reference) " " (:local r) ".")
(define (write-reference (r reference) (v object :unused)) void
(case r
(:select object (throw reference-error))
(:select ref (todo))))
(%subsection :semantics "Slots")
(defrecord slot-id)
(deftype slot-id (tag slot-id))
2001-04-12 08:31:46 +04:00
(defrecord slot
(id slot-id)
(type class)
(value object :var))
(deftype slot (tag slot))
2001-04-12 08:31:46 +04:00
(define (find-slot (id slot-id) (slots (vector slot))) slot
(const matching-slots (vector slot)
(map slots s s (= (& id s) id slot-id)))
(assert (= (length matching-slots) 1))
(return (nth matching-slots 0)))
(%subsection :semantics "Properties")
(deftag property
(name qualified-name)
(getter accessor-info)
(setter accessor-info)
(fixed boolean)
(enumerable boolean)
(deletable boolean))
(deftype property (tag property))
(deftag qualified-name (namespace namespace) (name string))
(deftype qualified-name (tag qualified-name))
2001-02-09 08:00:28 +03:00
(define (find-property (n qualified-name) (properties (vector property))) (vector property)
2001-04-12 08:31:46 +04:00
(return (map properties p p (= n (& name p) qualified-name))))
2001-02-07 08:08:44 +03:00
(%subsection :semantics "Accessors")
2001-04-12 08:31:46 +04:00
(deftag inaccessible-accessor)
(deftag abstract-accessor)
(deftag constant-accessor (value object))
(deftag slot-accessor (id slot-id))
(deftag indirect-accessor (f object))
(deftag alias-accessor (name qualified-name))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(deftype accessor (tag inaccessible-accessor abstract-accessor constant-accessor slot-accessor indirect-accessor alias-accessor))
(deftag accessor-info
(self-type class)
(final boolean)
(accessor accessor))
(deftype accessor-info (tag accessor-info))
2001-02-07 08:08:44 +03:00
2001-03-01 08:31:28 +03:00
(%subsection :semantics "Binary Operators")
2001-04-12 08:31:46 +04:00
(deftag bin-op-method
(left-type class)
(right-type class)
(op (-> (object object) object)))
(deftype bin-op-method (tag bin-op-method))
(defrecord binary-operator
(methods (vector bin-op-method) :var))
(deftype binary-operator (tag binary-operator))
(%text :comment "Return " (:tag true) " if " (:local m1) " is at least as specific as " (:local m2) ".")
(define (is-bin-op-subclass (m1 bin-op-method) (m2 bin-op-method)) boolean
(return (and (is-subclass (& left-type m1) (& left-type m2))
(is-subclass (& right-type m1) (& right-type m2)))))
(define (limited-instance-of (v object) (c class) (limit class-opt)) boolean
(if (instance-of v c)
(if (:narrow-false (in (tag null) limit))
(return true)
(return (is-proper-subclass limit c)))
(return false)))
(%text :comment "Return a function that takes two " (:type object) " arguments " (:local left) " and " (:local right)
" and returns the operator " (:local bin-op) " applied to " (:local left) " and " (:local right)
". If " (:local left-limit) " is a " (:type class)
2001-03-01 08:31:28 +03:00
", restrict the lookup to operator definitions with a superclass of " (:local left-limit)
2001-04-12 08:31:46 +04:00
" for the left operand. Similarly, if " (:local right-limit) " is a " (:type class)
2001-03-01 08:31:28 +03:00
", restrict the lookup to operator definitions with a superclass of " (:local right-limit) " for the right operand.")
2001-04-12 08:31:46 +04:00
(define (bin-op-eval (bin-op binary-operator) (left-limit class-opt) (right-limit class-opt)) (-> (object object) object)
(function (f (left object) (right object)) object
(const applicable-ops (vector bin-op-method)
(map (& methods bin-op) m m (and (limited-instance-of left (& left-type m) left-limit)
(limited-instance-of right (& right-type m) right-limit))))
(const best-ops (vector bin-op-method)
(map applicable-ops m m
(empty (map applicable-ops m2 m2 (not (is-bin-op-subclass m m2))))))
(rwhen (empty best-ops)
(throw method-not-found-error))
(assert (= (length best-ops) 1))
(return ((& op (nth best-ops 0)) left right)))
(return f))
2001-03-01 08:31:28 +03:00
2001-03-03 02:15:54 +03:00
(%subsection :semantics "Binary Operator Tables")
2001-04-12 08:31:46 +04:00
(define (add-objects (a object) (b object)) object
(const ap object (to-primitive a null))
(const bp object (to-primitive b null))
(if (or (in string ap) (in string bp))
(return (append (to-string ap) (to-string bp)))
(return (float64-add (to-number ap) (to-number bp)))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (subtract-objects (a object) (b object)) object
(return (float64-subtract (to-number a) (to-number b))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (multiply-objects (a object) (b object)) object
(return (float64-multiply (to-number a) (to-number b))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (divide-objects (a object) (b object)) object
(return (float64-divide (to-number a) (to-number b))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (remainder-objects (a object) (b object)) object
(return (float64-remainder (to-number a) (to-number b))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (less-objects (a object) (b object)) object
(const ap object (to-primitive a null))
(const bp object (to-primitive b null))
(if (:narrow-true (and (in string ap) (in string bp)))
(return (< ap bp string))
(return (float64-compare (to-number ap) (to-number bp) true false false false))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (less-or-equal-objects (a object) (b object)) object
(const ap object (to-primitive a null))
(const bp object (to-primitive b null))
(if (:narrow-true (and (in string ap) (in string bp)))
(return (<= ap bp string))
(return (float64-compare (to-number ap) (to-number bp) true true false false))))
2001-03-03 02:15:54 +03:00
2001-04-12 08:31:46 +04:00
(define (equal-objects (a object) (b object)) object
2001-03-03 02:15:54 +03:00
(case a
2001-04-12 08:31:46 +04:00
(:select (union undefined null)
(return (in (union undefined null) b)))
(:narrow boolean
(if (:narrow-true (in boolean b))
(return (= a b boolean))
(return (equal-objects (to-number a) b))))
(:narrow float64
(const bp object (to-primitive b null))
(case bp
(:select (union undefined null namespace class structure) (return false))
(:select (union boolean string float64) (return (float64-equal a (to-number bp))))))
(:narrow string
(const bp object (to-primitive b null))
(case bp
(:select (union undefined null namespace class structure) (return false))
(:select (union boolean float64) (return (float64-equal (to-number a) (to-number bp))))
(:narrow string (return (= a bp string)))))
(:select (union namespace class structure)
(case b
(:select (union undefined null) (return false))
(:select (union namespace class structure) (return (strict-equal-objects a b)))
(:select (union boolean float64 string)
(const ap object (to-primitive a null))
2001-03-03 02:15:54 +03:00
(case ap
2001-04-12 08:31:46 +04:00
(:select (union undefined null namespace class structure) (return false))
(:select (union boolean float64 string) (return (equal-objects ap b)))))))))
(define (strict-equal-objects (a object) (b object)) object
(if (:narrow-true (and (in float64 a) (in float64 b)))
(return (float64-equal a b))
(return (= a b object))))
(define (shift-left-objects (a object) (b object)) object
(const i integer (to-u-int32 (to-number a)))
(const count integer (bitwise-and (to-u-int32 (to-number b)) (hex #x1F)))
(return (real-to-float64 (u-int32-to-int32 (bitwise-and (bitwise-shift i count) (hex #xFFFFFFFF))))))
(define (shift-right-objects (a object) (b object)) object
(const i integer (to-int32 (to-number a)))
(const count integer (bitwise-and (to-u-int32 (to-number b)) (hex #x1F)))
(return (real-to-float64 (bitwise-shift i (neg count)))))
(define (shift-right-unsigned-objects (a object) (b object)) object
(const i integer (to-u-int32 (to-number a)))
(const count integer (bitwise-and (to-u-int32 (to-number b)) (hex #x1F)))
(return (real-to-float64 (bitwise-shift i (neg count)))))
(define (bitwise-and-objects (a object) (b object)) object
(const i integer (to-int32 (to-number a)))
(const j integer (to-int32 (to-number b)))
(return (real-to-float64 (bitwise-and i j))))
(define (bitwise-xor-objects (a object) (b object)) object
(const i integer (to-int32 (to-number a)))
(const j integer (to-int32 (to-number b)))
(return (real-to-float64 (bitwise-xor i j))))
(define (bitwise-or-objects (a object) (b object)) object
(const i integer (to-int32 (to-number a)))
(const j integer (to-int32 (to-number b)))
(return (real-to-float64 (bitwise-or i j))))
(define bin-op-add binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class add-objects))))
(define bin-op-subtract binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class subtract-objects))))
(define bin-op-multiply binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class multiply-objects))))
(define bin-op-divide binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class divide-objects))))
(define bin-op-remainder binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class remainder-objects))))
(define bin-op-less binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class less-objects))))
(define bin-op-less-or-equal binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class less-or-equal-objects))))
(define bin-op-equal binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class equal-objects))))
(define bin-op-strict-equal binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class strict-equal-objects))))
(define bin-op-shift-left binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class shift-left-objects))))
(define bin-op-shift-right binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class shift-right-objects))))
(define bin-op-shift-right-unsigned binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class shift-right-unsigned-objects))))
(define bin-op-bitwise-and binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class bitwise-and-objects))))
(define bin-op-bitwise-xor binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class bitwise-xor-objects))))
(define bin-op-bitwise-or binary-operator (tag binary-operator (vector (tag bin-op-method object-class object-class bitwise-or-objects))))
2001-03-01 08:31:28 +03:00
(%subsection :semantics "Unary Operators")
2001-04-12 08:31:46 +04:00
(deftag unary-operator
(operand-type class)
(op (-> (object) object)))
(deftype unary-operator (tag unary-operator))
2001-02-07 08:08:44 +03:00
2001-04-12 08:31:46 +04:00
(define (unary-not (a object)) object
(return (not (to-boolean a))))
2001-03-03 02:15:54 +03:00
2001-02-07 08:08:44 +03:00
2001-02-09 08:00:28 +03:00
(%subsection :semantics "Environments")
2001-04-12 08:31:46 +04:00
(deftag static-env
(enclosing-class class-opt)
(labels (vector string))
(can-return boolean)
(constants (vector definition)))
(deftype static-env (tag static-env))
2001-04-12 08:31:46 +04:00
(define initial-static-env static-env (tag static-env null (vector-of string) false (vector-of definition)))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "Return a " (:type static-env) " with label " (:local label) " prepended to " (:local s) ".")
(define (add-label (t static-env) (label string)) static-env
(return (tag static-env (& enclosing-class t) (append (vector label) (& labels t)) (& can-return t) (& constants t))))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "Return " (:tag true) " if " (:character-literal "super") " is permitted here.")
2001-03-01 08:31:28 +03:00
(define (allows-super (s static-env)) boolean
2001-04-12 08:31:46 +04:00
(return (/= (& enclosing-class s) null class-opt)))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(deftag dynamic-env
(parent dynamic-env-opt)
(definitions (vector definition)))
(deftype dynamic-env (tag dynamic-env))
(deftype dynamic-env-opt (union null dynamic-env))
2001-02-09 08:00:28 +03:00
2001-04-12 08:31:46 +04:00
(%text :comment "If the " (:type dynamic-env) " is from within a class" :apostrophe "s body, return that class; otherwise, return " (:tag null) ".")
(define (lexical-class (e dynamic-env :unused)) class-opt
2001-03-01 08:31:28 +03:00
(todo))
2001-04-12 08:31:46 +04:00
(define initial-dynamic-env dynamic-env (tag dynamic-env null (vector-of definition)))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(deftag definition
(name qualified-name)
(getter accessor-info)
(setter accessor-info))
(deftype definition (tag definition))
2001-03-01 08:31:28 +03:00
(%section "Terminal Actions")
2001-04-12 08:31:46 +04:00
(declare-action name $identifier string 1)
(declare-action eval $number float64 1)
(declare-action eval $string string 1)
2001-03-01 08:31:28 +03:00
(terminal-action name $identifier identity)
(terminal-action eval $number identity)
(terminal-action eval $string identity)
(%print-actions)
(%section "Expressions")
(grammar-argument :beta allow-in no-in)
(%subsection "Identifiers")
2001-03-01 08:31:28 +03:00
(rule :identifier ((name string))
(production :identifier ($identifier) identifier-identifier (name (name $identifier)))
(production :identifier (get) identifier-get (name "get"))
(production :identifier (set) identifier-set (name "set"))
(production :identifier (exclude) identifier-exclude (name "exclude"))
(production :identifier (include) identifier-include (name "include")))
(production :qualifier (:identifier) qualifier-identifier)
(production :qualifier (public) qualifier-public)
(production :qualifier (private) qualifier-private)
;(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)
(%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)
(%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)
(production :primary-expression ($regular-expression) primary-expression-regular-expression)
(production :primary-expression (:unit-expression) primary-expression-unit-expression)
(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)
2001-03-01 08:31:28 +03:00
(%print-actions)
(production :parenthesized-expression (\( (:assignment-expression allow-in) \)) parenthesized-expression-assignment-expression)
2001-04-12 08:31:46 +04:00
(rule :parenthesized-list-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production :parenthesized-list-expression (:parenthesized-expression) parenthesized-list-expression-parenthesized-expression
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production :parenthesized-list-expression (\( (:list-expression allow-in) \, (:assignment-expression allow-in) \)) parenthesized-list-expression-list-expression
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%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)
(production :field-name (:identifier) field-name-identifier)
(production :field-name ($string) field-name-string)
(production :field-name ($number) field-name-number)
(production :field-name (:parenthesized-expression) field-name-parenthesized-expression)
(%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 "Super Operator")
2001-04-12 08:31:46 +04:00
(rule :super-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-01 08:31:28 +03:00
(production :super-expression (super) super-expression-super
2001-04-12 08:31:46 +04:00
((verify s)
(rwhen (not (allows-super s))
(throw syntax-error)))
((eval (e :unused)) (todo))
((super e) (return (lexical-class e))))
2001-03-01 08:31:28 +03:00
(production :super-expression (:full-super-expression) super-expression-full-super-expression
2001-04-12 08:31:46 +04:00
((verify s)
(rwhen (not (allows-super s))
(throw syntax-error))
(todo))
((eval (e :unused)) (todo))
((super e) (return (lexical-class e)))))
(production :full-super-expression (super :parenthesized-expression) full-super-expression-super-parenthesized-expression)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Postfix Operators")
2001-04-12 08:31:46 +04:00
(rule :postfix-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production :postfix-expression (:attribute-expression) postfix-expression-attribute-expression
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production :postfix-expression (:full-postfix-expression) postfix-expression-full-postfix-expression
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production :postfix-expression (:short-new-expression) postfix-expression-short-new-expression
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo))))
2001-03-01 08:31:28 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule :postfix-expression-or-super ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-01 08:31:28 +03:00
(production :postfix-expression-or-super (:postfix-expression) postfix-expression-or-super-postfix-expression
(verify (verify :postfix-expression))
(eval (eval :postfix-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-01 08:31:28 +03:00
(production :postfix-expression-or-super (:super-expression) postfix-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(production :attribute-expression (:simple-qualified-identifier) attribute-expression-simple-qualified-identifier)
(production :attribute-expression (:attribute-expression :member-operator) attribute-expression-member-operator)
(production :attribute-expression (:attribute-expression :arguments) attribute-expression-call)
(production :full-postfix-expression (:primary-expression) full-postfix-expression-primary-expression)
(production :full-postfix-expression (:expression-qualified-identifier) full-postfix-expression-expression-qualified-identifier)
(production :full-postfix-expression (:full-new-expression) full-postfix-expression-full-new-expression)
(production :full-postfix-expression (:full-postfix-expression :member-operator) full-postfix-expression-member-operator)
2001-01-26 10:33:32 +03:00
(production :full-postfix-expression (:super-expression :dot-operator) full-postfix-expression-super-dot-operator)
(production :full-postfix-expression (:full-postfix-expression :arguments) full-postfix-expression-call)
(production :full-postfix-expression (:full-super-expression :arguments) full-postfix-expression-super-call)
(production :full-postfix-expression (:postfix-expression-or-super :no-line-break ++) full-postfix-expression-increment)
(production :full-postfix-expression (:postfix-expression-or-super :no-line-break --) full-postfix-expression-decrement)
(production :full-new-expression (new :full-new-subexpression :arguments) full-new-expression-new)
(production :full-new-expression (new :full-super-expression :arguments) full-new-expression-super-new)
(production :full-new-subexpression (:primary-expression) full-new-subexpression-primary-expression)
(production :full-new-subexpression (:qualified-identifier) full-new-subexpression-qualified-identifier)
(production :full-new-subexpression (:full-new-expression) full-new-subexpression-full-new-expression)
(production :full-new-subexpression (:full-new-subexpression :member-operator) full-new-subexpression-member-operator)
2001-01-26 10:33:32 +03:00
(production :full-new-subexpression (:super-expression :dot-operator) full-new-subexpression-super-dot-operator)
(production :short-new-expression (new :short-new-subexpression) short-new-expression-new)
(production :short-new-expression (new :super-expression) short-new-expression-super-new)
(production :short-new-subexpression (:full-new-subexpression) short-new-subexpression-new-full)
(production :short-new-subexpression (:short-new-expression) short-new-subexpression-new-short)
2000-09-23 12:15:06 +04:00
2001-01-26 10:33:32 +03:00
(production :member-operator (:dot-operator) member-operator-dot-operator)
(production :member-operator (\. class) member-operator-class)
(production :member-operator (\. :parenthesized-expression) member-operator-indirect)
2001-01-26 10:33:32 +03:00
(production :dot-operator (\. :qualified-identifier) dot-operator-qualified-identifier)
(production :dot-operator (:brackets) dot-operator-brackets)
(production :brackets ([ ]) brackets-none)
(production :brackets ([ (:list-expression allow-in) ]) brackets-unnamed)
(production :brackets ([ :named-argument-list ]) brackets-named)
(production :arguments (\( \)) arguments-none)
(production :arguments (:parenthesized-list-expression) arguments-unnamed)
(production :arguments (\( :named-argument-list \)) arguments-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 "Unary Operators")
(production :unary-expression (:postfix-expression) unary-expression-postfix)
(production :unary-expression (const :postfix-expression-or-super) unary-expression-const)
(production :unary-expression (delete :postfix-expression-or-super) unary-expression-delete)
2000-09-24 10:08:53 +04:00
(production :unary-expression (void :unary-expression) unary-expression-void)
(production :unary-expression (typeof :unary-expression) unary-expression-typeof)
(production :unary-expression (++ :postfix-expression-or-super) unary-expression-increment)
(production :unary-expression (-- :postfix-expression-or-super) unary-expression-decrement)
(production :unary-expression (+ :unary-expression-or-super) unary-expression-plus)
(production :unary-expression (- :unary-expression-or-super) unary-expression-minus)
(production :unary-expression (~ :unary-expression-or-super) unary-expression-bitwise-not)
(production :unary-expression (! :unary-expression) unary-expression-logical-not)
(production :unary-expression-or-super (:unary-expression) unary-expression-or-super-unary-expression)
(production :unary-expression-or-super (:super-expression) unary-expression-or-super-super)
(%subsection "Multiplicative Operators")
2001-04-12 08:31:46 +04:00
(rule :multiplicative-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression (:unary-expression) multiplicative-expression-unary
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression (:multiplicative-expression-or-super * :unary-expression-or-super) multiplicative-expression-multiply
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression (:multiplicative-expression-or-super / :unary-expression-or-super) multiplicative-expression-divide
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression (:multiplicative-expression-or-super % :unary-expression-or-super) multiplicative-expression-remainder
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused)) (todo))))
2001-03-03 02:15:54 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule :multiplicative-expression-or-super ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression-or-super (:multiplicative-expression) multiplicative-expression-or-super-multiplicative-expression
(verify (verify :multiplicative-expression))
(eval (eval :multiplicative-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-03 02:15:54 +03:00
(production :multiplicative-expression-or-super (:super-expression) multiplicative-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Additive Operators")
2001-04-12 08:31:46 +04:00
(rule :additive-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-03 02:15:54 +03:00
(production :additive-expression (:multiplicative-expression) additive-expression-multiplicative
(verify (verify :multiplicative-expression))
(eval (eval :multiplicative-expression)))
(production :additive-expression (:additive-expression-or-super + :multiplicative-expression-or-super) additive-expression-add
2001-04-12 08:31:46 +04:00
((verify s)
((verify :additive-expression-or-super) s)
((verify :multiplicative-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :additive-expression-or-super) e)))
(const b object (read-reference ((eval :multiplicative-expression-or-super) e)))
(const sa class-opt ((super :additive-expression-or-super) e))
(const sb class-opt ((super :multiplicative-expression-or-super) e))
(return ((bin-op-eval bin-op-add sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production :additive-expression (:additive-expression-or-super - :multiplicative-expression-or-super) additive-expression-subtract
2001-04-12 08:31:46 +04:00
((verify s)
((verify :additive-expression-or-super) s)
((verify :multiplicative-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :additive-expression-or-super) e)))
(const b object (read-reference ((eval :multiplicative-expression-or-super) e)))
(const sa class-opt ((super :additive-expression-or-super) e))
(const sb class-opt ((super :multiplicative-expression-or-super) e))
(return ((bin-op-eval bin-op-subtract sa sb) a b)))))
2001-03-03 02:15:54 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule :additive-expression-or-super ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-03 02:15:54 +03:00
(production :additive-expression-or-super (:additive-expression) additive-expression-or-super-additive-expression
(verify (verify :additive-expression))
(eval (eval :additive-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-03 02:15:54 +03:00
(production :additive-expression-or-super (:super-expression) additive-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Bitwise Shift Operators")
2001-04-12 08:31:46 +04:00
(rule :shift-expression ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-03 02:15:54 +03:00
(production :shift-expression (:additive-expression) shift-expression-additive
(verify (verify :additive-expression))
(eval (eval :additive-expression)))
(production :shift-expression (:shift-expression-or-super << :additive-expression-or-super) shift-expression-left
2001-04-12 08:31:46 +04:00
((verify s)
((verify :shift-expression-or-super) s)
((verify :additive-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :shift-expression-or-super) e)))
(const b object (read-reference ((eval :additive-expression-or-super) e)))
(const sa class-opt ((super :shift-expression-or-super) e))
(const sb class-opt ((super :additive-expression-or-super) e))
(return ((bin-op-eval bin-op-shift-left sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production :shift-expression (:shift-expression-or-super >> :additive-expression-or-super) shift-expression-right-signed
2001-04-12 08:31:46 +04:00
((verify s)
((verify :shift-expression-or-super) s)
((verify :additive-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :shift-expression-or-super) e)))
(const b object (read-reference ((eval :additive-expression-or-super) e)))
(const sa class-opt ((super :shift-expression-or-super) e))
(const sb class-opt ((super :additive-expression-or-super) e))
(return ((bin-op-eval bin-op-shift-right sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production :shift-expression (:shift-expression-or-super >>> :additive-expression-or-super) shift-expression-right-unsigned
2001-04-12 08:31:46 +04:00
((verify s)
((verify :shift-expression-or-super) s)
((verify :additive-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :shift-expression-or-super) e)))
(const b object (read-reference ((eval :additive-expression-or-super) e)))
(const sa class-opt ((super :shift-expression-or-super) e))
(const sb class-opt ((super :additive-expression-or-super) e))
(return ((bin-op-eval bin-op-shift-right-unsigned sa sb) a b)))))
2001-03-03 02:15:54 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule :shift-expression-or-super ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-03 02:15:54 +03:00
(production :shift-expression-or-super (:shift-expression) shift-expression-or-super-shift-expression
(verify (verify :shift-expression))
(eval (eval :shift-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-03 02:15:54 +03:00
(production :shift-expression-or-super (:super-expression) shift-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Relational Operators")
2001-04-12 08:31:46 +04:00
(rule (:relational-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-03 02:15:54 +03:00
(production (:relational-expression :beta) (:shift-expression) relational-expression-shift
(verify (verify :shift-expression))
(eval (eval :shift-expression)))
(production (:relational-expression :beta) ((:relational-expression-or-super :beta) < :shift-expression-or-super) relational-expression-less
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression-or-super) s)
((verify :shift-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :relational-expression-or-super) e)))
(const b object (read-reference ((eval :shift-expression-or-super) e)))
(const sa class-opt ((super :relational-expression-or-super) e))
(const sb class-opt ((super :shift-expression-or-super) e))
(return ((bin-op-eval bin-op-less sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production (:relational-expression :beta) ((:relational-expression-or-super :beta) > :shift-expression-or-super) relational-expression-greater
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression-or-super) s)
((verify :shift-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :relational-expression-or-super) e)))
(const b object (read-reference ((eval :shift-expression-or-super) e)))
(const sa class-opt ((super :relational-expression-or-super) e))
(const sb class-opt ((super :shift-expression-or-super) e))
(return ((bin-op-eval bin-op-less sb sa) b a))))
2001-03-03 02:15:54 +03:00
(production (:relational-expression :beta) ((:relational-expression-or-super :beta) <= :shift-expression-or-super) relational-expression-less-or-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression-or-super) s)
((verify :shift-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :relational-expression-or-super) e)))
(const b object (read-reference ((eval :shift-expression-or-super) e)))
(const sa class-opt ((super :relational-expression-or-super) e))
(const sb class-opt ((super :shift-expression-or-super) e))
(return ((bin-op-eval bin-op-less-or-equal sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production (:relational-expression :beta) ((:relational-expression-or-super :beta) >= :shift-expression-or-super) relational-expression-greater-or-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression-or-super) s)
((verify :shift-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :relational-expression-or-super) e)))
(const b object (read-reference ((eval :shift-expression-or-super) e)))
(const sa class-opt ((super :relational-expression-or-super) e))
(const sb class-opt ((super :shift-expression-or-super) e))
(return ((bin-op-eval bin-op-less-or-equal sb sa) b a))))
2001-03-03 02:15:54 +03:00
(production (:relational-expression :beta) ((:relational-expression :beta) instanceof :shift-expression) relational-expression-instanceof
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression) s)
((verify :shift-expression) s))
((eval (e :unused)) (todo)))
(production (:relational-expression :beta) ((:relational-expression :beta) as :shift-expression) relational-expression-as
((verify s)
((verify :relational-expression) s)
((verify :shift-expression) s))
((eval (e :unused)) (todo)))
2001-03-03 02:15:54 +03:00
(production (:relational-expression allow-in) ((:relational-expression allow-in) in :shift-expression-or-super) relational-expression-in
2001-04-12 08:31:46 +04:00
((verify s)
((verify :relational-expression) s)
((verify :shift-expression-or-super) s))
((eval (e :unused)) (todo))))
2001-03-03 02:15:54 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule (:relational-expression-or-super :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-03 02:15:54 +03:00
(production (:relational-expression-or-super :beta) ((:relational-expression :beta)) relational-expression-or-super-relational-expression
(verify (verify :relational-expression))
(eval (eval :relational-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-03 02:15:54 +03:00
(production (:relational-expression-or-super :beta) (:super-expression) relational-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Equality Operators")
2001-04-12 08:31:46 +04:00
(rule (:equality-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-03 02:15:54 +03:00
(production (:equality-expression :beta) ((:relational-expression :beta)) equality-expression-relational
(verify (verify :relational-expression))
(eval (eval :relational-expression)))
(production (:equality-expression :beta) ((:equality-expression-or-super :beta) == (:relational-expression-or-super :beta)) equality-expression-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :equality-expression-or-super) s)
((verify :relational-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :equality-expression-or-super) e)))
(const b object (read-reference ((eval :relational-expression-or-super) e)))
(const sa class-opt ((super :equality-expression-or-super) e))
(const sb class-opt ((super :relational-expression-or-super) e))
(return ((bin-op-eval bin-op-equal sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production (:equality-expression :beta) ((:equality-expression-or-super :beta) != (:relational-expression-or-super :beta)) equality-expression-not-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :equality-expression-or-super) s)
((verify :relational-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :equality-expression-or-super) e)))
(const b object (read-reference ((eval :relational-expression-or-super) e)))
(const sa class-opt ((super :equality-expression-or-super) e))
(const sb class-opt ((super :relational-expression-or-super) e))
(return (unary-not ((bin-op-eval bin-op-equal sa sb) a b)))))
2001-03-03 02:15:54 +03:00
(production (:equality-expression :beta) ((:equality-expression-or-super :beta) === (:relational-expression-or-super :beta)) equality-expression-strict-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :equality-expression-or-super) s)
((verify :relational-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :equality-expression-or-super) e)))
(const b object (read-reference ((eval :relational-expression-or-super) e)))
(const sa class-opt ((super :equality-expression-or-super) e))
(const sb class-opt ((super :relational-expression-or-super) e))
(return ((bin-op-eval bin-op-strict-equal sa sb) a b))))
2001-03-03 02:15:54 +03:00
(production (:equality-expression :beta) ((:equality-expression-or-super :beta) !== (:relational-expression-or-super :beta)) equality-expression-strict-not-equal
2001-04-12 08:31:46 +04:00
((verify s)
((verify :equality-expression-or-super) s)
((verify :relational-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :equality-expression-or-super) e)))
(const b object (read-reference ((eval :relational-expression-or-super) e)))
(const sa class-opt ((super :equality-expression-or-super) e))
(const sb class-opt ((super :relational-expression-or-super) e))
(return (unary-not ((bin-op-eval bin-op-strict-equal sa sb) a b))))))
2001-03-03 02:15:54 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule (:equality-expression-or-super :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-03 02:15:54 +03:00
(production (:equality-expression-or-super :beta) ((:equality-expression :beta)) equality-expression-or-super-equality-expression
(verify (verify :equality-expression))
(eval (eval :equality-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-03 02:15:54 +03:00
(production (:equality-expression-or-super :beta) (:super-expression) equality-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Binary Bitwise Operators")
2001-04-12 08:31:46 +04:00
(rule (:bitwise-and-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-and-expression :beta) ((:equality-expression :beta)) bitwise-and-expression-equality
2001-03-03 02:15:54 +03:00
(verify (verify :equality-expression))
(eval (eval :equality-expression)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-and-expression :beta) ((:bitwise-and-expression-or-super :beta) & (:equality-expression-or-super :beta)) bitwise-and-expression-and
2001-04-12 08:31:46 +04:00
((verify s)
((verify :bitwise-and-expression-or-super) s)
((verify :equality-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :bitwise-and-expression-or-super) e)))
(const b object (read-reference ((eval :equality-expression-or-super) e)))
(const sa class-opt ((super :bitwise-and-expression-or-super) e))
(const sb class-opt ((super :equality-expression-or-super) e))
(return ((bin-op-eval bin-op-bitwise-and sa sb) a b)))))
(rule (:bitwise-xor-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-xor-expression :beta) ((:bitwise-and-expression :beta)) bitwise-xor-expression-bitwise-and
(verify (verify :bitwise-and-expression))
(eval (eval :bitwise-and-expression)))
(production (:bitwise-xor-expression :beta) ((:bitwise-xor-expression-or-super :beta) ^ (:bitwise-and-expression-or-super :beta)) bitwise-xor-expression-xor
2001-04-12 08:31:46 +04:00
((verify s)
((verify :bitwise-xor-expression-or-super) s)
((verify :bitwise-and-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :bitwise-xor-expression-or-super) e)))
(const b object (read-reference ((eval :bitwise-and-expression-or-super) e)))
(const sa class-opt ((super :bitwise-xor-expression-or-super) e))
(const sb class-opt ((super :bitwise-and-expression-or-super) e))
(return ((bin-op-eval bin-op-bitwise-xor sa sb) a b)))))
(rule (:bitwise-or-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-or-expression :beta) ((:bitwise-xor-expression :beta)) bitwise-or-expression-bitwise-xor
(verify (verify :bitwise-xor-expression))
(eval (eval :bitwise-xor-expression)))
(production (:bitwise-or-expression :beta) ((:bitwise-or-expression-or-super :beta) \| (:bitwise-xor-expression-or-super :beta)) bitwise-or-expression-or
2001-04-12 08:31:46 +04:00
((verify s)
((verify :bitwise-or-expression-or-super) s)
((verify :bitwise-xor-expression-or-super) s))
((eval e)
(const a object (read-reference ((eval :bitwise-or-expression-or-super) e)))
(const b object (read-reference ((eval :bitwise-xor-expression-or-super) e)))
(const sa class-opt ((super :bitwise-or-expression-or-super) e))
(const sb class-opt ((super :bitwise-xor-expression-or-super) e))
(return ((bin-op-eval bin-op-bitwise-or sa sb) a b)))))
2001-03-01 08:31:28 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule (:bitwise-and-expression-or-super :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-and-expression-or-super :beta) ((:bitwise-and-expression :beta)) bitwise-and-expression-or-super-bitwise-and-expression
(verify (verify :bitwise-and-expression))
(eval (eval :bitwise-and-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-and-expression-or-super :beta) (:super-expression) bitwise-and-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
2001-04-12 08:31:46 +04:00
(rule (:bitwise-xor-expression-or-super :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-xor-expression-or-super :beta) ((:bitwise-xor-expression :beta)) bitwise-xor-expression-or-super-bitwise-xor-expression
(verify (verify :bitwise-xor-expression))
(eval (eval :bitwise-xor-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-xor-expression-or-super :beta) (:super-expression) bitwise-xor-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
2001-04-12 08:31:46 +04:00
(rule (:bitwise-or-expression-or-super :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)) (super (-> (dynamic-env) class-opt)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-or-expression-or-super :beta) ((:bitwise-or-expression :beta)) bitwise-or-expression-or-super-bitwise-or-expression
(verify (verify :bitwise-or-expression))
(eval (eval :bitwise-or-expression))
2001-04-12 08:31:46 +04:00
((super (e :unused)) (return null)))
2001-03-01 08:31:28 +03:00
(production (:bitwise-or-expression-or-super :beta) (:super-expression) bitwise-or-expression-or-super-super
(verify (verify :super-expression))
(eval (eval :super-expression))
(super (super :super-expression))))
(%print-actions)
(%subsection "Binary Logical Operators")
2001-04-12 08:31:46 +04:00
(rule (:logical-and-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:logical-and-expression :beta) ((:bitwise-or-expression :beta)) logical-and-expression-bitwise-or
(verify (verify :bitwise-or-expression))
(eval (eval :bitwise-or-expression)))
(production (:logical-and-expression :beta) ((:logical-and-expression :beta) && (:bitwise-or-expression :beta)) logical-and-expression-and
2001-04-12 08:31:46 +04:00
((verify s)
((verify :logical-and-expression) s)
((verify :bitwise-or-expression) s))
((eval e)
(const a object (read-reference ((eval :logical-and-expression) e)))
(if (to-boolean a)
(return (read-reference ((eval :bitwise-or-expression) e)))
(return a)))))
2001-03-01 08:31:28 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule (:logical-xor-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:logical-xor-expression :beta) ((:logical-and-expression :beta)) logical-xor-expression-logical-and
(verify (verify :logical-and-expression))
(eval (eval :logical-and-expression)))
(production (:logical-xor-expression :beta) ((:logical-xor-expression :beta) ^^ (:logical-and-expression :beta)) logical-xor-expression-xor
2001-04-12 08:31:46 +04:00
((verify s)
((verify :logical-xor-expression) s)
((verify :logical-and-expression) s))
((eval e)
(const a object (read-reference ((eval :logical-xor-expression) e)))
(const b object (read-reference ((eval :logical-and-expression) e)))
(const ab boolean (to-boolean a))
(const bb boolean (to-boolean b))
(return (xor ab bb)))))
2001-03-01 08:31:28 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule (:logical-or-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:logical-or-expression :beta) ((:logical-xor-expression :beta)) logical-or-expression-logical-xor
(verify (verify :logical-xor-expression))
(eval (eval :logical-xor-expression)))
(production (:logical-or-expression :beta) ((:logical-or-expression :beta) \|\| (:logical-xor-expression :beta)) logical-or-expression-or
2001-04-12 08:31:46 +04:00
((verify s)
((verify :logical-or-expression) s)
((verify :logical-xor-expression) s))
((eval e)
(const a object (read-reference ((eval :logical-or-expression) e)))
(if (to-boolean a)
(return a)
(return (read-reference ((eval :logical-xor-expression) e)))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Conditional Operator")
2001-04-12 08:31:46 +04:00
(rule (:conditional-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:conditional-expression :beta) ((:logical-or-expression :beta)) conditional-expression-logical-or
(verify (verify :logical-or-expression))
(eval (eval :logical-or-expression)))
(production (:conditional-expression :beta) ((:logical-or-expression :beta) ? (:assignment-expression :beta) \: (:assignment-expression :beta)) conditional-expression-conditional
2001-04-12 08:31:46 +04:00
((verify s)
((verify :logical-or-expression) s)
((verify :assignment-expression 1) s)
((verify :assignment-expression 2) s))
((eval e)
(if (to-boolean (read-reference ((eval :logical-or-expression) e)))
(return ((eval :assignment-expression 1) e))
(return ((eval :assignment-expression 2) e))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(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)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Assignment Operators")
2001-04-12 08:31:46 +04:00
(rule (:assignment-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:assignment-expression :beta) ((:conditional-expression :beta)) assignment-expression-conditional
(verify (verify :conditional-expression))
(eval (eval :conditional-expression)))
(production (:assignment-expression :beta) (:postfix-expression = (:assignment-expression :beta)) assignment-expression-assignment
2001-04-12 08:31:46 +04:00
((verify s)
((verify :postfix-expression) s)
((verify :assignment-expression) s))
((eval e)
(const r reference ((eval :postfix-expression) e))
(const a object (read-reference ((eval :assignment-expression) e)))
(write-reference r a)
(return a)))
2001-03-01 08:31:28 +03:00
(production (:assignment-expression :beta) (:postfix-expression-or-super :compound-assignment (:assignment-expression :beta)) assignment-expression-compound
2001-04-12 08:31:46 +04:00
((verify s)
((verify :postfix-expression-or-super) s)
((verify :assignment-expression) s))
((eval e)
(return (eval-assignment-op (bin-op-eval (bin-op :compound-assignment) ((super :postfix-expression-or-super) e) null)
(eval :postfix-expression-or-super) (eval :assignment-expression) e))))
2001-03-01 08:31:28 +03:00
(production (:assignment-expression :beta) (:postfix-expression-or-super :compound-assignment :super-expression) assignment-expression-compound-super
2001-04-12 08:31:46 +04:00
((verify s)
((verify :postfix-expression-or-super) s)
((verify :super-expression) s))
((eval e)
(return (eval-assignment-op (bin-op-eval (bin-op :compound-assignment) ((super :postfix-expression-or-super) e) ((super :super-expression) e))
(eval :postfix-expression-or-super) (eval :super-expression) e))))
2001-03-01 08:31:28 +03:00
(production (:assignment-expression :beta) (:postfix-expression :logical-assignment (:assignment-expression :beta)) assignment-expression-logical-compound
2001-04-12 08:31:46 +04:00
((verify s)
((verify :postfix-expression) s)
((verify :assignment-expression) s))
((eval (e :unused)) (todo))))
(define (eval-assignment-op (op (-> (object object) object)) (left-eval (-> (dynamic-env) reference)) (right-eval (-> (dynamic-env) reference)) (e dynamic-env)) reference
(const r-left reference (left-eval e))
(const v-left object (read-reference r-left))
(const v-right object (read-reference (right-eval e)))
(const result object (op v-left v-right))
(write-reference r-left result)
(return result))
2001-03-01 08:31:28 +03:00
(%print-actions)
2001-04-12 08:31:46 +04:00
(rule :compound-assignment ((bin-op binary-operator))
(production :compound-assignment (*=) compound-assignment-multiply (bin-op bin-op-multiply))
(production :compound-assignment (/=) compound-assignment-divide (bin-op bin-op-divide))
(production :compound-assignment (%=) compound-assignment-remainder (bin-op bin-op-remainder))
(production :compound-assignment (+=) compound-assignment-add (bin-op bin-op-add))
(production :compound-assignment (-=) compound-assignment-subtract (bin-op bin-op-subtract))
(production :compound-assignment (<<=) compound-assignment-shift-left (bin-op bin-op-shift-left))
(production :compound-assignment (>>=) compound-assignment-shift-right (bin-op bin-op-shift-right))
(production :compound-assignment (>>>=) compound-assignment-shift-right-unsigned (bin-op bin-op-shift-right-unsigned))
(production :compound-assignment (&=) compound-assignment-bitwise-and (bin-op bin-op-bitwise-and))
(production :compound-assignment (^=) compound-assignment-bitwise-xor (bin-op bin-op-bitwise-xor))
(production :compound-assignment (\|=) compound-assignment-bitwise-or (bin-op bin-op-bitwise-or)))
2001-03-01 08:31:28 +03:00
(%print-actions)
(production :logical-assignment (&&=) logical-assignment-logical-and)
(production :logical-assignment (^^=) logical-assignment-logical-xor)
(production :logical-assignment (\|\|=) logical-assignment-logical-or)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Comma Expressions")
2001-04-12 08:31:46 +04:00
(rule (:list-expression :beta) ((verify (-> (static-env) void)) (eval (-> (dynamic-env) reference)))
2001-03-01 08:31:28 +03:00
(production (:list-expression :beta) ((:assignment-expression :beta)) list-expression-assignment
(verify (verify :assignment-expression))
(eval (eval :assignment-expression)))
(production (:list-expression :beta) ((:list-expression :beta) \, (:assignment-expression :beta)) list-expression-comma
2001-04-12 08:31:46 +04:00
((verify s)
((verify :list-expression) s)
((verify :assignment-expression) s))
((eval e)
(exec (read-reference ((eval :list-expression) e)))
(return ((eval :assignment-expression) e)))))
(production :optional-expression ((:list-expression allow-in)) optional-expression-expression)
(production :optional-expression () optional-expression-empty)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Type Expressions")
(production (:type-expression :beta) ((:non-assignment-expression :beta)) type-expression-non-assignment-expression)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%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)
2001-04-12 08:31:46 +04:00
(rule (:statement :omega) ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:empty-statement) statement-empty-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)))
((eval (e :unused) d) (return d)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:expression-statement (:semicolon :omega)) statement-expression-statement
(verify (verify :expression-statement))
2001-04-12 08:31:46 +04:00
((eval e (d :unused)) (return ((eval :expression-statement) e))))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:super-statement (:semicolon :omega)) statement-super-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:block-statement) statement-block-statement
(verify (verify :block-statement))
(eval (eval :block-statement)))
(production (:statement :omega) ((:labeled-statement :omega)) statement-labeled-statement
(verify (verify :labeled-statement))
(eval (eval :labeled-statement)))
(production (:statement :omega) ((:if-statement :omega)) statement-if-statement
(verify (verify :if-statement))
(eval (eval :if-statement)))
(production (:statement :omega) (:switch-statement) statement-switch-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:do-statement (:semicolon :omega)) statement-do-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) ((:while-statement :omega)) statement-while-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) ((:for-statement :omega)) statement-for-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) ((:with-statement :omega)) statement-with-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:continue-statement (:semicolon :omega)) statement-continue-statement
(verify (verify :continue-statement))
(eval (eval :continue-statement)))
(production (:statement :omega) (:break-statement (:semicolon :omega)) statement-break-statement
(verify (verify :break-statement))
(eval (eval :break-statement)))
(production (:statement :omega) (:return-statement (:semicolon :omega)) statement-return-statement
(verify (verify :return-statement))
2001-04-12 08:31:46 +04:00
((eval e (d :unused)) (return ((eval :return-statement) e))))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:throw-statement (:semicolon :omega)) statement-throw-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:statement :omega) (:try-statement) statement-try-statement
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(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")
2001-04-12 08:31:46 +04:00
(rule :expression-statement ((verify (-> (static-env) void)) (eval (-> (dynamic-env) object)))
2001-03-01 08:31:28 +03:00
(production :expression-statement ((:- function { const) (:list-expression allow-in)) expression-statement-list-expression
(verify (verify :list-expression))
2001-04-12 08:31:46 +04:00
((eval e) (return (read-reference ((eval :list-expression) e))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Super Statement")
(production :super-statement (super :arguments) super-statement-super-arguments)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Block Statement")
2001-04-12 08:31:46 +04:00
(rule :block-statement ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :block-statement (:block) block-statement-block
(verify (verify :block))
(eval (eval :block))))
2001-04-12 08:31:46 +04:00
(rule :block ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :block ({ :directives }) block-directives
(verify (verify :directives))
(eval (eval :directives))))
2001-04-12 08:31:46 +04:00
(rule :directives ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :directives () directives-none
2001-04-12 08:31:46 +04:00
((verify (s :unused)))
((eval (e :unused) d) (return d)))
2001-03-01 08:31:28 +03:00
(production :directives (:directives-prefix (:directive abbrev)) directives-more
2001-04-12 08:31:46 +04:00
((verify s)
((verify :directives-prefix) s)
((verify :directive) s))
((eval e d)
(const v object ((eval :directive) e d))
(return ((eval :directives-prefix) e v)))))
(rule :directives-prefix ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :directives-prefix () directives-prefix-none
2001-04-12 08:31:46 +04:00
((verify (s :unused)))
((eval (e :unused) d) (return d)))
2001-03-01 08:31:28 +03:00
(production :directives-prefix (:directives-prefix (:directive full)) directives-prefix-more
2001-04-12 08:31:46 +04:00
((verify s)
((verify :directives-prefix) s)
((verify :directive) s))
((eval e d)
(const v object ((eval :directive) e d))
(return ((eval :directives-prefix) e v)))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Labeled Statements")
2001-04-12 08:31:46 +04:00
(rule (:labeled-statement :omega) ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production (:labeled-statement :omega) (:identifier \: (:substatement :omega)) labeled-statement-label
2001-04-12 08:31:46 +04:00
((verify s) ((verify :substatement) (add-label s (name :identifier))))
((eval e d)
(catch ((return ((eval :substatement) e d)))
(x) (if (:narrow-true (in (tag go-break) x))
(if (= (& label x) (name :identifier) string)
(return (& value x))
2001-03-01 08:31:28 +03:00
(throw x))
(throw x))))))
(%print-actions)
(%subsection "If Statement")
2001-04-12 08:31:46 +04:00
(rule (:if-statement :omega) ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production (:if-statement abbrev) (if :parenthesized-list-expression (:substatement abbrev)) if-statement-if-then-abbrev
2001-04-12 08:31:46 +04:00
((verify s)
((verify :parenthesized-list-expression) s)
((verify :substatement) s))
((eval e d)
(if (to-boolean (read-reference ((eval :parenthesized-list-expression) e)))
(return ((eval :substatement) e d))
(return d))))
2001-03-01 08:31:28 +03:00
(production (:if-statement full) (if :parenthesized-list-expression (:substatement full)) if-statement-if-then-full
2001-04-12 08:31:46 +04:00
((verify s)
((verify :parenthesized-list-expression) s)
((verify :substatement) s))
((eval e d)
(if (to-boolean (read-reference ((eval :parenthesized-list-expression) e)))
(return ((eval :substatement) e d))
(return d))))
2001-03-01 08:31:28 +03:00
(production (:if-statement :omega) (if :parenthesized-list-expression (:substatement abbrev-no-short-if)
else (:substatement :omega)) if-statement-if-then-else
2001-04-12 08:31:46 +04:00
((verify s)
((verify :parenthesized-list-expression) s)
((verify :substatement 1) s)
((verify :substatement 2) s))
((eval e d)
(if (to-boolean (read-reference ((eval :parenthesized-list-expression) e)))
(return ((eval :substatement 1) e d))
(return ((eval :substatement 2) e d))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Switch Statement")
(production :switch-statement (switch :parenthesized-list-expression { :case-statements }) switch-statement-cases)
(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)
(production (:case-statement :omega_2) ((:substatement :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)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Do-While Statement")
(production :do-statement (do (:substatement abbrev) while :parenthesized-list-expression) do-statement-do-while)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "While Statement")
(production (:while-statement :omega) (while :parenthesized-list-expression (:substatement :omega)) while-statement-while)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "For Statements")
(production (:for-statement :omega) (for \( :for-initializer \; :optional-expression \; :optional-expression \)
(:substatement :omega)) for-statement-c-style)
(production (:for-statement :omega) (for \( :for-in-binding in (:list-expression allow-in) \) (:substatement :omega)) for-statement-in)
(production :for-initializer () for-initializer-empty)
(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)
(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)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "With Statement")
(production (:with-statement :omega) (with :parenthesized-list-expression (:substatement :omega)) with-statement-with)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Continue and Break Statements")
2001-04-12 08:31:46 +04:00
(rule :continue-statement ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :continue-statement (continue) continue-statement-unlabeled
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) d) (throw (tag go-continue d ""))))
2001-03-01 08:31:28 +03:00
(production :continue-statement (continue :no-line-break :identifier) continue-statement-labeled
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) d) (throw (tag go-continue d (name :identifier))))))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(rule :break-statement ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production :break-statement (break) break-statement-unlabeled
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) d) (throw (tag go-break d ""))))
2001-03-01 08:31:28 +03:00
(production :break-statement (break :no-line-break :identifier) break-statement-labeled
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) d) (throw (tag go-break d (name :identifier))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Return Statement")
2001-04-12 08:31:46 +04:00
(rule :return-statement ((verify (-> (static-env) void)) (eval (-> (dynamic-env) object)))
2001-03-01 08:31:28 +03:00
(production :return-statement (return) return-statement-default
2001-04-12 08:31:46 +04:00
((verify s)
(when (not (& can-return s))
(throw syntax-error)))
((eval (e :unused)) (throw (tag go-return undefined))))
2001-03-01 08:31:28 +03:00
(production :return-statement (return :no-line-break (:list-expression allow-in)) return-statement-expression
2001-04-12 08:31:46 +04:00
((verify s)
(when (not (& can-return s))
(throw syntax-error))
((verify :list-expression) s))
((eval e) (throw (tag go-return (read-reference ((eval :list-expression) e)))))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Throw Statement")
(production :throw-statement (throw :no-line-break (:list-expression allow-in)) throw-statement-throw)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Try Statement")
(production :try-statement (try :block-statement :catch-clauses) try-statement-catch-clauses)
(production :try-statement (try :block-statement :finally-clause) try-statement-finally-clause)
(production :try-statement (try :block-statement :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 \( :parameter \) :block) catch-clause-block)
(production :finally-clause (finally :block-statement) finally-clause-block-statement)
2001-03-01 08:31:28 +03:00
(%print-actions)
(%section "Directives")
2001-04-12 08:31:46 +04:00
(rule (:directive :omega_2) ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production (:directive :omega_2) ((:statement :omega_2)) directive-statement
(verify (verify :statement))
(eval (eval :statement)))
(production (:directive :omega_2) ((:annotated-definition :omega_2)) directive-annotated-definition
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:directive :omega_2) (:annotated-block) directive-annotated-block
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:directive :omega_2) (:use-directive (:semicolon :omega_2)) directive-use-directive
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(? js2
(production (:directive :omega_2) (:include-directive (:semicolon :omega_2)) directive-include-directive
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo))))
2001-03-01 08:31:28 +03:00
(production (:directive :omega_2) (:language-directive (:noninsertable-semicolon :omega_2)) directive-language-directive
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo))))
2001-03-01 08:31:28 +03:00
2001-04-12 08:31:46 +04:00
(rule (:substatement :omega) ((verify (-> (static-env) void)) (eval (-> (dynamic-env object) object)))
2001-03-01 08:31:28 +03:00
(production (:substatement :omega) ((:statement :omega)) substatement-statement
(verify (verify :statement))
(eval (eval :statement)))
(production (:substatement :omega) (:simple-variable-definition (:semicolon :omega)) substatement-simple-variable-definition
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo)))
2001-03-01 08:31:28 +03:00
(production (:substatement :omega) (:simple-annotated-block) substatement-simple-annotated-block
2001-04-12 08:31:46 +04:00
((verify (s :unused)) (todo))
((eval (e :unused) (d :unused)) (todo))))
2001-03-01 08:31:28 +03:00
(%print-actions)
(%subsection "Annotated Blocks")
(production :annotated-block (:nonempty-attributes :block) annotated-block-nonempty-attributes-and-block)
(production :nonempty-attributes (:attribute :no-line-break :attributes) nonempty-attributes-more)
(production :simple-annotated-block (:nonempty-attributes { :substatements }) simple-annotated-block-nonempty-attributes-and-simple-block)
(production :substatements () substatements-none)
(production :substatements (:substatements-prefix (:substatement abbrev)) substatements-more)
(production :substatements-prefix () substatements-prefix-none)
(production :substatements-prefix (:substatements-prefix (:substatement full)) substatements-prefix-more)
(%subsection "Use Directive")
(production :use-directive (use :no-line-break namespace :nonassignment-expression-list :use-includes-excludes) use-directive-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)
(production :use-includes-excludes () use-includes-excludes-none)
(production :use-includes-excludes (exclude :use-name-patterns) use-includes-excludes-exclude-list)
(production :use-includes-excludes (include :use-name-patterns) use-includes-excludes-include-list)
2001-01-10 05:50:13 +03:00
(production :use-name-patterns (*) use-name-patterns-wildcard)
(production :use-name-patterns (:use-name-pattern-list) use-name-patterns-use-name-pattern-list)
(production :use-name-pattern-list (:identifier) use-name-pattern-list-one)
(production :use-name-pattern-list (:use-name-pattern-list \, :identifier) use-name-pattern-list-more)
#|
(production :use-name-patterns (:use-name-pattern) use-name-patterns-one)
(production :use-name-patterns (:use-name-patterns \, :use-name-pattern) use-name-patterns-more)
(production :use-name-pattern (:qualified-wildcard-pattern) use-name-pattern-qualified-wildcard-pattern)
(production :use-name-pattern (:full-postfix-expression \. :qualified-wildcard-pattern) use-name-pattern-dot-qualified-wildcard-pattern)
(production :use-name-pattern (:attribute-expression \. :qualified-wildcard-pattern) use-name-pattern-dot-qualified-wildcard-pattern2)
(production :qualified-wildcard-pattern (:qualified-identifier) qualified-wildcard-pattern-qualified-identifier)
(production :qualified-wildcard-pattern (:wildcard-pattern) qualified-wildcard-pattern-wildcard-pattern)
(production :qualified-wildcard-pattern (:qualifier \:\: :wildcard-pattern) qualified-wildcard-pattern-qualifier)
(production :qualified-wildcard-pattern (:parenthesized-expression \:\: :wildcard-pattern) qualified-wildcard-pattern-expression-qualifier)
(production :wildcard-pattern (*) wildcard-pattern-all)
(production :wildcard-pattern ($regular-expression) wildcard-pattern-regular-expression)
2001-01-10 05:50:13 +03:00
|#
(? js2
(%subsection "Include Directive")
(production :include-directive (include :no-line-break $string) include-directive-include))
(%section "Language Directive")
(production :language-directive (use :language-alternatives) language-directive-language-alternatives)
2000-09-23 12:15:06 +04:00
(production :language-alternatives (:language-ids) language-alternatives-one)
(production :language-alternatives (:language-alternatives \| :language-ids) language-alternatives-more)
2000-09-23 12:15:06 +04:00
(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 "Definitions")
(production (:annotated-definition :omega_2) (:attributes (:definition :omega_2)) annotated-definition-attributes-and-definition)
(production (:annotated-definition :omega_2) (:package-definition) annotated-definition-package-definition)
(production (:definition :omega_2) (:import-definition (:semicolon :omega_2)) definition-import-definition)
(production (:definition :omega_2) (:export-definition (:semicolon :omega_2)) definition-export-definition)
(production (:definition :omega_2) (:variable-definition (:semicolon :omega_2)) definition-variable-definition)
(production (:definition :omega_2) ((:function-definition :omega_2)) definition-function-definition)
(production (:definition :omega_2) ((:class-definition :omega_2)) definition-class-definition)
(production (:definition :omega_2) (:namespace-definition (:semicolon :omega_2)) definition-namespace-definition)
(? js2
(production (:definition :omega_2) ((:interface-definition :omega_2)) definition-interface-definition))
(production :attributes () attributes-none)
(production :attributes (:attribute :no-line-break :attributes) attributes-more)
(production :attribute (:attribute-expression) attribute-attribute-expression)
(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)
(production :attribute (true) attribute-true)
(production :attribute (false) attribute-false)
2000-09-23 12:15:06 +04:00
(%subsection "Import Definition")
(production :import-definition (import :import-binding :import-uses :use-includes-excludes) import-definition-import)
(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)
(production :import-uses () import-uses-none)
(production :import-uses (\: :nonassignment-expression-list) import-uses-nonassignment-expression-list)
(%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) = (:variable-initializer :beta)) variable-binding-initialized)
(production (:variable-initializer :beta) ((:assignment-expression :beta)) variable-initializer-assignment-expression)
(production (:variable-initializer :beta) (:multiple-attributes) variable-initializer-multiple-attributes)
(production (:variable-initializer :beta) (abstract) variable-initializer-abstract)
(production (:variable-initializer :beta) (final) variable-initializer-final)
(production (:variable-initializer :beta) (private) variable-initializer-private)
(production (:variable-initializer :beta) (static) variable-initializer-static)
(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)
(production :simple-variable-definition (var :untyped-variable-binding-list) simple-variable-definition-definition)
(production :untyped-variable-binding-list (:untyped-variable-binding) untyped-variable-binding-list-one)
(production :untyped-variable-binding-list (:untyped-variable-binding-list \, :untyped-variable-binding) untyped-variable-binding-list-more)
(production :untyped-variable-binding (:identifier) untyped-variable-binding-simple)
(production :untyped-variable-binding (:identifier = (:variable-initializer allow-in)) untyped-variable-binding-initialized)
(%subsection "Function Definition")
(production (:function-definition :omega_2) (:function-declaration :block) function-definition-definition)
(production (:function-definition :omega_2) (:function-declaration (:semicolon :omega_2)) function-definition-declaration)
(production :function-declaration (function :function-name :function-signature) function-declaration-signature-and-body)
(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)
(production :function-name ($string) function-name-string)
(production :function-signature (:parameter-signature :result-signature) function-signature-parameter-and-result-signatures)
(production :parameter-signature (\( :parameters \)) parameter-signature-parameters)
(production :parameters () parameters-none)
(production :parameters (:all-parameters) parameters-all-parameters)
(production :all-parameters (:parameter) all-parameters-parameter)
(production :all-parameters (:parameter \, :all-parameters) all-parameters-parameter-and-more)
2001-04-12 08:31:46 +04:00
(production :all-parameters (:optional-parameters) all-parameters-optional-parameters)
2001-04-12 08:31:46 +04:00
(production :optional-parameters (:optional-parameter) optional-parameters-optional-parameter)
(production :optional-parameters (:optional-parameter \, :optional-parameters) optional-parameters-optional-parameter-and-more)
(production :optional-parameters (:rest-parameter) optional-parameters-rest-parameter)
(production :rest-parameter (\.\.\.) rest-parameter-none)
(production :rest-parameter (\.\.\. :parameter) rest-parameter-parameter)
(production :parameter (:parameter-attributes :identifier) parameter-identifier)
(production :parameter (:parameter-attributes :identifier \: (:type-expression allow-in)) parameter-identifier-and-type)
2001-04-12 08:31:46 +04:00
;(production :parameter (:parameter-attributes (:- const) (:type-expression allow-in) :identifier) parameter-type-and-identifier)
(production :parameter-attributes () parameter-attributes-none)
(production :parameter-attributes (const) parameter-attributes-const)
(production :optional-parameter (:parameter = (:assignment-expression allow-in)) optional-parameter-assignment-expression)
(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")
(production (:class-definition :omega_2) (class :identifier :inheritance :block) class-definition-definition)
(production (:class-definition :omega_2) (class :identifier (:semicolon :omega_2)) class-definition-declaration)
2000-09-23 12:15:06 +04:00
(production :inheritance () inheritance-none)
(production :inheritance (extends (:type-expression allow-in)) inheritance-extends)
(? 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)
(%subsection "Interface Definition")
(production (:interface-definition :omega_2) (interface :identifier :extends-list :block) interface-definition-definition)
(production (:interface-definition :omega_2) (interface :identifier (:semicolon :omega_2)) interface-definition-declaration)
(production :extends-list () extends-list-none)
(production :extends-list (extends :type-expression-list) extends-list-one)
(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))
(%subsection "Namespace Definition")
(production :namespace-definition (namespace :identifier) namespace-definition-normal)
(%section "Package Definition")
(production :package-definition (package :block) package-definition-anonymous)
(production :package-definition (package :package-name :block) package-definition-named)
(production :package-name (:identifier) package-name-one)
(production :package-name (:package-name \. :identifier) package-name-more)
(%section "Programs")
2001-04-12 08:31:46 +04:00
(rule :program ((eval-program object))
(production :program (:directives) program-directives
2001-04-12 08:31:46 +04:00
(eval-program
(begin
((verify :directives) initial-static-env)
(return ((eval :directives) initial-dynamic-env undefined))))))))
(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.
(defparameter *ew* nil)
(defparameter *eg* nil)
1999-05-11 00:52:58 +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
; 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.
;
; USE ONLY ON canonical-lr-1 grammars.
; DON'T RUN THIS AFTER CALLING forward-parser-states.
(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)
(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)))))
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
((production-first-terminal (production)
(first (production-rhs production)))
(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)
2001-04-12 08:31:46 +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
2001-04-12 08:31:46 +04:00
(depict-paragraph (markup-stream :body-text)
1999-05-11 00:52:58 +04:00
(depict markup-stream bin-name)
(depict-list markup-stream #'depict-terminal bin-terminals :separator '(" " :spc " "))))))
(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 '\# '&&= '-> '@ '^^ '^^= '\|\|=))
(setf (svref bins 4) (list 'abstract 'class 'const 'debugger 'enum 'export 'extends 'final 'goto 'implements 'import
'interface 'native 'package 'private 'protected 'public 'static 'super 'synchronized
'throws 'transient 'volatile))
; 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))))))
2001-04-12 08:31:46 +04:00
(depict-paragraph (markup-stream :section-heading)
2001-03-01 08:31:28 +03:00
(depict-link (markup-stream :definition "terminals" "" nil)
(depict markup-stream "Terminals")))
1999-05-11 00:52:58 +04:00
(mapc #'depict-terminal-bin '("General tokens: " "Punctuation tokens: " "Future punctuation tokens: "
"Reserved words: " "Future reserved words: " "Non-reserved words: ")
(coerce bins 'list)))))
#|
(values
(length (grammar-states *jg*))
(depict-rtf-to-local-file
2000-09-12 03:49:53 +04:00
"JS20/ParserGrammarJS2.rtf"
"JavaScript 2.0 Syntactic Grammar"
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *jg*)
(depict-world-commands markup-stream *jw* :visible-semantics nil)))
(depict-rtf-to-local-file
"JS20/ParserSemanticsJS2.rtf"
"JavaScript 2.0 Syntactic Semantics"
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *jg*)
(depict-world-commands markup-stream *jw*)))
(compute-ecma-subset)
(depict-rtf-to-local-file
2000-09-12 03:49:53 +04:00
"JS20/ParserGrammarES4.rtf"
"ECMAScript Edition 4 Syntactic Grammar"
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *eg*)
(depict-world-commands markup-stream *ew* :visible-semantics nil)))
(depict-rtf-to-local-file
"JS20/ParserSemanticsES4.rtf"
"ECMAScript Edition 4 Syntactic Semantics"
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *eg*)
(depict-world-commands markup-stream *ew*)))
(length (grammar-states *jg*))
(depict-html-to-local-file
2000-09-12 03:49:53 +04:00
"JS20/ParserGrammarJS2.html"
"JavaScript 2.0 Syntactic Grammar"
t
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *jg*)
(depict-world-commands markup-stream *jw* :visible-semantics nil))
:external-link-base "notation.html")
(depict-html-to-local-file
"JS20/ParserSemanticsJS2.html"
"JavaScript 2.0 Syntactic Semantics"
t
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *jg*)
(depict-world-commands markup-stream *jw*))
:external-link-base "notation.html")
(compute-ecma-subset)
(depict-html-to-local-file
2000-09-12 03:49:53 +04:00
"JS20/ParserGrammarES4.html"
"ECMAScript Edition 4 Syntactic Grammar"
t
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *eg*)
(depict-world-commands markup-stream *ew* :visible-semantics nil))
:external-link-base "notation.html")
(depict-html-to-local-file
"JS20/ParserSemanticsES4.html"
"ECMAScript Edition 4 Syntactic Semantics"
t
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *eg*)
(depict-world-commands markup-stream *ew*))
:external-link-base "notation.html"))
(depict-html-to-local-file
"JS20/ParserSemanticsJS2.html"
"JavaScript 2.0 Syntactic Semantics"
t
#'(lambda (markup-stream)
(depict-js-terminals markup-stream *jg*)
(depict-world-commands markup-stream *jw*))
:external-link-base "notation.html")
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))
(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*))