| Hello, I don't really have as deep an understanding of this subject as I'd like, so my explanation might seem rough, but here's my two cents. You can say a language is a set of rules. Syntactic rules describe what proper sentences in that language look like, while semantic rules describe actions associated with syntactic constructs. The most basic of languages have simple semantic rules. For each language, you can have a program, which accepts as it's input a sentence, checks if it respects the syntactic rules of that language, and then performs the actions dictated by the semantic rules. This bit is clear, I think. Starting from the other direction, if you have a program, you can invent a language, which describes what the program does (semantic) and what are proper inputs (syntactic). Some examples are in order. * Suppose you have a program that finds out the maximum element in a sequence of comma separated numbers. What would the language associated with this program be? Well, it's syntactic rules are simple : a proper input sentence of this program's language is a list of comma separated numbers. The semantic action associated with such a sentence would be to find the maximum of the sentence. * For your Fibonacci example. Even a simple function/program such as this defines it's own language. What would the syntactic rules be? A proper sentence for the Fibonacci function would be a single number (let's call it n). The semantic rule associated is calculating the nth number in the series. * Of course, no list of examples would be complete without the poster children on language - program equivalence : regular expressions and compilers. Regular expressions are written in a small language that describes a program which, when given a certain input, says weather the input matches or doesn't. The syntactic and semantic rules are more complex than in our previous examples, but are well known. As for compilers, if we bend our minds and language a little bit, we can say that GCC is a program which receives a sentence written in the C programming language (so GCC's syntactic rules are C's syntactic rules), and produces an equivalent program in machine language (so GCC's semantic rules are to produce a machine language translation of a C program). Anyway, I hope these few examples help. |