How do companies find out how many calories are in their food?
These days, mostly software. In the good/bad old days, by actually burning it (or having a laboratory do that for them). Software is much simpler (unless you are writing it, though it is probably more tedious than complex.)

Input ingredients and quantities, out comes calories. For a restaurant that assumes that the recipe used for calculation matches the actual recipe used.

Here is a USDA database, for instance. Tedious to use, but gives the idea.
http://ndb.nal.usda.gov/ndb/nutrients/index