Mercurial > projects > dil
changeset 84:ac8d961d10d1
- Added code for parsing This-,Super-,Null-,Bool-,Dollar-,CharLiteral- and StringLiteralExpression.
author | aziz |
---|---|
date | Thu, 05 Jul 2007 10:35:04 +0000 |
parents | 9e6d66f647c9 |
children | d8dc3171440d |
files | trunk/src/Expressions.d trunk/src/Parser.d trunk/src/Token.d |
diffstat | 3 files changed, 130 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Expressions.d Wed Jul 04 23:00:01 2007 +0000 +++ b/trunk/src/Expressions.d Thu Jul 05 10:35:04 2007 +0000 @@ -329,11 +329,6 @@ { super(e); } } -class PrimaryExpression -{ - -} - class IndexExpression : UnaryExpression { Expression[] args; @@ -355,6 +350,67 @@ } } +/* +class PrimaryExpression +{ + +} +*/ + +class GlobalIdExpression : Expression +{ + string identifier; + this(string identifier) + { + this.identifier = identifier; + } +} + +class ThisExpression : Expression +{ + this() + {} +} + +class SuperExpression : Expression +{ + this() + {} +} + +class NullExpression : Expression +{ + this() + {} +} + +class DollarExpression : Expression +{ + this() + {} +} + +class BoolExpression : Expression +{ + bool value; + this(bool value) + { this.value = value; } +} + +class CharLiteralExpression : Expression +{ + TOK tok; + this(TOK tok) + { this.tok = tok; } +} + +class StringLiteralExpression : Expression +{ + string str; + this(string str) + { this.str = str; } +} + class AssertExpression {
--- a/trunk/src/Parser.d Wed Jul 04 23:00:01 2007 +0000 +++ b/trunk/src/Parser.d Thu Jul 05 10:35:04 2007 +0000 @@ -388,7 +388,74 @@ switch (lx.token.type) { case T.Identifier: - + break; + case T.Dot: + nT(); +// if (lx.token.type != T.Identifier) +// error(); + e = new GlobalIdExpression(lx.token.srcText); + break; + case T.This: + nT(); + e = new ThisExpression(); + break; + case T.Super: + nT(); + e = new SuperExpression(); + break; + case T.Null: + nT(); + e = new NullExpression(); + break; + case T.True, T.False: + nT(); + e = new BoolExpression(lx.token.type == T.True ? true : false); + break; + case T.Dollar: + nT(); + e = new DollarExpression(); + break; + case T.Int32/*, ...*/: // Number literals + break; + case T.CharLiteral, T.WCharLiteral, T.DCharLiteral: + nT(); + e = new CharLiteralExpression(lx.token.type); + break; + case T.String: + char[] buffer = lx.token.str; + nT(); + while (lx.token.type == T.String) + { + string tmp = lx.token.str; + if (tmp.length > 1) + { + buffer[$-1] = tmp[0]; // replace '\0' + buffer ~= tmp[1..$]; // append the rest + } + nT(); + } + e = new StringLiteralExpression(buffer); + break; + case T.LBracket: + break; + case T.LBrace: + break; + case T.Function, T.Delegate: + break; + case T.Assert: + break; + case T.Mixin: + break; + case T.Import: + break; + case T.Typeid: + break; + case T.Is: + break; + case T.LParen: + break; + default: + // BasicType . Identifier } return e; }