How do I separate parsing logic from semantic logic (from code generation logic)?
I’m using an internal DSL => Expression Builder + Semantic Model
Parsing
How do I hold symbols to cross-reference between different parts of the parse?
=> Symbol Table
How do I keep hierarchic context during the parse?
As much as possible, I keep it on the stack and use parameters and return values.
If I can’t => Context Variable
How do I gradually build up an immutable object?
How do I collect and return multiple errors back to the caller of the parse?
=> Notification
External DSLs
How do I break up text into a parsing structure?
=> Syntax-Directed Translation + BNF
My structure is very simple => Delimiter-Directed Translation
How do I build a lexer?
If I’m using a Parser Generator and there is a lexer generator that fits well, I’ll use that.
How do I build a parser?
My grammar is simple => Parser Combinator
There is no Parser Generator for my platform => Parser Combinator
I prefer control flow to composing objects => Recursive Descent Parser
How do I generate output?
My output maps cleanly onto the Semantic Model => Embedded Translation
My transformation is more complicated => Tree Construction
I want to execute simple DSL statements immediately => Embedded Interpretation
How do I handle arithmetic expressions, Boolean expressions, or similar structures?
How do I handle cases that are too rare to be worth extending the DSL? How do I weave non-DSL behavior into the DSL?
=> Foreign Code + Embedment Helper
I’m using Foreign Code, and my DSL has become overwhelmed and thus hard to see.
How I do I change my lexing rules in the middle of a parse?
How do I handle newlines that are part of the grammar when using Syntax-Directed Translation?
Internal DSLs
How do I represent a sequence of high-level statements?
How do I handle a fixed sequence of clauses?
The clauses are mandatory => Nested Function
There are optional clauses => Literal Map
I need optional clauses and don’t have literal map syntax => Method Chaining
How do I handle a variable sequence of clauses?
Each clause is the same => Literal List
The clauses are different => Method Chaining
Each clause should appear only once => Literal Map
How do I build simple expressions in method names?
How do I represent method parameters as method names?
How do I start an expression with a number (or other literal)?
How do I use bare function calls without using global data or functions?
How do I control when I evaluate a clause?
The clause is inside a method => Nested Closure The clause is in a class definition => Annotation
How do I get static type checking or type-safe autocompletion?
How do I make my DSL look less like the host language?
My changes are simple textual substitutions => Textual Polishing
If it’s more complicated, use an external DSL instead.
How do I populate my Semantic Model with expressions written in my host language without evaluating those expressions?
Code Generation
How do I drive producing the output code?
Most of the output is generated => Transformer Generation
There’s a lot of non-generated output => Templated Generation
How do I keep my templates readable using Templated Generation?
How do I structure my semantics in my target code?
The target language isn’t expressive enough => Model Ignorant Generation
How do I interweave generated and handwritten code?
Use calls between generated and handwritten objects.
I need to mix generated and handwritten code in the same object => Generation Gap
Alternative Computational Models
How do I arrange computation using a model different from my host language?
How do I represent conditional logic?
I have a composite conditional expression => Decision Table
I have a list of conditions to be evaluated => Production Rule System
How do I represent tasks that are computationally expensive and have prerequisite tasks that must be checked first and executed if necessary?
How do I represent a machine that reacts differently to events depending on the state it’s in?
3.139.105.159