Skip to content

Instantly share code, notes, and snippets.

@osoleve
Created January 26, 2013 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osoleve/4644547 to your computer and use it in GitHub Desktop.
Save osoleve/4644547 to your computer and use it in GitHub Desktop.
Via Google Translate
(define (%shunting-yard stmt stack)
"Converts infix-notation mathematical equations into
postfix-notation mathematical equations, using an
implementation of Dijkstra's Shunting-yard Algorithm."
(cond ((null? stmt)
(stack-operations stack))
((number? (car stmt))
(cons (car stmt) (%shunting-yard (cdr stmt) stack)))
((operator? (car stmt))
(operator-actions stmt stack))
((eq? (car stmt) #\()
(%shunting-yard (cdr stmt) (cons (car stmt) stack)))
((eq? (car stmt) #\))
(if (eq? #\( (car stack))
(%shunting-yard (cdr stmt) (cdr stack))
(cons (car stack) (%shunting-yard stmt (cdr stack)))))))
To Arabic:
(تعريف (٪ تحويلة فناء كومة stmt)
   "تحويل أقحم-تدوين المعادلات الرياضية إلى
POSTFIX-تدوين المعادلات الرياضية، وذلك باستخدام
تنفيذ خوارزمية تحويلة فناء ديكسترا ".
   (كوند ((فارغة؟ stmt)
          (كومة كومة عمليات))
         ((عدد؟ (سيارة stmt))
          (سلبيات (سيارة stmt) (٪ تحويلة ياردة (مجلس الإنماء والإعمار stmt) كومة)))
         ((المشغل؟ (سيارة stmt))
          (مشغل الإجراءات كومة stmt))
         ((EQ؟ (سيارة stmt) # \ ()
          (٪ تحويلة ياردة (مجلس الإنماء والإعمار stmt) (سلبيات (سيارة stmt) كومة)))
         ((EQ؟ (سيارة stmt) # \))
          (إذا كان (EQ؟ # \ ((كومة سيارة))
              (٪ تحويلة ياردة (مجلس الإنماء والإعمار stmt) (مجلس الإنماء والإعمار المكدس))
              (سلبيات (كومة سيارة) (٪ تحويلة فناء stmt (مجلس الإنماء والإعمار المكدس)))))))
And back:
(Define (% Ext yard pile stmt)
"Inset converter - identify the mathematical equations to
POSTFIX-codification of mathematical equations, using
Implementation of Ex-yard Dijkstra algorithm. "
(Cond ((null? Stmt)
(Pile stack operations))
((? (Car stmt))
(Cons (car stmt) (% Ext yards (CDR stmt) stack)))
((Operator? (Car stmt))
(Operator actions pile stmt))
(% Ext yards (CDR stmt) (cons (car stmt) stack)))
(If (EQ? # \ ((Car pile))
(% Ext yards (CDR stmt) (CDR stack))
(Cons (car pile) (% Ext yard stmt (CDR stack)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment