[Maude-help] Re: Parsing question (answer + new question)
Todd Wilson
twilson at csufresno.edu
Wed Nov 2 00:37:23 CST 2005
I recently asked:
> Is there a way that I can get Maude to (meta)parse literal constants
> without also automatically parsing expressions involving these?
My problem was that using metaParse(upModule(M),...), where M was 'NAT,
'FLOAT, 'STRING, or some module like EXP that imported these together,
didn't work, because all of the operations defined on the respective
sorts were also imported. (My examples had some minor errors, as well.)
Well, by doing some experiments, I found that the following works:
fmod EXP is
sorts Nat Float String Exp .
subsorts Nat Float String < Exp .
op 0 : -> Nat .
op s_ : Nat -> Nat [iter special (
id-hook SuccSymbol ()
term-hook zeroTerm (0))] .
op <Floats> : -> Float [special (id-hook FloatSymbol ())] .
op <Strings> : -> String [special (id-hook StringSymbol ())] .
op f : Exp -> Exp .
endfm
Now, entering the following
select META-LEVEL .
red metaParse(upModule('EXP,false), 'f '`( '123 '`), 'Exp) .
red metaParse(upModule('EXP,false), 'f '`( '1.23 '`), 'Exp) .
red metaParse(upModule('EXP,false), 'f '`( '"123" '`), 'Exp) .
red metaParse(upModule('EXP,false), 'f '`( '123 '+ '1 '`), 'Exp) .
gives the results I wanted, namely:
result ResultPair: {'f['s_^123['0.Nat]],'Exp}
result ResultPair: {'f['1.23.Float],'Exp}
result ResultPair: {'f['"123".String],'Exp}
result ResultPair?: noParse(3)
I copied the "special" declarations used in EXP above from
prelude.maude, hoping that they might produce the parsing behavior I was
looking for, and I was rewarded. However, now, my question becomes:
what is the link between these specials and the way Maude parses
integers, floats, and strings? More generally, does there exist any
documentation of these special attributes, id-hook, op-hook, term-hook,
etc.? Am I creating some possible problems by using these features to
parse literal constants in my applications?
Todd Wilson
Department of Computer Science
California State University, Fresno
More information about the Maude-help
mailing list