IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scheme Discussion :

Créer un compilateur en scheme


Sujet :

Scheme

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 2
    Points : 7
    Points
    7
    Par défaut Créer un compilateur en scheme
    J'ai un projet de créer un compilateur en langage scheme, SVP,, est ce qu'il y a quelqu'un pour m'aider dans plusieurs choses..

  2. #2
    Membre actif
    Homme Profil pro
    Inscrit en
    Mai 2013
    Messages
    152
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Mai 2013
    Messages : 152
    Points : 275
    Points
    275
    Par défaut
    À vrai dire, je n’ai aucune idée comment on écrit des compilateurs, mais on pourrait, peut-être, discuter quelque chose de concret.

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2017
    Messages : 2
    Points : 7
    Points
    7
    Par défaut
    C'est le code que j'ai écrit; mais il y a un problème pour le booléen dans (= ,expr1 ,expr2),

    je doit écrire push $1 pour #f et push $9 pour #t mais je ne sais pas comment!

    et aussi pour: (println #f) et (println #t)


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    ;;; File: codegen.scm
     	 
     	(include "match.scm")
     	 
     	;;;============================================================================
     	 
     	;; Program compiler.
     	 
     	(define (compile-program exprs)
     	(list " .text\n"
     	" .globl _main\n"
     	" .globl main\n"
     	"_main:\n"
     	"main:\n"
     	(map compile-expr exprs)
     	" mov $0, %rax\n"
     	" ret\n"))
     	 
     	(define jumping 0)
     	 
     	(define (compile-expr expr)
     	(if (and (pair? expr)
     	(equal? (car expr) 'println)
     	(pair? (cdr expr))
     	(null? (cddr expr)))
     	 
     	(let ((val (cadr expr)))
     	(list " push $" val "\n"
     	" call print_word_dec\n"
     	" push $10\n"
     	" call putchar\n"))
     	 
     	(error "unknown expression" expr)))
     	 
     	 
     	 
     	(define (compile-expr expr) ;; version avec macro "match"
     	(match expr
     	 
     	((println ,val)
     	 
     	(list " push $" val "\n"
     	" call print_word_dec\n"
     	" push $10\n"
     	" call putchar\n"))))
     	 
     	 
     	(define (compile-expr expr)
     	(match expr
     	 
     	((println ,expr1)
     	 
     	(append (compile-expr expr1)
     	(list " call print_word_dec\n"
     	" push $10\n"
     	" call putchar\n")))
     	 
     	(,val
     	 
     	(list " push $" val "\n"))))
     	 
     	 
     	(define (compile-expr expr)
     	(match expr
     	 
     	((println #f) ;when (boolean? expr1)
     	 
     	(append
     	(list " push $35\n"
     	" call putchar\n"
     	" push $102\n"
     	" call putchar\n"
     	" push $10\n"
     	" call putchar\n")))
     	 
     	((println #t) ;when (boolean? expr1)
     	 
     	(append
     	(list " push $35\n"
     	" call putchar\n"
     	" push $116\n"
     	" call putchar\n"
     	" push $10\n"
     	" call putchar\n")))
     	 
     	((println ,expr1)
     	 
     	(append (compile-expr expr1)
     	(list " call print_word_dec\n"
     	" push $10\n"
     	" call putchar\n")))
     	 
     	((+ ,expr1 ,expr2)
     	 
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rax\n"
     	" add %rax,(%rsp)\n")))
     	 
     	((- ,expr1 ,expr2)
     	 
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rax\n"
     	" sub %rax,(%rsp)\n")))
     	((* ,expr1 ,expr2)
     	 
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" imul (%rsp), %rbx\n"
     	" mov %rbx,(%rsp)\n")))
     	 
     	((quotient ,expr1 ,expr2)
     	 
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" mov (%rsp), %rax\n"
     	" cqto\n"
     	" idiv %rbx\n"
     	" mov %rax,(%rsp)\n")))
     	 
     	((modulo ,expr1 ,expr2)
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" mov %rbx, %rcx\n"
     	" mov (%rsp), %rax\n "
     	" cqto\n"
     	" idiv %rbx\n"
     	" mov %rdx, (%rsp)\n"
     	" test %rax, %rax\n"
     	(string-append " js negatif" (number->string (begin
     	(set! jumping (+ 1 jumping)) jumping)) "\n")
     	(string-append " positif" (number->string jumping) ":\n")
     	(string-append " jmp end" (number->string jumping) "\n")
     	(string-append " negatif" (number->string jumping) ":\n")
     	" test %rdx, %rdx\n"
     	(string-append " jz nul" (number->string jumping) "\n")
     	" add %rcx,(%rsp)\n"
     	(string-append " jmp end" (number->string jumping) "\n")
     	(string-append " nul" (number->string jumping) ":\n")
     	(string-append " jmp end" (number->string jumping) "\n")
     	(string-append " end" (number->string jumping) ":\n"))))
     	 
     	 
     	 
     	((= ,expr1 ,expr2)
     	(let ((et1 (gensym)))
     	(let ((et2 (gensym)))
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" pop %rax\n"
     	" cmp %rbx,%rax\n"
     	" je " et1 "\n"
     	" push $35\n";#
     	" call putchar\n"
     	" push $102\n";#f
     	" call putchar\n"
     	" push $10\n"
     	; " call putchar\n"
     	" jmp " et2 "\n"
     	" " et1 ":\n"
     	" push $35\n";#
     	" call putchar\n"
     	" push $116\n";#t
     	" call putchar\n"
     	" push $10\n"
     	; " call putchar\n"
     	" " et2 ":\n")))))
     	 
     	((< ,expr1 ,expr2)
     	(let ((et1 (gensym)))
     	(let ((et2 (gensym)))
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" pop %rax\n"
     	" sub %rbx,%rax\n"
     	" jl " et1 "\n"
     	" push $35\n";#
     	" call putchar\n"
     	" push $102\n";#f
     	" call putchar\n"
     	" push $10\n"
     	; " call putchar\n"
     	" jmp " et2 "\n"
     	" " et1 ":\n"
     	" push $35\n";#
     	" call putchar\n"
     	" push $116\n";#t
     	" call putchar\n"
     	" push $10\n"
     	; " call putchar\n"
     	" " et2 ":\n")))))
     	 
     	((if ,condition ,expr1 ,expr2)
     	 
     	(if condition
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rax\n"))
     	(append (compile-expr expr1)
     	(compile-expr expr2)
     	(list " pop %rbx\n"
     	" movq %rbx,(%rsp)\n"))))
     	 
     	 
     	(,val
     	(list " push $" val "\n"))))
     	;;;===========================================================================

Discussions similaires

  1. [VB.net] Créer un compilateur
    Par HHpp67 dans le forum VB.NET
    Réponses: 4
    Dernier message: 19/02/2011, 15h29
  2. comment créer un compilateur pour le langage C ?
    Par mooan dans le forum Choisir un environnement de développement
    Réponses: 1
    Dernier message: 02/12/2010, 12h27
  3. [Visiteur] comment utiliser le design pattern de visiteur pour créer un compilateur
    Par katimm dans le forum Design Patterns
    Réponses: 12
    Dernier message: 18/09/2008, 10h22
  4. Comment créer un compilateur ?
    Par @v@lon dans le forum Langages de programmation
    Réponses: 53
    Dernier message: 13/04/2007, 16h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo