P.E. is right on the money. The bore/stroke, thus the displacement is something totally different than compression ratio.
As P.E. said, the piston dome shape and the combustion chamber size determine the C.R. Here's how they might change. If you have a piston top with a "dish", this increases the combustion chamber volume when the piston is at top dead center(TDC). Yes it also increases volume when piston is at bottom dead center(BDC). This is a ratio, so the effect of this volume change is different at BDC than it is at TDC.
In the M103 engine, at least the USA equipped model, you have a dished piston. You could increase the CR by using a flat top piston. I expect that this would raise the CR by a point or two. There would be a problem with this, the M103 already has a high compression ratio, if memory serves me correctly, it is 10:1. When you get much higher than this CR, you quickly reach a point where you can't run the engine on the gasoline we now have, without experiencing engine destroying preignition (spark knock).
The M103 engine is pretty well optimized as it is for a street engine. You could put a little more camshaft in it and pick up maybe 10 or 20 horsepower, but you would be sacrificing torque in the midrange which is not over abundant in these engines.
I believe the M103 makes something like 190 HP. In a 3.0 litre engine, this is right at 1HP per cubic inch. Once you go much past 1HP per cubic inch, you are starting to enter race engine territory, not street engine characteristics.
I have no doubt that with time to play and a VERY thick wallet, you could up the HP in this engine, but it would become undrivable on the street.
Your other question was about rear axle gears. I understand where this question comes from, the 124 cars are geared very tall. This is because of the Corporate Average Fuel Economy (CAFE) laws that were passed in the US about the time the 124 came out. There was a penalty to a manufacture whose average fuel economy of all the cars they sold in the US was not above a certain level. Tall gears mean better fuel economy at the expense of performance.
An independent machine shop would have an EXTREMELY difficult time fabricating rear axle gears. These are hypoid cut gears and would be a very complex task, most machine shops would not have the equipment to do this regardless of the time they would be willing to put into it. Even if they could, they would have to be properly hardened. This would be a totally impractial approach.
The good news for you is that I would be surprised if you can't buy a ring gear and pinion from AMG or maybe even MB. I'm sure it would be expensive, but available. With gears in hand don't expect to be able to throw them in one Saturday morning. The differential unit must come out(not a real big deal in itself) and the gears changed AND PROPERLY ADJUSTED. An experienced tech can set them up properly. This must be done, or your gears will either be noisy or won't last long, or both.
If you insist on adding performance to your 124 car, are willing to spend the money for the modifications AND for the additional fuel you will burn thereafter, I would recommend going the gear route and not modifying the engine.
One more thing to keep in mind. When you put a performance gear in the rear, you will be giving up top speed.
Whenever you decide to go down the path of modifying a car, you must keep something in mind; every modification you make will have a downside. To pick up performance, you will almost always give up fuel economy. In many cases when you pick up performance you will be giving up engine life.
Modifying a car is a compromise. Be sure you always look for the downside to whatever modification you're making, because there ALWAYS is one.
'01 C Class, Six Speed
'84 Euro 240D, manual, 533K miles
'88 300E 5 Speed
'81 300D Daughter's Car
Over 800,000 miles in