upgrade to #lang scheme
svn: r15345
This commit is contained in:
parent
3d356123cf
commit
b55944bb93
|
@ -1,79 +1,79 @@
|
||||||
(module contexts mzscheme
|
#lang scheme
|
||||||
|
|
||||||
(define-struct block-context (return?))
|
(define-struct block-context (return?))
|
||||||
(define-struct (top-block-context block-context) ())
|
(define-struct (top-block-context block-context) ())
|
||||||
(define-struct (expression-block-context block-context) ())
|
(define-struct (expression-block-context block-context) ())
|
||||||
|
|
||||||
(define-struct definition-context ())
|
|
||||||
(define-struct (function-definition-context definition-context) ())
|
|
||||||
(define-struct (value-definition-context definition-context) ())
|
|
||||||
(define-struct (constant-definition-context value-definition-context) ())
|
|
||||||
(define-struct (variable-definition-context value-definition-context) ())
|
|
||||||
|
|
||||||
(define-struct expression-context ())
|
(define-struct definition-context ())
|
||||||
(define-struct type-context ())
|
(define-struct (function-definition-context definition-context) ())
|
||||||
(define-struct type-or-expression-context ())
|
(define-struct (value-definition-context definition-context) ())
|
||||||
(define-struct prototype-context ())
|
(define-struct (constant-definition-context value-definition-context) ())
|
||||||
|
(define-struct (variable-definition-context value-definition-context) ())
|
||||||
|
|
||||||
(define the-block-context (make-block-context #f))
|
(define-struct expression-context ())
|
||||||
(define the-top-block-context (make-top-block-context #f))
|
(define-struct type-context ())
|
||||||
(define the-expression-block-context (make-expression-block-context #f))
|
(define-struct type-or-expression-context ())
|
||||||
(define the-return-block-context (make-block-context #t))
|
(define-struct prototype-context ())
|
||||||
(define the-expression-return-block-context (make-expression-block-context #t))
|
|
||||||
|
|
||||||
(define the-variable-definition-context (make-variable-definition-context))
|
(define the-block-context (make-block-context #f))
|
||||||
(define the-constant-definition-context (make-constant-definition-context))
|
(define the-top-block-context (make-top-block-context #f))
|
||||||
(define the-function-definition-context (make-function-definition-context))
|
(define the-expression-block-context (make-expression-block-context #f))
|
||||||
|
(define the-return-block-context (make-block-context #t))
|
||||||
|
(define the-expression-return-block-context (make-expression-block-context #t))
|
||||||
|
|
||||||
(define the-expression-context (make-expression-context))
|
(define the-variable-definition-context (make-variable-definition-context))
|
||||||
(define the-type-context (make-type-context))
|
(define the-constant-definition-context (make-constant-definition-context))
|
||||||
(define the-type-or-expression-context (make-type-or-expression-context))
|
(define the-function-definition-context (make-function-definition-context))
|
||||||
(define the-prototype-context (make-prototype-context))
|
|
||||||
|
|
||||||
(define (context->name ctx)
|
(define the-expression-context (make-expression-context))
|
||||||
(cond
|
(define the-type-context (make-type-context))
|
||||||
[(type-context? ctx) "a type"]
|
(define the-type-or-expression-context (make-type-or-expression-context))
|
||||||
[(type-or-expression-context? ctx) "a type or expression"]
|
(define the-prototype-context (make-prototype-context))
|
||||||
[(expression-context? ctx) "an expression"]
|
|
||||||
[(expression-block-context? ctx) "a statement"]
|
|
||||||
[(block-context? ctx) "a block"]
|
|
||||||
[(variable-definition-context? ctx) "a variable-definition"]
|
|
||||||
[(constant-definition-context? ctx) "a constant-definition"]
|
|
||||||
[(function-definition-context? ctx) "a function-definition"]
|
|
||||||
[(prototype-context? ctx) "a function-definition"]
|
|
||||||
[else "an expression"]))
|
|
||||||
|
|
||||||
(provide block-context?
|
|
||||||
expression-block-context?
|
|
||||||
top-block-context?
|
|
||||||
|
|
||||||
definition-context?
|
(define (context->name ctx)
|
||||||
function-definition-context?
|
(cond
|
||||||
value-definition-context?
|
[(type-context? ctx) "a type"]
|
||||||
variable-definition-context?
|
[(type-or-expression-context? ctx) "a type or expression"]
|
||||||
constant-definition-context?
|
[(expression-context? ctx) "an expression"]
|
||||||
|
[(expression-block-context? ctx) "a statement"]
|
||||||
|
[(block-context? ctx) "a block"]
|
||||||
|
[(variable-definition-context? ctx) "a variable-definition"]
|
||||||
|
[(constant-definition-context? ctx) "a constant-definition"]
|
||||||
|
[(function-definition-context? ctx) "a function-definition"]
|
||||||
|
[(prototype-context? ctx) "a function-definition"]
|
||||||
|
[else "an expression"]))
|
||||||
|
|
||||||
expression-context?
|
(provide block-context?
|
||||||
type-context?
|
expression-block-context?
|
||||||
type-or-expression-context?
|
top-block-context?
|
||||||
prototype-context?
|
|
||||||
|
|
||||||
block-context-return?
|
definition-context?
|
||||||
|
function-definition-context?
|
||||||
|
value-definition-context?
|
||||||
|
variable-definition-context?
|
||||||
|
constant-definition-context?
|
||||||
|
|
||||||
the-block-context
|
expression-context?
|
||||||
the-top-block-context
|
type-context?
|
||||||
the-return-block-context
|
type-or-expression-context?
|
||||||
the-expression-block-context
|
prototype-context?
|
||||||
the-expression-return-block-context
|
|
||||||
|
|
||||||
make-function-definition-context
|
block-context-return?
|
||||||
the-variable-definition-context
|
|
||||||
the-constant-definition-context
|
|
||||||
the-function-definition-context
|
|
||||||
|
|
||||||
the-expression-context
|
the-block-context
|
||||||
the-type-context
|
the-top-block-context
|
||||||
the-type-or-expression-context
|
the-return-block-context
|
||||||
the-prototype-context
|
the-expression-block-context
|
||||||
|
the-expression-return-block-context
|
||||||
|
|
||||||
context->name))
|
make-function-definition-context
|
||||||
|
the-variable-definition-context
|
||||||
|
the-constant-definition-context
|
||||||
|
the-function-definition-context
|
||||||
|
|
||||||
|
the-expression-context
|
||||||
|
the-type-context
|
||||||
|
the-type-or-expression-context
|
||||||
|
the-prototype-context
|
||||||
|
|
||||||
|
context->name)
|
||||||
|
|
|
@ -1,91 +1,91 @@
|
||||||
|
#lang scheme
|
||||||
|
|
||||||
(module ops mzscheme
|
|
||||||
(provide unary-prefix-ops
|
(provide unary-prefix-ops
|
||||||
unary-postfix-ops
|
unary-postfix-ops
|
||||||
(struct op (id))
|
(struct-out op)
|
||||||
(struct prefix ())
|
(struct-out prefix)
|
||||||
(struct cast-prefix (type))
|
(struct-out cast-prefix)
|
||||||
(struct infix ())
|
(struct-out infix)
|
||||||
(struct postfix ())
|
(struct-out postfix)
|
||||||
prec-key
|
prec-key
|
||||||
precedence-table
|
precedence-table
|
||||||
op-table)
|
op-table)
|
||||||
|
|
||||||
(define unary-prefix-ops '(++
|
(define unary-prefix-ops '(++
|
||||||
--
|
--
|
||||||
+
|
+
|
||||||
-
|
-
|
||||||
!
|
!
|
||||||
~))
|
~))
|
||||||
|
|
||||||
(define unary-postfix-ops '(++
|
|
||||||
--))
|
|
||||||
|
|
||||||
(define-struct op (id))
|
|
||||||
(define-struct (prefix op) ())
|
|
||||||
(define-struct (cast-prefix prefix) (type))
|
|
||||||
(define-struct (infix op) ())
|
|
||||||
(define-struct (postfix op) ())
|
|
||||||
|
|
||||||
(define (prec-key op)
|
(define unary-postfix-ops '(++
|
||||||
(and op
|
--))
|
||||||
(cons (cond
|
|
||||||
[(prefix? op) 'pre]
|
|
||||||
[(infix? op) 'in]
|
|
||||||
[(postfix? op) 'post])
|
|
||||||
(syntax-e (op-id op)))))
|
|
||||||
|
|
||||||
(define precedence-table (make-immutable-hash-table
|
|
||||||
'(((in . |.|) . 100)
|
|
||||||
((in . #%parens) . 100)
|
|
||||||
((in . #%brackets) . 100)
|
|
||||||
((in . #%angles) . 100)
|
|
||||||
((post . ++) . 100)
|
|
||||||
((post . --) . 100)
|
|
||||||
((pre . ++) . 95)
|
|
||||||
((pre . --) . 95)
|
|
||||||
((pre . +) . 95)
|
|
||||||
((pre . -) . 95)
|
|
||||||
((pre . ~) . 95)
|
|
||||||
((pre . !) . 95)
|
|
||||||
((pre . #%parens) . 95)
|
|
||||||
((in . *) . 90)
|
|
||||||
((in . %) . 90)
|
|
||||||
((in . /) . 90)
|
|
||||||
((in . +) . 85)
|
|
||||||
((in . -) . 85)
|
|
||||||
((in . >>) . 80)
|
|
||||||
((in . <<) . 80)
|
|
||||||
((in . >>>) . 80)
|
|
||||||
((in . <) . 70)
|
|
||||||
((in . >) . 70)
|
|
||||||
((in . <=) . 70)
|
|
||||||
((in . >=) . 70)
|
|
||||||
((in . ==) . 60)
|
|
||||||
((in . !=) . 60)
|
|
||||||
((in . &) . 55)
|
|
||||||
((in . ^) . 50)
|
|
||||||
((in . \|) . 45)
|
|
||||||
((in . &&) . 40)
|
|
||||||
((in . \|\|) . 35)
|
|
||||||
((in . =) . 10)
|
|
||||||
((in . +=) . 10)
|
|
||||||
((in . -=) . 10)
|
|
||||||
((in . *=) . 10)
|
|
||||||
((in . /=) . 10)
|
|
||||||
((in . %=) . 10)
|
|
||||||
((in . &=) . 10)
|
|
||||||
((in . ^=) . 10)
|
|
||||||
((in . \|=) . 10)
|
|
||||||
((in . <<=) . 10)
|
|
||||||
((in . >>=) . 10)
|
|
||||||
((in . >>>=) . 10)
|
|
||||||
((in . \,) . 6)
|
|
||||||
((in . :) . 5)
|
|
||||||
((in . ?) . 4))
|
|
||||||
'equal))
|
|
||||||
|
|
||||||
(define op-table (make-hash-table))
|
(define-struct op (id))
|
||||||
(hash-table-for-each precedence-table (lambda (k v)
|
(define-struct (prefix op) ())
|
||||||
(hash-table-put! op-table (cdr k) #t))))
|
(define-struct (cast-prefix prefix) (type))
|
||||||
|
(define-struct (infix op) ())
|
||||||
|
(define-struct (postfix op) ())
|
||||||
|
|
||||||
|
(define (prec-key op)
|
||||||
|
(and op
|
||||||
|
(cons (cond
|
||||||
|
[(prefix? op) 'pre]
|
||||||
|
[(infix? op) 'in]
|
||||||
|
[(postfix? op) 'post])
|
||||||
|
(syntax-e (op-id op)))))
|
||||||
|
|
||||||
|
(define precedence-table (make-immutable-hash
|
||||||
|
'(((in . |.|) . 100)
|
||||||
|
((in . #%parens) . 100)
|
||||||
|
((in . #%brackets) . 100)
|
||||||
|
((in . #%angles) . 100)
|
||||||
|
((post . ++) . 100)
|
||||||
|
((post . --) . 100)
|
||||||
|
((pre . ++) . 95)
|
||||||
|
((pre . --) . 95)
|
||||||
|
((pre . +) . 95)
|
||||||
|
((pre . -) . 95)
|
||||||
|
((pre . ~) . 95)
|
||||||
|
((pre . !) . 95)
|
||||||
|
((pre . #%parens) . 95)
|
||||||
|
((in . *) . 90)
|
||||||
|
((in . %) . 90)
|
||||||
|
((in . /) . 90)
|
||||||
|
((in . +) . 85)
|
||||||
|
((in . -) . 85)
|
||||||
|
((in . >>) . 80)
|
||||||
|
((in . <<) . 80)
|
||||||
|
((in . >>>) . 80)
|
||||||
|
((in . <) . 70)
|
||||||
|
((in . >) . 70)
|
||||||
|
((in . <=) . 70)
|
||||||
|
((in . >=) . 70)
|
||||||
|
((in . ==) . 60)
|
||||||
|
((in . !=) . 60)
|
||||||
|
((in . &) . 55)
|
||||||
|
((in . ^) . 50)
|
||||||
|
((in . \|) . 45)
|
||||||
|
((in . &&) . 40)
|
||||||
|
((in . \|\|) . 35)
|
||||||
|
((in . =) . 10)
|
||||||
|
((in . +=) . 10)
|
||||||
|
((in . -=) . 10)
|
||||||
|
((in . *=) . 10)
|
||||||
|
((in . /=) . 10)
|
||||||
|
((in . %=) . 10)
|
||||||
|
((in . &=) . 10)
|
||||||
|
((in . ^=) . 10)
|
||||||
|
((in . \|=) . 10)
|
||||||
|
((in . <<=) . 10)
|
||||||
|
((in . >>=) . 10)
|
||||||
|
((in . >>>=) . 10)
|
||||||
|
((in . \,) . 6)
|
||||||
|
((in . :) . 5)
|
||||||
|
((in . ?) . 4))))
|
||||||
|
|
||||||
|
|
||||||
|
(define op-table (make-hash))
|
||||||
|
(hash-for-each precedence-table (lambda (k v)
|
||||||
|
(hash-set! op-table (cdr k) #t)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user