k-user AT lists.cs.illinois.edu
Subject: K-user mailing list
List archive
- From: "Park, Daejun" <dpark69 AT illinois.edu>
- To: SITTHISAK Pakakorn <pakakorn.s AT jaist.ac.jp>
- Cc: "k-user AT cs.uiuc.edu" <k-user AT cs.uiuc.edu>
- Subject: Re: [K-user] New syntactic category
- Date: Fri, 22 Aug 2014 15:04:29 +0000
- Accept-language: en-US
- List-archive: <http://lists.cs.uiuc.edu/pipermail/k-user/>
- List-id: <k-user.cs.uiuc.edu>
Hi Pakakorn,
You can use #tokenToString and #parseToken, built-in functions for conversion between tokens and strings. For example,
syntax Name ::= Token{[\_\$A-Za-z][\_\$A-Za-z0-9]*} [notInRules]
syntax String ::= StringOfName(Name) [function, notInPrograms]
rule StringOfName(N:Name) => #tokenToString(N)
syntax Name ::= NameOfString(String) [function, notInPrograms]
rule NameOfString(S:String) => #parseToken("Name", S)
syntax String ::= StringOfName(Name) [function, notInPrograms]
rule StringOfName(N:Name) => #tokenToString(N)
syntax Name ::= NameOfString(String) [function, notInPrograms]
rule NameOfString(S:String) => #parseToken("Name", S)
Once you get the string representation of the token, you can use the built-in string library functions to manipulate the string, such as substrString, findString, replaceAll, lengthString, Char2String, and String2Char. Please refer to "include/builtins/string.k"
for details:
https://github.com/kframework/k/blob/master/include/builtins/string.k
Best,
Daejun
On Aug 20, 2014, at 2:06 PM, SITTHISAK Pakakorn <pakakorn.s AT jaist.ac.jp> wrote:
Hi,
If I would like to define my NewId like this.
syntax NewId ::= Lexer{( [A-Za-z][A-Za-z0-9]* | [A-Za-z][A-Za-z0-9]* "_" [A-Za-z][A-Za-z0-9]*) }
I would like to define function like newIdToString and concatenation function like
newIdToString( NewId_A1 ) => "NewId_A1"
concat(NewId , A1 ) => NewId_A1
How can I access each character, decompose new syntactical category and convert to other sorts, like String?
Thank you.
Pakakorn
_______________________________________________
k-user mailing list
k-user AT cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/k-user
- [K-user] New syntactic category, SITTHISAK Pakakorn, 08/20/2014
- Re: [K-user] New syntactic category, Park, Daejun, 08/22/2014
Archive powered by MHonArc 2.6.16.