3 ms·
IMO, The best example of designing and implementing a "small" language can be seen in Chapter 8 of "The Unix Programming Environment by Kernighan & Pike" where
by truth_be_told 8y ago
IMO, The best example of designing and implementing a "small" language can be seen in Chapter 8 of "The Unix Programming Environment by Kernighan & Pike" where they walk you through the construction of "hoc" (higher order calculator) using the standard compiler construction tools. The example is realistic, not too small nor too big and every step is explained. The exposition is very clear and you really can "get" how languages are designed and implemented. This should be the first thing you should read :-)
If you have a specific problem, you can then write a small DSL for it. I once had the opportunity to write a small "test language" for the sub-protocols of H.323. These protocols are specified using SDL (https://en.wikipedia.org/wiki/Specification_and_Description_Language https://en.wikipedia.org/wiki/Specification_and_Description_...) and i just converted the tokens in the spec directly into my language and put a simple markdown syntax around it. The tests simply exercise the protocol FSM.
Eg:
<H245>
<Test1>
<Prestimuli>
Var1=Val1 //these are assignments
Var2=Val2
</Prestimuli>
<Stimuli>
MsgFromNetwork=<msg name> //trigger to FSM
</Stimuli>
<Poststimuli>
Var1=Val1.1 //these are assertions
Var2=Val2.1
</Poststimuli>
</Test1>
</H245>
Though simple, this worked nicely, allowing me to push off the actual writing of the test cases to non-programmers who just had to convert the SDL diagrams from the spec. to text as given above.