If Rep. Phil Gramm (R-Tex.) could have written a script for his political life this past year, he'd have been hard-pressed to top the one supplied by his enemies, his friends and fate.

Gramm, who switched parties last winter after the Democratic leadership in Congress punished him for disloyalty during the Reagan budget battles, has emerged as the lead contender for this state's 1984 Republican senatorial nomination.

In the two weeks since Sen. John G. Tower (R-Tex.) shocked the political world by announcing that he won't seek a fifth term, Gramm has lined up support from a broad swath of state GOP heavyweights, especially the operatives and fund-raisers who had surrounded former governor Bill Clements.

"Phil has certainly gotten out of the box ahead of everyone else," said state GOP Chairman George Strake. "He has a habit of not waiting for things to happen, but making them happen."

Immediately after Tower's announcement, speculation on possible GOP candidates ran from Clements to former governor John B. Connally to former ambassador to England Anne Armstrong to White House chief of staff James A. Baker III.

But one by one, each scotched a Senate race. Strake said Connally and Clements were probably never interested in the first place, Baker was too involved with his White House chores and Armstrong "said no, then maybe, then no . . . . She might have assessed how quickly Phil got a jump on the field."

Gramm hasn't announced officially, but he is in the middle of a 10-day statewide speaking tour.

The former Texas A&M economics professor commented with characteristic immodesty:

"I'm not saying the reception has been as strong as the Aggies get when they run out onto Kyle Field, but it's pretty close."

Gramm has been carrying around a Lance Tarrance poll showing that he has a high name recognition (66.3 percent) statewide and a 2-to-1 favorable-unfavorable ratio.

Those numbers don't frighten state Democratic leaders.

Nothing would please them more than to get a crack at Gramm statewide next year.

"It is always a pleasure to have the opportunity to give treason its just rewards," said state Democratic Chairman Rober Slagle.

He was referring to allegations that, as Democratic member of the House Budget Committee, Gramm fed strategic information to Republican officials in the White House.

For those alleged activities, and for his professorial, high-profile advocacy of Reaganomics, the Democrats stripped him of his committee assignment in January.

But Gramm was waiting with a counterstrategy.

He immediately resigned from Congress, switched parties, cast himself as a martyr and, six weeks later, won a special election as a Republican to succeed himself in his solidly Democratic, largely rural district that stretches between Houston and Dallas.

"Party-switching can be a problem for a candidate," Strake said, "but I don't sense it this time. People are impressed that Phil did it the honorable way, by resigning and running again. He's almost turned it to his advantage."

The two other likely candidates in a GOP primary do not have nearly Gramm's party leadership support.

They are Rep. Ron Paul, a staunch conservative from Houston who supports the gold standard, and Robert Mosbacher Jr., 32, a former aide to Senate Majority Leader Howard H. Baker Jr. (R-Tenn.) and son of a wealthy Houston oilman.

At the moment, the Democratic primary looks far more competitive.

Rep. Kent R. Hance joined the race just hours after Tower made his announcement.

Hance is expected to have substantial financial backing from the conservative ranks of the party but he'll need to offset the disadvantages of coming from the western part of the state, which is more sparsely populated.

A Hance-Gramm fall election would pit two former "Boll Weevils"--rebel Democrats who supported President Reagan's budget and tax proposals--against one another.

"As much as some Democrats may dislike Kent for what he did, they're ready to kill Gramm for being a traitor," one Hance aide said. "We think we'd be the strongest fall candidate by far."

Conventional wisdom favors any Democrat here in 1984.

Tower is the state's only GOP senator in a century, and the Democrats are on an upswing following last year's upset victory by Gov. Mark White.

Yet the Democratic primary looks like it will be devoid of single towering figure or statewide incumbent.

The other announced candidates are state Sen. Lloyd Doggett of Austin, the hope of the liberals, and former representative Robert Krueger, a moderate who narrowly lost to Tower in 1978. Another possible entry is ex-governor Dolph Briscoe.