I'm putting together a lexer/parser for a simple programming language using a Prolog DCG that builds up the list of tokens/syntax tree using DCG arguments, e.g.
symbol(semicolon) --> ";".
symbol(if) --> "if".
and then the syntax tree is built using those arguments to the DCG rules.
However, I've hit a bump in that when it gets to parsing variables and numbers (only integers in this language), I need the DCG arguments to be more dynamic, e.g.
symbol(number(X)) --> X, {integer(N)}.
Essentially, I need the DCG argument to essentially be generated from what it's actually parsing. Is there a way to do this? If not, what could be a good workaround?
EDIT: As a specific example, I've got the rule
symbol(num(N)) --> {number_codes(N,C)}, C.
and I need the output N=7
when querying phrase(symbol(num(N)),"7").