In my understanding, when a computer program is written, a syntax is a legal statement in the sense that tokens supplied are in expected relative positions. Whether or not that makes "semantic" sense to a given computation or a human is generally regarded as a separate issue.
My question is why is it that semantics is not just a hidden layer of more syntax that isn't obvious in a local scope like that of a single syntactical statement let a = 10
, but is a collective "syntax" of a given context. An algorithm to sort a list of numbers would then be a semantic, given a particular algorithm. Clearly there is no one semantic general syntax of the entire algorithm, as different programmers may use different syntactic statements to solve the problem in essentially the same spirit as the original algorithm intended it. What matters is the end result of the computation, and the computation itself, behaved in generally the same way.