Diodes and transistors represent the fundamental device building blocks for modern semiconductor electronics. Two-dimensional (2D) semiconductors have drawn considerable recent interest for their atomically thin channel and electrostatically tunable device characteristics. However, unlike three-dimensional (3D) semiconductors in which the selective impurity doping can be readily used for controlling the charge carrier type/concentration and realizing functional diodes and transistors, the impurity doping in 2D semiconductors has been challenging due to the limited physical space in the atomically thin lattice for incorporating impurity dopants. To date, the carrier type is usually determined by its intrinsic defects of a given 2D semiconductor and hardly tunable for specific device functions. The creation of diodes or complementary transistor circuits is typically achieved by physical assembly of two distinct 2D semiconductors with intrinsically opposite carrier types. In this dissertation, the development of novel solid-state ionic doping approaches is reported and investigated with which a new class of programmable devices are created to enable 2D diodes, transistors and complementary inverters with tunable carrier type and device polarity. In the first part, by using organic-inorganic halide perovskite materials (methylammonium lead iodide, CH3NH3PbI3) as a solid-state ionic doping agent, a 2D field-effect transistor can be transformed to reversibly switchable diodes and transistors. The perovskite layer not only provides effective doping effects to semiconductor channels, but also greatly enhances the optical absorption of the 2D transistors. In the next chapter, superionic silver iodide (AgI) is employed as a solid-state ionic dopant to show that few-layer WSe2 field-effect transistors can be reversibly transformed into transistors with switchable polarity or diodes with near-unity ideality factors which stably operate at room temperature. Furthermore, complementary logic gates including inverter, NAND and NOR gates are constructed by integrating innately identical transistors. Lastly, it is demonstrated that programmed functions can be erased by thermal or irradiation excitation in a triggerable manner, creating a transient electronic system attractive for protecting vital information.