k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: Gurvan Le Guernic <gleguern AT gmail.com>
- To: k-user AT lists.cs.illinois.edu
- Subject: [[K-user] ] [K] Parsing input stream
- Date: Wed, 20 Jan 2016 17:55:52 +0100
Hi,
I'm using K to specify the semantics of a "message" filtering language. In order to evaluate the semantics, the "filtering program" is the program parsed by K at start up and the "messages" to filter are retrieved from stdin, i.e. the configuration contains the following fragment :<streams color="yellow">
<in stream="stdin"> .List </in>
<out stream="stdout"> .List </out>
</streams>
syntax Holder ::= "getNextMsg"
rule
<k> . => getNextMsg </k>
<out> ... .List => ListItem("> ") </out>
[structural]
rule
<filter> F:Filter </filter>
<k> getNextMsg => F </k>
<in> ListItem(Msg:String) => .List ...</in>
<input>
...
<msg>
<ctt> _ => replaceAll(Msg, "\n", "") </ctt>
</msg>
</input>
[structural]
syntax MsgTimeStp ::= Int
syntax MsgPortId ::= String
syntax MsgData ::= String
syntax Msg ::= "(" MsgTimeStp "," MsgPortId "," MsgData ")"
I modified the configuration :
syntax Msg ::= "NullMsg"
<rawInput> NullMsg:Msg </rawInput>
and tried to replace the last rule with the following one :
rule
<filter> F:Filter </filter>
<k> getNextMsg => parseInputMsg </k>
<in> ListItem(Msg:Msg) => .List ...</in>
<rawInput> Msg </rawInput>
[structural]
syntax Msg ::= "NullMsg"
<rawInput> NullMsg:Msg </rawInput>
and tried to replace the last rule with the following one :
rule
<filter> F:Filter </filter>
<k> getNextMsg => parseInputMsg </k>
<in> ListItem(Msg:Msg) => .List ...</in>
<rawInput> Msg </rawInput>
[structural]
It does compile and start runing. However, when I provide the following string "( 3 , IN, 000000000000100001000 )" on stdin, K stops (without error messages) and output a configuration where the cell <k> still contains "getNextMsg".
Is there a way to parse the piece of data retrieved from stdin into a K term on which to apply further rules ? Or do I have no other way than to add to the program the messages to parse and do the parsing at load time ?
Thanks,
Gurvan Le Guernic
- [[K-user] ] [K] Parsing input stream, Gurvan Le Guernic, 01/20/2016
- Re: [[K-user] ] [K] Parsing input stream, Park, Daejun, 01/20/2016
Archive powered by MHonArc 2.6.16.