Cyber-Physical systems (CPS), containing discrete behaviors of the cyber and continuous behaviors of the physical, have gained wide applications in many fields. Since CPS subsume the intersection of cyber systems and physical processes, the traditional modeling languages which merely include discrete variables are no longer applicable to CPS. Accordingly, a shared variable language called CPSLsc was proposed to specify CPS. In this paper, we elaborate the algebraic semantics for this language, so that every program of CPSLsc can be converted into a unified form called guarded choice form and the sequentialization of parallel programs is achieved. Additionally, we formalize the algebraic semantics in the rewriting engine Real-Time Maude. With the algebraic laws constructed, for every program specified with CPSLsc, we can simulate its execution step by step. Furthermore, automatic transformation and execution are attained. As a consequence, if the program and its initial data state are provided, the corresponding trace of data states during execution can be generated. In the light of the generated trace, automatic verification can be carried out as well.