StringOrd¶
The character code of the first character of a string.
Declaration¶
Syntax¶
StringOrd(expr arg, ttype type, expr? value)
Arguments¶
Argument |
Description |
|---|---|
|
the string. |
|
the type of the expression. |
|
the compile time value of the expression, when the frontend could fold it; |
Return values¶
The value of the expression.
Description¶
The result is an integer. Ichar and Iachar are the
Fortran spellings of the same idea, in the processor collating sequence and in
ASCII respectively; StringOrd is LPython’s ord.
Examples¶
(StringOrd
:arg (Var
:v (SymbolRef 1 "c")
)
:type (Integer
:kind 4
)
:value nil
)
It comes from this complete ASR text document:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"main" (Program
:symtab (SymbolTable
:id 1
:symbols {
"b" (Variable
:parent_symtab 1
:name "b"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Logical
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"c" (Variable
:parent_symtab 1
:name "c"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (String
:kind 1
:len (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"n" (Variable
:parent_symtab 1
:name "n"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Integer
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"s" (Variable
:parent_symtab 1
:name "s"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (String
:kind 1
:len (IntegerConstant
:n 5
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"t" (Variable
:parent_symtab 1
:name "t"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Allocatable
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
}
)
:name "main"
:dependencies []
:body [
(Assignment
:target (Var
:v (SymbolRef 1 "s")
)
:value (StringConstant
:s "hello"
:type (String
:kind 1
:len (IntegerConstant
:n 5
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "t")
)
:value (StringConcat
:left (Var
:v (SymbolRef 1 "s")
)
:right (StringConstant
:s "!"
:type (String
:kind 1
:len (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
)
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "t")
)
:value (StringRepeat
:left (Var
:v (SymbolRef 1 "s")
)
:right (IntegerConstant
:n 3
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (String
:kind 1
:len nil
:len_kind :DeferredLength
:physical_type :DescriptorString
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "n")
)
:value (StringLen
:arg (Var
:v (SymbolRef 1 "s")
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "c")
)
:value (StringItem
:arg (Var
:v (SymbolRef 1 "s")
)
:idx (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (String
:kind 1
:len (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "t")
)
:value (StringSection
:arg (Var
:v (SymbolRef 1 "s")
)
:start (IntegerConstant
:n 2
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:end (IntegerConstant
:n 4
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:step (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (String
:kind 1
:len (IntegerConstant
:n 3
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "b")
)
:value (StringCompare
:left (Var
:v (SymbolRef 1 "s")
)
:op :Eq
:right (StringConstant
:s "world"
:type (String
:kind 1
:len (IntegerConstant
:n 5
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
)
:type (Logical
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "b")
)
:value (StringContains
:substr (StringConstant
:s "ell"
:type (String
:kind 1
:len (IntegerConstant
:n 3
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
)
:str (Var
:v (SymbolRef 1 "s")
)
:type (Logical
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "n")
)
:value (StringOrd
:arg (Var
:v (SymbolRef 1 "c")
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "c")
)
:value (StringChr
:arg (IntegerConstant
:n 65
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (String
:kind 1
:len (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:len_kind :ExpressionLength
:physical_type :DescriptorString
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "n")
)
:value (Ichar
:arg (Var
:v (SymbolRef 1 "c")
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 1 "n")
)
:value (Iachar
:arg (Var
:v (SymbolRef 1 "c")
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
)
}
)
:items []
)