Abarim Publications' online Biblical Hebrew Dictionary
The masculine noun גג (gag) means roof or top, or (as HAW Theological Wordbook of the Old Testament puts it) the highest point of an edifice. Its root is unknown and it has no sibling derivations.
The noun גג (gag) denotes most commonly the flat roof of a building on which things can take place; usually to do with idolatrous worship (Judges 16:27, Joshua 2:6, 2 Samuel 11:2, 2 Kings 23:12, Jeremiah 19:13 and 32:29, Zephaniah 1:5; but also Acts 10:9). Roofs were also used to publish messages, news or expressions of grief into the neighborhood (Isaiah 15:3, Matthew 10:27, Luke 12:3), and possibly as a place of refuge (Joshua 2:6, Isaiah 22:1, Matthew 24:17) or lodging (1 Samuel 9:25-26, 2 Samuel 16:22).
The housetop seems to indicate a certain spiritual exposure. Someone on the housetop opens himself for something, preferable something soothing, or higher. Since societies at large were often referred to as houses (particularly the "houses" of the national deity), their "roofs" might refer to its apex in science and technology. Note that although in our day and age technology is mostly either electronic or else noisy and stinky, the cultures featured in the Bible (and yet even the Bible itself) excelled mostly in information technology.
The alphabet was arguably the most sophisticated thing to come out of the Bronze Age, but the literary traditions that carried it went much beyond what we today call a good yarn. Mankind's most ancient stories contain a level of complexity that is truly mind boggling. Whether by intuition, natural selection or some other technique, the ancient stories that we know so well are the mere wrappings of vast data banks and pools of wisdom, ranging from the Standard Model of Elementary Particles to Relativity Theory, evolution theory, cosmology, sociology, psychology and an untold library of technologies.
Also note that the ominous names Gog and Magog are derived from this root.