A 3-address code is designed to be a simplified form of machine language.
Each 3-address instruction has an operation kind and up to 3 operands. Each operand can be a name or a number.
See a sample 3-address translation.
Some compilers generate code for each expression or statement while parsing the expression or statement.
Typically, gen(inst) adds 3-address code inst to an array of 3-address codes.
See an expression example for an example of syntax-directed translation of expressions and control flow and backpatching for an example translation of statements.
You should be able to write semantic actions to do a simple syntax-directed translation.