<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
I have question from calculator.m example in mercury<br><br>1) Arguments in the predicate declaration (e.g. fullexpr) are different from its implementation.<br>e.g. arguments for fullexpr are three, but it just takes one (i.e. X) in its implementation.<br>Why is that so? <br><br>2) What is the purpose of ['\n'] <br> <br><br><br>-------------------------------------------------------------<br><br>% Simple recursive-descent parser.<br><br>:- pred fullexpr(expr::out, list(char)::in, list(char)::out) is semidet.<br><br>fullexpr(X) --><br> expr(X),<br> ['\n'].<br><br>:- pred expr(expr::out, list(char)::in, list(char)::out) is semidet.<br><br>expr(Expr) --><br> factor(Factor),<br> expr2(Factor, Expr).<br><br>:- pred expr2(expr::in, expr::out, list(char)::in, list(char)::out) is semidet.<br><br>expr2(Factor, Expr) --><br> ( ['+'] -> factor(Factor2), expr2(plus( Factor, Factor2), Expr)<br> ; ['-'] -> factor(Factor2), expr2(minus(Factor, Factor2), Expr)<br> ; { Expr = Factor }<br> ).<br><br>:- pred factor(expr::out, list(char)::in, list(char)::out) is semidet.<br><br>factor(Factor) --><br> term(Term),<br> factor2(Term, Factor).<br><br>:- pred factor2(expr::in, expr::out, list(char)::in, list(char)::out)<br> is semidet.<br><br>factor2(Term, Factor) --><br> ( ['*'] -> term(Term2), factor2(times(Term, Term2), Factor)<br> ; ['/'] -> term(Term2), factor2(div( Term, Term2), Factor)<br> ; { Factor = Term }<br> ).<br><br>:- pred term(expr::out, list(char)::in, list(char)::out) is semidet.<br><br>term(Term) --><br> ( const(Const) -><br> { string.from_char_list(Const, ConstString) },<br> { string.to_int(ConstString, Num) },<br> { Term = number(Num) }<br> ;<br> ['('], expr(Term), [')']<br> ).<br><br>:- pred const(list(char)::out, list(char)::in, list(char)::out) is semidet.<br><br>const([Digit|Rest]) --><br> digit(Digit),<br> ( const(Const) -><br> { Rest = Const }<br> ;<br> { Rest = [] }<br> ).<br><br>:- pred digit(char::out, list(char)::in, list(char)::out) is semidet.<br><br>digit(Char) --><br> [Char],<br> { char.is_digit(Char) }.<br><br /><hr />Con Windows Live Messenger chatti, parli, giochi, crei il tuo blog, controlli la tua posta, scambi file, foto e molto altro con un solo programma GRATUITO. <a href='http://www.messenger.it' target='_new'>Scarica Messenger 8.1</a></body>
</html>