Building a DSL is not something easy especially with a rich syntax like you proposed, so I assume you are ready :)
The pipeline is:
Script -> Compiler -> PHP code for specific template
Then you are going to use the PHP code to get data
TEXT -> PHP code for that template -> data(structured JSON,XML,...)
So to build a compiler you need to understand the flow:
Script -> Lexer(Tokenizer) -> Parser -> AST/CFG -> PHP code generation
Tokenizer breaks a stream of text into tokens, usually by looking for whitespace (tabs, spaces, new lines).
Lexer is basically a tokenizer, but it usually attaches extra context to the tokens -- this token is a number, that token is a string literal, this other token is an equality operator.
Parser takes the stream of tokens from the lexer and turns it into an abstract syntax tree representing the (usually) program represented by the original text.
A tree representation of the abstract syntactic structure of source
code written in a programming language. Each node of the tree denotes
a construct occurring in the source code. The syntax is "abstract" in
not representing every detail appearing in the real syntax. For
instance, grouping parentheses are implicit in the tree structure, and
a syntactic construct like an if-condition-then expression may be
denoted by means of a single node with two branches.
They are good for expressions not instructions, if you are considering using expressions in your DSL.
a representation, using graph notation, of all paths that might be
traversed through a program during its execution.
Each node is an instruction object (declare, get, read,...) with attributes. eg:
get {
target: customer_name,
from: line {n: 3}
}
Building
PHP is a very poor choice, because there are no quality libraries to build lexers and parsers, like Flex/Bison in C/C++. In this question there are some tools but I don't recommend them Flex/Bison-like functionality within PHP.
I suggest that you build it yourself: