16.5. Building Commands
Imperative languages such as Sling let a user write a script, or program, that tells the computer what to do. When you create a parser for an imperative language, a good approach is to follow the command pattern [Gamma et al.]. The intent of this pattern is to encapsulate a request. The Sling parser builds a command object that contains the user's request in a Java object. An advantage of building a command from an imperative script is that this approach divides your user's task into two phases.
Users, when programming in your language, will spend much of their time trying to arrive at a syntactically correct input that your parser can recognize. Simple typographic errors as well as deeper misunderstandings about the rules ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access