Yuce's Blog

Cognitive dissonance is yoga for the brain.*

Infix Comparison in Marvin

2005-04-16

Here is a sample Marvin code that converts an infix expression into postfix. I have also posted this one to the In­fix­Com­par­i­son page of Con­cate­na­tive Languages Wiki. Note from the future: Sadly, these links are broken.

# infix.mar | Converts an infix expression into postfix

# This implementation uses the global variable space as a hash-table
# for operator precedence.

"listop forth dequeop" use

@|> globs & pushfrom ;

@string dfront NONE =
    { iftrue dpushf }
    { else
        dpopf 2dup |>
        { iftrue swap dpushf }
  

marvin, infix

Infix to Postfix Converter Class in Marvin

2005-04-16

Here is an object oriented version of the infix to postfix converter written in Marvin:

# infixoop.mar | Converts an infix expression into postfix

# This implementation uses the object data as a hash-table
#    for operator precedence.

"listop forth dequeop" use

@@Infix
    @new  # define the hash-table for operator precedence
        FALSE ^++ ^+- ^-+ ^-- ^*+ ^*- ^** ^*/ ^/+ ^/- ^/* ://
        TRUE ^+* ^+/ ^-* :-/ me ;

    @|> & pushfrom ;

    @string dfront NONE 

marvin, infix, postfix