Quote from: ms on February 09, 2005, 06:19:22 PM
In hla the following are legal:
str1: string := "abc" "de";
str2: string := @date;
str3: string := @time;
but not:
str4: string := @date @time;
I think that last initialization should be also legal.
Also, how can I get a string initialized with the date and time of compilation ?
Regards
str3 : string := @date + @time;
or, more likely,
str4 :string := @date + " " + @time;
Juxtaposition (concatenation without an operator) is a short-cut for string literal constants only. This is provided (as in the C language) to deal with issues like limited source code line lengths (on your display or printout) and other similar issues. But juxtapostion is *not* the standard way to concantenate two arbitrary compile-time string variables. The concatenation operator ("+") serves that purpose.
Cheers,
Randy Hyde
Quote from: ms on February 09, 2005, 09:58:52 PM
str4 :string := @date + " " + @time;
is exactly what I was looking (I suppose that should be in some part of the manuals, but I could'nt
find it).
I thought that since @date and @time are compile time functions and were replaced at compile time by the result strings, the juxtaposition was ok.
Thanks, regards
There is a subtle difference between "replaced at compile time by the result strings" and having the strings fed back into the scanner to be reprocessed. The "concatenation" of two juxtaposed string literals is handled by the HLA lexer (written in Flex), not by the parser. The parser never actually sees something like
"Hello " "World"
All the parser sees is "Hello World", as the lexer has already combined the two. Compile-time functions, OTOH, are processed by the parser, long after the lexer would have combined string literals.
There is *one* case where you can get results that seem to disobey the "only string literals" rule: when using TEXT constants. Consider the following:
const
str1 : text := " ""Hello "" ";
str2 : text := " ""World"" ";
str3 : text := str1 str2; // Note: no "+" operator.
This actually works, because (again) the lexer immediately expands all text constants on the spot, and refeeds the result back into the lexer, so that the lexer sees the following:
str3 :text := "Hello " "World" ;
Note that this trick only works for TEXT constants and, possibly, macros as they are expanded and fed back into the lexer. All other string values are processed by the parser, so you can't use this trick.
Cheers,
Randy Hyde