2005/5/10

     
 

CfgScript Literal Expressions

artefaktur

| Literals | Assigment | Operator | Instanceof | Delegates | Lambda |

Literals are hard coded values of basic or component types.


Content of this chapter:

   LiteralExpression
     BoolLiteral
     IntegerLiteral
     FloatLiteral
     NilLiteral
     StringLiteral
     CharLiteral
   Samples




 LiteralExpression

LiteralExpression
:  IntegerLiteral
|  BoolLiteral
|  FloatLiteral
|  NilLiteral
|  StringLiteral
|  CharLiteral
|  ArrayLiteral
|  PropsLiteral
;

 BoolLiteral

BoolLiteral
: 'true'
| 'false'
;


 IntegerLiteral

IntegerLiteral
: '0x'(0-F)+ 
| 0(0-7)+ 
| (0-9)+ [IntegerLiteralTypeSuffix]
;

IntegerLiteralTypeSuffix
: 'b' 
| 'B' 
| 's' 
| 'S' 
| 'i'
| 'I' 
| 'l' 
| 'L'
;

 FloatLiteral

FloatLiteral
: (0-9)+ '.' (0-9)+[ 'e' (0-9)+] [d|D|f|F]
;

 NilLiteral

NilLiteral
: 'Nil'
| 'nil'
| 'null'
;
A Nil literal represends an uninitialized (via new) Object variable.


acdk.lang.Object obj;
obj == Nil;
obj = new String("");
obj != Nil;
obj = Nil; // free reference to object
obj == Nil;


 StringLiteral

String literals in CfgScript followings the rules of String in C/C++ with following exceptions:
  • Automatic String concanating is not supported yet.
  • String literals can be in multiple lines. The resulting string contains the new lines


s1 = "Hello\nWorld";
s2 = "Hello
World";
s1.equals(s2) == true;
CfgScript supports also unicode characters using \uxxxx escape sequence.
The xxxx is a hexdecimal number identifying the character.
Please refer also to http charts.

A sample converting ü ä ö to upper case:

String s = "ue=\u00fc; ae=\u00e4; oe=\u00f6"; // 
String us = s.toUpperCase();
out.println("lc: " + s + "; uc: " + us + "; = " + "UE=\u00dc; AE=\u00c4; OE=\u00d6");

The standard C escape codes ("\n\t\r\b") are also supported.

With the  BacktickOperator it is possible to expand variable inline in the string, similar to perl, tcl or sh.

 CharLiteral

Single Character are quoted with single '.

char c1 = 'c';
char c2 = '\0';
char c3 = 'A';

Unicode characters are supported using \uxxxx escape sequence.

UnicodeCharacter.toUpperCase('\u00e4') == '\u00c4'

 Samples