Skip to Content.
Sympa Menu

maude-help - Re: [Maude-help] Re: simple calculator program

maude-help AT lists.cs.illinois.edu

Subject: Maude-help mailing list

List archive

Re: [Maude-help] Re: simple calculator program


Chronological Thread 
  • From: Steven Eker <eker AT csl.sri.com>
  • To: "Kok Wei Shiung" <kwshiung AT yoyo.monash.edu.my>, maude-help AT banyan.cs.uiuc.edu
  • Subject: Re: [Maude-help] Re: simple calculator program
  • Date: Thu, 9 Oct 2003 12:37:20 -0700
  • List-archive: <http://maude.cs.uiuc.edu/pipermail/maude-help/>
  • List-id: Maude help list <maude-help.maude.cs.uiuc.edu>
  • Organization: SRI International

Hi,

There are a number of problems with this code:

The second colon in the op declarations shouldn't be there.
The way to end an fmod is "endfm".
ceq's need an if part.
You're using MachineInt which only exists in the Maude 1. I recommend using
Maude 2 for new programs.
If you use the built in operators like _+_, they will evaluate their
arguments
before calc(...) gets matched in most cases. Also you need to be careful
about attributes when overloading built in operators.

Best regards,

Steven Eker

On Thursday 09 October 2003 02:03 am, Kok Wei Shiung wrote:
> Hi maude-help,
>
> I've encountered problem on this piece of code:
>
> fmod CALC is
> protecting MACHINE-INT .
>
> sorts first second answer .
> subsorts first < second < answer < MachineInt .
>
> op _ : MachineInt : -> first [assoc] .
> op _*_ : MachineInt MachineInt : -> first [assoc] .
> op _/_ : MachineInt MachineInt : -> first [assoc] .
> op _+_ : first first : -> second [assoc] .
> op _-_ : first first : -> second [assoc] .
> op calc : second -> MachineInt .
>
> var N1 : MachineInt .
> var N2 : MachineInt .
>
> eq calc( N1 ) = N1 .
> ceq calc( N1 + N2 ) = N1 + N2 .
> ceq calc( N1 - N2 ) = N1 - N2 .
> eq calc( N1 * N2 ) = N1 * N2 .
> eq calc( N1 / N2 ) = N1 / N2 .
> end fmod)
>
> This is a simple calculator program. It suppose to take an equation,
> evaluate the (*/) first then follow by (+-). An Error message 'no loop
> state' appear when i load it into maude. Is this error caused by the
> grammar itself or syntax error of the code? How to fix this problem?
>
>
> Thank you!
>
>
> from,
> Vincent





Archive powered by MHonArc 2.6.16.

Top of Page