という文法を定義しましたmsl
#lang plai-typed
(define-type msl
[msl-num (n : number)]
[msl-add (l : msl) (r : msl)]
[msl-mul (l : msl) (r : msl)]
[msl-sub (l : msl) (r : msl)]
[msl-pow (l : msl) (r : msl)]
[msl-error (s : string)]
)
(define(** u t)
(cond
((= u 1) t)
(else
(* t(**(sub1 u) t)))))
に変換するパーサー関数がありs-expression
ますmsl
(define (parse [s : s-expression]) : msl
(cond
[(s-exp-number? s) (msl-num (s-exp->number s))]
[(s-exp-list? s)
(let ([sl (s-exp->list s)])
(case (s-exp->symbol (first sl))
[(+) (msl-add (parse (second sl)) (parse (third sl)))]
[(*) (msl-mul (parse (second sl)) (parse (third sl)))]
[ (-) (msl-sub (parse (second sl)) (parse (third sl)))]
[ (**) (msl-pow (parse (second sl)) (parse (third sl))) ]
[else (error 'parse "invalid list input")]))]
[else (error 'parse "invalid input")]))
msl
私の質問は次のとおりです。式をこのように変換するにはどうすればよいs-expression
ですか? 私はこのテーマの初心者です