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 (top-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 block-context (return?))
|
||||
(define-struct (top-block-context block-context) ())
|
||||
(define-struct (expression-block-context block-context) ())
|
||||
|
||||
(define-struct expression-context ())
|
||||
(define-struct type-context ())
|
||||
(define-struct type-or-expression-context ())
|
||||
(define-struct prototype-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 the-block-context (make-block-context #f))
|
||||
(define the-top-block-context (make-top-block-context #f))
|
||||
(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-struct expression-context ())
|
||||
(define-struct type-context ())
|
||||
(define-struct type-or-expression-context ())
|
||||
(define-struct prototype-context ())
|
||||
|
||||
(define the-variable-definition-context (make-variable-definition-context))
|
||||
(define the-constant-definition-context (make-constant-definition-context))
|
||||
(define the-function-definition-context (make-function-definition-context))
|
||||
(define the-block-context (make-block-context #f))
|
||||
(define the-top-block-context (make-top-block-context #f))
|
||||
(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-type-context (make-type-context))
|
||||
(define the-type-or-expression-context (make-type-or-expression-context))
|
||||
(define the-prototype-context (make-prototype-context))
|
||||
(define the-variable-definition-context (make-variable-definition-context))
|
||||
(define the-constant-definition-context (make-constant-definition-context))
|
||||
(define the-function-definition-context (make-function-definition-context))
|
||||
|
||||
(define (context->name ctx)
|
||||
(cond
|
||||
[(type-context? ctx) "a type"]
|
||||
[(type-or-expression-context? ctx) "a type or expression"]
|
||||
[(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?
|
||||
(define the-expression-context (make-expression-context))
|
||||
(define the-type-context (make-type-context))
|
||||
(define the-type-or-expression-context (make-type-or-expression-context))
|
||||
(define the-prototype-context (make-prototype-context))
|
||||
|
||||
definition-context?
|
||||
function-definition-context?
|
||||
value-definition-context?
|
||||
variable-definition-context?
|
||||
constant-definition-context?
|
||||
(define (context->name ctx)
|
||||
(cond
|
||||
[(type-context? ctx) "a type"]
|
||||
[(type-or-expression-context? ctx) "a type or expression"]
|
||||
[(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?
|
||||
type-context?
|
||||
type-or-expression-context?
|
||||
prototype-context?
|
||||
(provide block-context?
|
||||
expression-block-context?
|
||||
top-block-context?
|
||||
|
||||
block-context-return?
|
||||
definition-context?
|
||||
function-definition-context?
|
||||
value-definition-context?
|
||||
variable-definition-context?
|
||||
constant-definition-context?
|
||||
|
||||
the-block-context
|
||||
the-top-block-context
|
||||
the-return-block-context
|
||||
the-expression-block-context
|
||||
the-expression-return-block-context
|
||||
expression-context?
|
||||
type-context?
|
||||
type-or-expression-context?
|
||||
prototype-context?
|
||||
|
||||
make-function-definition-context
|
||||
the-variable-definition-context
|
||||
the-constant-definition-context
|
||||
the-function-definition-context
|
||||
block-context-return?
|
||||
|
||||
the-expression-context
|
||||
the-type-context
|
||||
the-type-or-expression-context
|
||||
the-prototype-context
|
||||
the-block-context
|
||||
the-top-block-context
|
||||
the-return-block-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
|
||||
unary-postfix-ops
|
||||
(struct op (id))
|
||||
(struct prefix ())
|
||||
(struct cast-prefix (type))
|
||||
(struct infix ())
|
||||
(struct postfix ())
|
||||
prec-key
|
||||
precedence-table
|
||||
op-table)
|
||||
unary-postfix-ops
|
||||
(struct-out op)
|
||||
(struct-out prefix)
|
||||
(struct-out cast-prefix)
|
||||
(struct-out infix)
|
||||
(struct-out postfix)
|
||||
prec-key
|
||||
precedence-table
|
||||
op-table)
|
||||
|
||||
(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 unary-prefix-ops '(++
|
||||
--
|
||||
+
|
||||
-
|
||||
!
|
||||
~))
|
||||
|
||||
(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-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 unary-postfix-ops '(++
|
||||
--))
|
||||
|
||||
(define op-table (make-hash-table))
|
||||
(hash-table-for-each precedence-table (lambda (k v)
|
||||
(hash-table-put! op-table (cdr k) #t))))
|
||||
(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)
|
||||
(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