# Why not just use FSTs for combining syntactic and semantic analysis?

I've just found the finite state transducer.

Since the FST processes two tapes: one for input, one for output,

shouldn't it be possible to use FST to "pack together" some compiler stages, such as Syntactic Analysis and Semantic Analysis.

The FST could take in tokens and output semantically analysed code.

How useful this would be depends on the level of the Chomsky hierarchy at which the transducer operates:

• Regular languages:

A Finite State Automaton (FSA) is represented by its transitions (e.g. via a diagram or a list of triples) and the corresponding transducer can be seen as adding an output to each of the transitions.

Hence, the output is at the same 'granularity' as the input alphabet, which may not always be what's desired for associating semantics with syntax.

The issue is not so much with the redundant (epsilon) outputs' as the possible need to make semantic decisions at the level of sequences of syntactic elements, modeled in regular languages by a (necessarily fairly messy) nested transducer scheme.

• Context-free grammars

More usefully than for regular languages, it is possible to use syntax-directed translation which can be seen as a transducing' scheme associating a semantic output with a grammatical production.

• I did think that but was thinking of e.g. adding "epsilons" (empty string) to the outputs that aren't required. Then possibly even filtering them out. – mavavilj Dec 25 '15 at 23:49
• @mavavilj - is the revised answer above of any greater help? – NietzscheanAI Dec 26 '15 at 8:33
• What's the difference between syntax-directed translation and the FST? – mavavilj Dec 26 '15 at 9:02
• @mavavilj - answer now revised to make the distinction explicit. – NietzscheanAI Dec 26 '15 at 9:34