What are the definitions of syntax and semantics?
To beging with, the expression "formal language" may refer to formally
defined sets of string as considered in the theory of automata and
formal languages. I shall write that "Formal Language" with capital
first letters. But "formal language" may also refer to some kind of
language that is intended for expressing meaning, but is precisely
defined mathematically. I shall rather call it formally defined language.

A first remark is that formally defined languages are similar to natural
languages (vernacular), in the sense that both are used to convey
meaning through representations of that meaning.

This is the fundamental issue. We have to convey meaning, to others,
or to ourselves (when we take notes). Meaning can concern all sorts of
things, some finite, some infinite, possibly about strange domains of
human imaginations, such as real numbers, or the set of all sets.
But we can always do that only through representation. The
representation may be a linear sequence of symbols. It may also be a
spatially organized collection of symbols. It may be drawings, or data
structures in a computer, or sound stream, or gestures. It is
physical.

To answer the question in a nutshell, and in a very general way: the
organisation of the physical representation of discourse is syntax,
while semantics is the meaning conveyed, and the way it is derived
into, or from, the representation.

A major characteristic of syntax is that syntactic representations
are finite: they convey a finite amount of information. This is true
of pictures that can de digitized with finite precision to convey what
they are supposed to convey, But the best example is one of the most
common form of representation: the written text. If one takes all the
symbols used for writing as digits in a proper base, any written text
may be read an integer number, which is a finite object. This does not
prevent the discourse from being about infinite objects, or whatever
else, including ghosts, leprechauns, the Zeta function, the turtle
that carries the planet on its back and the last Sunday before the
Big-Bang. And, this does not forbid having an infinite number of
representations, of sentences of the language.

But how is syntax connected to semantics? How do we associate a
meaning with physical representation. The most basic way is to
associate a specific meaning to specific representations, and learn
these associations. This is basically how ideographic writing gets
started. But it has limitation: you can define only a finite number of
meanings in this way. An important aspect of language is to
be able to handle unbounded number of meaning by associating in an
organized way the representation of elementary meanings.

So syntax is not just a collection of elementary representations, but
also a collection of rules to associate them to make more complex
representations. Elementary representations correspond to elementary
meanings, and rules associating them indicate how the simpler meanings
can be composed to make more complex meanings.

A simple example is the way formally defined languages are
specified in mathematics (I am simplifying somewhat, skipping over
some technical issues, parsing technology for example). The syntax is
defined as a set of string over an alphabet. This set is often defined
by a context-free grammar. that provides rules to create strings on
the alphabet. The rules also associate strctures to strings: the
parse-trees. The definition of semantics associate a value (of
whatever domain) to the elements of the alphabet, and associate
operations on these values to the rules of the grammar. This define a
homomorphism from the set of string in the context-free syntax to the
set of values in the semantic domain. (Note that, sometimes, the syntax is directly defined as a set of trees.)

So we have an infinite set (the syntax Formal Language) of finite
representations (string or sentences of the formal language) which has
a finite definition/description (the Context-Free grammar). The
semantics is defined by specifying a domain of values, and both the
domain and the values in it may be finite or infinite entities. For example
a mathematical text, though finite, can talk about real numbers which
are a continuously infinite set of infinite entities (in the sens that
most reals do not have a finite description). Furthermore, the mapping
is finitely defined, by associating a function with each grammar rule.
A rule composes subpart of the text into a larger text, and the
associated function composes the meaning of these subparts into a
meaning for the larger text.

Not all kinds of Formal Languages may be appropriate for syntax
definition. They must provide some structure to the language strings
that can be used to define the semantics mapping. Besides context-free languages and grammars, there are
many other kinds of Formal Languages and Formal Language Definitions
that can provide structure for syntax strings (tree adjoining grammars
for example). They are mostly used in computational linguistics for
natural language. Other mechanisms, such as attributes or features on
grammar symbols, can be added both to specify the strings of the
languages or the semantics mapping (but it may be disputed whether
they should be considered syntax or semantics).

However, as written earlier, syntax need not be composed of strings of
symbols. Other structured representations can be considered, such as
graphs, or sound stream. An interesting example is abstract syntax
trees that can represent programs of a programming language as tree
structures. Some programming systems and development environments
actually consider the abstract syntax tree (AST) as the primary
representation of programs, and provide tools to create programs
represented directly as AST, possibly without ever producing a string
representation in some cases. The language Lisp was probably the first to do that.
This is also very frequent in proof systems and other symbolic
computation systems that manipulate mathematical formulae, which
remain represented by tree structures, or even other data types.

This shows that different representation systems, different syntaxes,
may be used to represent the same semantic structures. Actually, when
these representations can easily be translated into each other, while
preserving semantic meaning, they are often considered the same
language. In other words, the same language may have multiple
syntactic representations, including multiple string syntaxes.  But
the semantics preserving intertranslatability shows that these
different representations are structurally similar. Another obvious
example is natural language, that can exist as text or as speech.

Conversely, given a syntax, it is possible to combine it with
different semantic interpretations, i.e. different semantic mappings.