name = 'expr/3' slug = 'arithmetic expressions with meaning' description = '''\
Write a DCG with the starting symbol expr
for the language of arithmetic expressions consisting of numbers (without leading zeros), addition and multiplication. Subexpressions can be grouped using parentheses. The meaning of a word in this language is the numeric value of the represented arithmetic expression.
Example words: (1+2)*3
, 42*8*3
, (2+1)*(3+4)
.
?- expr(N, ['(',2,'+',1,')','*','(',3,'+',4,')'], []). % (2+1)*(3+4) = 21 N = 21.''' hint = {}