Human behavior understanding has attracted the attention of researchers in various fields over the last years. Recognizing behaviors with sufficient accuracy from sensors analysis is still an unsolved problem, because of many reasons, including the low accuracy of the data, differences in the human behaviors as well as the gap between low-level sensors data and high-level scene semantics. In this context, an application that is attracting the interest of both public and industrial entities is the possibility to allow elderly or physically impaired people conducting a normal life at home. Ambient intelligence (AmI) technologies, intended as the possibility of automatically detecting and reacting to the status of the environment and of the persons, is probably the major enabling factor for the achievement of such an ambitious objective. AmI technologies require suitable networks of sensors and actuators, as well as adequate processing and communication technologies. In this paper we propose a solution based on context free grammars for human behavior understanding with an application to assisted living. First, the grammars of the different actions performed by a person in his/her daily life are discovered. Then, a longterm analysis of the behavior is used to generate a control grammar, taking care of the context when an action is performed, and adding semantics. The proposed framework is tested on a dataset acquired in a real environment and compared with state of the art methods already available for the problem considered.