1. A method comprising, by a computing device: accessing a social graph comprising a plurality of nodes and a plurality of edges connecting the nodes, each of the edges between two of the nodes representing a single degree of separation between them, the nodes comprising: a first-user node corresponding to a first user associated with an online social network; and a plurality of second nodes that each correspond to a concept or a second user associated with the online social network; receiving from the first user an unstructured text query; identifying one or more edges or one or more second nodes, each of the identified edges or identified nodes corresponding to at least a portion of the unstructured text query; accessing a context-free grammar model comprising a plurality of grammars, each grammar comprising one or more query tokens; identifying one or more grammars, each identified grammar having one or more query tokens corresponding to at least one of the identified second nodes or identified edges; determining a first score for each identified grammar; and generating one or more structured queries, each structured query corresponding to an identified grammar having first score greater than a grammar-threshold score wherein the structured query is based on a string generated by the identified grammar, each structured query comprising the query tokens of the corresponding identified grammar, wherein one or more of the query tokens of the structured query corresponds to at least one of the identified second nodes or identified edges.