I'm trying to implement the Class Condition of conditional statements (COBOL) into K. I've already implemented with success the logic of:
- IF [condition] THEN .. ELSE .. END-IF
- Relation Condition (IS GREATER THAN,IS LESS THAN..)
- Sign Condition (IS POSITIVE,...)
- Negated Condition (IF NOT...)
Now i'm trying to implement the class condition for this statement but i cannot figure how to do it.. "Class condition is used to check if an operand contains only alphabets or numeric data. Spaces are considered in ALPHABETIC, ALPHABETIC-LOWER, and ALPHABETIC-UPPER."
I've tried to use some functions of the string library of K (/k/include/builtins/string.k)
My current implementation is (Faulty and not optimized):
syntax Int ::= "lengthString" "(" String ")" [function, klabel(lengthString), hook(STRING.length)]
syntax Int ::= "ordChar" "(" String ")" [function, klabel(ordChar), hook(STRING.ord)]
rule I:String IS ALPHABETIC-UPPER => (ordChar(I) >=Int ordChar("A")) AND (ordChar(I) <=Int ordChar("Z"))
But work only in case of the variable I is composed by a single character, i thought that i must compare every single char but i'm not able to figure how to do
Can someone give me a hint for implement that? I've searched in all tutorials and on the official site, but nothing is able to help me
Thanks to all for the help
Aucun commentaire:
Enregistrer un commentaire