Coal can be considered to be a sedimentary rock in the class known as chemical sedimentary rocks. It is made up mostly of organic matter. Microscopic examination reveals plant matter - leaves, bark, wood. This plant matter has been compacted over a long time period. It is presumed to have its origin in plant matter that has been buried in an oxygen-deficient environment like a swamp and then compacted over time.
Lignite and bituminous coals are considered to be just sedimentary rocks, but anthracite coal is metamorphic. Anthracite has been altered by the pressures of folding and deformation during mountain building.
Lutgens and Tarbuck