Parsing Cymbol
To demonstrate how to parse a programming language with syntax derived from C, weâre going to build a grammar for a language I conjured up called Cymbol. Cymbol is a simple non-object-oriented programming language that looks like C without structs. A grammar for this language serves as a good prototype for other new programming languages, if youâd like to build one. We wonât see any new ANTLR syntax, but our grammar will demonstrate how to build a simple left-recursive expression rule.
When designing a language, thereâs no formal grammar or language reference manual to work from. Instead, we start by conjuring up representative samples of the language. From there, we derive a grammar as we did in âDeriving Grammars ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.