Math in manhattan

Perl, 100 99 98 bytes

97 bytes code + 1 byte command line

s/ |.*\K(\d)(\d*)-M\1|\+M/\2/g+s/(\d+)\*M(.)/$1=~s@$2@$&x$&@erg/e+s#/(M.)\d+#*\1#&&redo,$\=eval}{

Usage example:

echo "123 *M 2 * 3 + 150 /M 53" | perl -p entry.pl

Python, 644 bytes

import operator as o,re
x,q,t,r,w='*/+-M';mm,md,ma,ms='*M /M +M -M'.split()
n=lambda x:x
a=lambda a,b:str(10*int(a)+int(b))
v=lambda a,b:a[::-1].replace(b,'',1)[::-1]
m=lambda a,b:a.replace(b,b*int(b))
d=lambda a,b:m(a,b[0])if a>0 else b[0]
def p(s):s=s.group();ss=s.split();l=s.split(ss[1]);h={mm:m,md:d,ma:a,ms:v,x:o.mul,q:o.div,t:o.add,r:o.sub}.get(ss[1],n);return str(h(*map(int if h in[o.mul,o.div,o.add,o.sub]else n,map(u,map(str.strip,l)))))
def u(s):z=r'\d+ (?:\{0}{2}|\{1}{2}) \d+';return re.sub(z.format(t,r,''),p,re.sub(z.format(t,r,w),p,re.sub(z.format(x,q,''),p,re.sub(z.format(x,q,w),p,re.sub(r'\((.*)\)',u,s)))))
print u(input())

Accepts input on STDIN (wrapped in quotes). Uses regex to match and parse operations. All work is done on strings, and casting to and from ints is only used when doing normal mathematical operations.

I'm pretty sure this could be golfed further, so I'll be working on that over the next few days.


Dyalog APL, 104 81 79 93 75 bytes

Edit: Now handles 4342343 -M 3443423 correctly.

M←{⍎(5|⌊⍺⍺2)⊃'⍺×M⍣(⍺≠1)⍎⊃b'(b⎕R(⍵⍴'&')⊢a)'10⊥⍺⍵'(('(.*)',b←⍕⍵)⎕R'\1'⊢a←⍕⍺)}

Background

This extends APL to include the Manhattan operator. An operator in APL terminology is a modifier of functions (e.g. ÷). An example of an operator is which modifies functions to swap their arguments so 3 = 2 ÷⍨ 6. So too, M modifies the basic arithmetic functions to be their Manhattan relatives. Note that since the resulting language is an extension of APL, APL's strict right-to-left precedence remains.

Explanation

The overarching structure is M←{⍎(5|⌊⍺⍺2)⊃} which applies the function (+ or - or × or ÷) to 2 and uses the result to chose which string to evaluate. The strings are:

3 for -M: (('(.*)',b←⍕⍵)⎕R'\1'⊢a←⍕⍺)
 regex remove the last occurrence of b (string rep. of right arg.) in a (string rep. of left arg.)

2 for +M: '10⊥⍺⍵'
 evaluate the arguments as base-10 digits

1 for ×M: (b⎕R(⍵⍴'&')⊢a)
 replace occurrences of b with b ampersands (i.e. regex for the

0 for ÷M: '⍺×M⍣(⍺≠1)⍎⊃b'
⍎⊃b first digit of b
⍺×M⍣(⍺≠1) apply ⍺ ×M if ⍺ ≠ 1

out of of the above four strings, pick number:

(5|⌊⍺⍺2) mod-5 of the floor of the function applied to 2, namely:
 3 = 5 | ⌊-2
 2 = 5 | ⌊+2
 1 = 5 | ⌊×2 because ×2 ⇔ sgn(2) ⇔ 1
 0 = 5 | ⌊÷2 because ÷2 ⇔ 1 ÷ 2 ⇔ 0.5

Lots of thanks to my dear friend ngn for amazing shavings.