Skip to Content.
Sympa Menu

k-user - [K-user] How to escape underscores in syntax

k-user AT lists.cs.illinois.edu

Subject: K-user mailing list

List archive

[K-user] How to escape underscores in syntax


Chronological Thread 
  • From: Ulrich Kühne <ulrichk AT informatik.uni-bremen.de>
  • To: k-user AT cs.uiuc.edu
  • Cc: ulrichk AT informatik.uni-bremen.de
  • Subject: [K-user] How to escape underscores in syntax
  • Date: Wed, 12 Sep 2012 09:44:36 +0200
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
  • List-id: <k-user.cs.uiuc.edu>

Hi,

I would like to parse a language which has keywords containing underscores '_'. Unfortunately, since the '_' is a special symbol in K, there seems to be no way of escaping it in the syntax rules and make it work as expected. Here is a minimal example:

module FOO
syntax Foo ::= "foo_bar" Int
syntax KResult ::= Int
rule foo_bar X:Int => X
endmodule

What I get is an error message:

$> kompile foo
Some errors occurred..
sdf-load:error: parse error, '_' unexpected
--- input string [file: ./Program.sdf line: 11 col: 14]

I also tried things like "foo\_bar", but this doesn't work either. So an (unpleasant) workaround would entail preprocessing the source code in order to remove all underscores. There must be a better way, no?

Thanks in advance.
Ulrich

PS: A reference document would be great, listing all the builtins and operations. It took me quite some time to figure out the "X in keys(Map)" trick :-)



  • [K-user] How to escape underscores in syntax, Ulrich Kühne, 09/12/2012

Archive powered by MHonArc 2.6.16.

Top of Page