예제 #1
0
 private void LoadKeywords()
 {
     _keywords = new Dictionary <string, TokenID>(StringComparer.OrdinalIgnoreCase);
     for (int i = 1; i < 9; i++)
     {
         TokenID tokenID = (TokenID)i;
         string  key     = tokenID.ToString();
         _keywords[key] = tokenID;
     }
 }
예제 #2
0
            public override string ToString()
            {
                StringBuilder buf = new StringBuilder();

                buf.Append(RuleId.ToString());
                buf.Append(':');
                foreach (TokenID id in Tokens)
                {
                    buf.Append(' ');
                    buf.Append(id.ToString());
                }
                return(buf.ToString());
            }
예제 #3
0
	    public PredefinedTypeNode(TokenID type, Token relatedToken) 
            : base( new IdentifierExpression(type.ToString().ToLower(), relatedToken) )
		{
	        this.type = type;
		}
예제 #4
0
 public OperatorName(TokenID token, Context context)
     : base(token.ToString(), NameVisibilityRestriction.Everyone, Scope.Static, context)
 {
 }
예제 #5
0
        /// <summary>
        ///		Returns an identifier for a token from an id.
        /// </summary>
        /// <param name="id">ID to work out identifier from.</param>
        public static string IdentFromID(TokenID id)
        {
            switch (id)
            {
            case TokenID.KeywordState:
                return("state");

            case TokenID.KeywordEvent:
                return("event");

            case TokenID.KeywordDefault:
                return("default");

            case TokenID.KeywordSwitch:
                return("switch");

            case TokenID.KeywordCase:
                return("case");

            case TokenID.KeywordIf:
                return("if");

            case TokenID.KeywordElse:
                return("else");

            case TokenID.KeywordEnum:
                return("enum");

            case TokenID.KeywordConst:
                return("const");

            case TokenID.KeywordStatic:
                return("static");

            case TokenID.KeywordRef:
                return("ref");

            case TokenID.KeywordReturn:
                return("return");

            case TokenID.KeywordWhile:
                return("while");

            case TokenID.KeywordDo:
                return("do");

            case TokenID.KeywordNew:
                return("new");

            case TokenID.KeywordDelete:
                return("delete");

            case TokenID.KeywordLock:
                return("lock");

            case TokenID.KeywordObject:
                return("Object");

            case TokenID.KeywordString:
                return("string");

            case TokenID.KeywordBool:
                return("bool");

            case TokenID.KeywordByte:
                return("byte");

            case TokenID.KeywordInt:
                return("int");

            case TokenID.KeywordShort:
                return("short");

            case TokenID.KeywordFloat:
                return("float");

            case TokenID.KeywordLong:
                return("long");

            case TokenID.KeywordVoid:
                return("void");

            case TokenID.KeywordThread:
                return("thread");

            case TokenID.KeywordGoto:
                return("goto");

            case TokenID.KeywordBreak:
                return("break");

            case TokenID.KeywordContinue:
                return("continue");

            case TokenID.KeywordIndexer:
                return("indexer");

            case TokenID.KeywordGotoState:
                return("gotostate");

            case TokenID.KeywordBreakpoint:
                return("breakpoint");

            case TokenID.KeywordProperty:
                return("property");

            case TokenID.KeywordClass:
                return("class");

            case TokenID.KeywordStruct:
                return("struct");

            case TokenID.KeywordPublic:
                return("public");

            case TokenID.KeywordPrivate:
                return("private");

            case TokenID.KeywordProtected:
                return("protected");

            case TokenID.KeywordEngine:
                return("engine");

            case TokenID.KeywordEditor:
                return("editor");

            case TokenID.KeywordConsole:
                return("console");

            case TokenID.TypeIdentifier:
                return("identifier");

            case TokenID.TypeString:
                return("string literal");

            case TokenID.TypeFloat:
                return("floating-point literal");

            case TokenID.TypeDouble:
                return("double precision floating-point literal");

            case TokenID.TypeInteger:
                return("integer literal");

            case TokenID.TypeBoolean:
                return("boolean literal");

            case TokenID.TypeVoid:
                return("void");

            case TokenID.OpModulus:
                return("%");

            case TokenID.OpLogicalAnd:
                return("&&");

            case TokenID.OpLogicalOr:
                return("||");

            case TokenID.OpLogicalNot:
                return("!");

            case TokenID.OpBitwiseSHL:
                return("<<");

            case TokenID.OpBitwiseSHR:
                return(">>");

            case TokenID.OpBitwiseAnd:
                return("&");

            case TokenID.OpBitwiseOr:
                return("|");

            case TokenID.OpBitwiseXOr:
                return("^");

            case TokenID.OpBitwiseNot:
                return("~");

            case TokenID.OpMultiply:
                return("*");

            case TokenID.OpDivide:
                return("/");

            case TokenID.OpAdd:
                return("+");

            case TokenID.OpSub:
                return("-");

            case TokenID.OpLess:
                return("<");

            case TokenID.OpGreater:
                return(">");

            case TokenID.OpLessEqual:
                return("<=");

            case TokenID.OpGreaterEqual:
                return(">=");

            case TokenID.OpNotEqual:
                return("!=");

            case TokenID.OpEqual:
                return("==");

            case TokenID.OpAssign:
                return("=");

            case TokenID.OpAssignAdd:
                return("+=");

            case TokenID.OpAssignSub:
                return("-=");

            case TokenID.OpAssignMultiply:
                return("*=");

            case TokenID.OpAssignDivide:
                return("/=");

            case TokenID.OpAssignModulus:
                return("%=");

            case TokenID.OpAssignBitwiseAnd:
                return("&=");

            case TokenID.OpAssignBitwiseOr:
                return("|=");

            case TokenID.OpAssignBitwiseNot:
                return("~=");

            case TokenID.OpAssignBitwiseXOr:
                return("^=");

            case TokenID.OpAssignBitwiseSHL:
                return("=<<");

            case TokenID.OpAssignBitwiseSHR:
                return("=>>");

            case TokenID.OpMemberResolver:
                return("->");

            case TokenID.CharOpenBrace:
                return("{");

            case TokenID.CharCloseBrace:
                return("}");

            case TokenID.CharOpenBracket:
                return("[");

            case TokenID.CharCloseBracket:
                return("]");

            case TokenID.CharOpenParenthesis:
                return("(");

            case TokenID.CharCloseParenthesis:
                return(")");

            case TokenID.CharComma:
                return(",");

            case TokenID.CharColon:
                return(":");

            case TokenID.CharSemiColon:
                return(";");

            case TokenID.CharPeriod:
                return(".");

            case TokenID.CharDirective:
                return("#");

            default:
                return("*" + id.ToString());
            }
        }
예제 #6
0
 public override string ToString()
 {
     return(ID.ToString());
 }
        /// <summary>
        ///		Returns an identifier for a token from an id.
        /// </summary>
        /// <param name="id">ID to work out identifier from.</param>
        public static string IdentFromID(TokenID id)
        {
            switch (id)
            {
                case TokenID.KeywordState:
                    return "state";
                case TokenID.KeywordEvent:
                    return "event";
                case TokenID.KeywordDefault:
                    return "default";
                case TokenID.KeywordSwitch:
                    return "switch";
                case TokenID.KeywordCase:
                    return "case";
                case TokenID.KeywordIf:
                    return "if";
                case TokenID.KeywordElse:
                    return "else";
                case TokenID.KeywordEnum:
                    return "enum";
                case TokenID.KeywordConst:
                    return "const";
                case TokenID.KeywordStatic:
                    return "static";
                case TokenID.KeywordRef:
                    return "ref";
                case TokenID.KeywordReturn:
                    return "return";
                case TokenID.KeywordWhile:
                    return "while";
                case TokenID.KeywordDo:
                    return "do";
                case TokenID.KeywordNew:
                    return "new";
                case TokenID.KeywordDelete:
                    return "delete";
                case TokenID.KeywordLock:
                    return "lock";
                case TokenID.KeywordObject:
                    return "Object";
                case TokenID.KeywordString:
                    return "string";
                case TokenID.KeywordBool:
                    return "bool";
                case TokenID.KeywordByte:
                    return "byte";
                case TokenID.KeywordInt:
                    return "int";
                case TokenID.KeywordShort:
                    return "short";
                case TokenID.KeywordFloat:
                    return "float";
                case TokenID.KeywordLong:
                    return "long";
                case TokenID.KeywordVoid:
                    return "void";
                case TokenID.KeywordThread:
                    return "thread";
                case TokenID.KeywordGoto:
                    return "goto";
                case TokenID.KeywordBreak:
                    return "break";
                case TokenID.KeywordContinue:
                    return "continue";
                case TokenID.KeywordIndexer:
                    return "indexer";
                case TokenID.KeywordGotoState:
                    return "gotostate";
                case TokenID.KeywordBreakpoint:
                    return "breakpoint";
                case TokenID.KeywordProperty:
                    return "property";
                case TokenID.KeywordClass:
                    return "class";
                case TokenID.KeywordStruct:
                    return "struct";
                case TokenID.KeywordPublic:
                    return "public";
                case TokenID.KeywordPrivate:
                    return "private";
                case TokenID.KeywordProtected:
                    return "protected";
                case TokenID.KeywordEngine:
                    return "engine";
                case TokenID.KeywordEditor:
                    return "editor";
                case TokenID.KeywordConsole:
                    return "console";

                case TokenID.TypeIdentifier:
                    return "identifier";
                case TokenID.TypeString:
                    return "string literal";
                case TokenID.TypeFloat:
                    return "floating-point literal";
                case TokenID.TypeDouble:
                    return "double precision floating-point literal";
                case TokenID.TypeInteger:
                    return "integer literal";
                case TokenID.TypeBoolean:
                    return "boolean literal";
                case TokenID.TypeVoid:
                    return "void";

                case TokenID.OpModulus:
                    return "%";

                case TokenID.OpLogicalAnd:
                    return "&&";
                case TokenID.OpLogicalOr:
                    return "||";
                case TokenID.OpLogicalNot:
                    return "!";

                case TokenID.OpBitwiseSHL:
                    return "<<";
                case TokenID.OpBitwiseSHR:
                    return ">>";
                case TokenID.OpBitwiseAnd:
                    return "&";
                case TokenID.OpBitwiseOr:
                    return "|";
                case TokenID.OpBitwiseXOr:
                    return "^";
                case TokenID.OpBitwiseNot:
                    return "~";

                case TokenID.OpMultiply:
                    return "*";
                case TokenID.OpDivide:
                    return "/";
                case TokenID.OpAdd:
                    return "+";
                case TokenID.OpSub:
                    return "-";

                case TokenID.OpLess:
                    return "<";
                case TokenID.OpGreater:
                    return ">";
                case TokenID.OpLessEqual:
                    return "<=";
                case TokenID.OpGreaterEqual:
                    return ">=";
                case TokenID.OpNotEqual:
                    return "!=";
                case TokenID.OpEqual:
                    return "==";

                case TokenID.OpAssign:
                    return "=";
                case TokenID.OpAssignAdd:
                    return "+=";
                case TokenID.OpAssignSub:
                    return "-=";
                case TokenID.OpAssignMultiply:
                    return "*=";
                case TokenID.OpAssignDivide:
                    return "/=";
                case TokenID.OpAssignModulus:
                    return "%=";
                case TokenID.OpAssignBitwiseAnd:
                    return "&=";
                case TokenID.OpAssignBitwiseOr:
                    return "|=";
                case TokenID.OpAssignBitwiseNot:
                    return "~=";
                case TokenID.OpAssignBitwiseXOr:
                    return "^=";
                case TokenID.OpAssignBitwiseSHL:
                    return "=<<";
                case TokenID.OpAssignBitwiseSHR:
                    return "=>>";

                case TokenID.OpMemberResolver:
                    return "->";

                case TokenID.CharOpenBrace:
                    return "{";
                case TokenID.CharCloseBrace:
                    return "}";
                case TokenID.CharOpenBracket:
                    return "[";
                case TokenID.CharCloseBracket:
                    return "]";
                case TokenID.CharOpenParenthesis:
                    return "(";
                case TokenID.CharCloseParenthesis:
                    return ")";
                case TokenID.CharComma:
                    return ",";
                case TokenID.CharColon:
                    return ":";
                case TokenID.CharSemiColon:
                    return ";";
                case TokenID.CharPeriod:
                    return ".";
                case TokenID.CharDirective:
                    return "#";

                default:
                    return "*"+id.ToString();
            }
        }
예제 #8
0
 public OperatorName(TokenID token, Context context)
     : base(token.ToString(), NameVisibilityRestriction.Everyone, Scope.Static, context)
 {
 }
 public PredefinedTypeNode(TokenID type, Token relatedToken)
     : base(new IdentifierExpression(type.ToString().ToLower(), relatedToken))
 {
     this.type = type;
 }
예제 #10
0
 public static bool IsKeyWord(TokenID tokId)
 {
     return keywords.ContainsKey(tokId.ToString().ToLower());
 }
예제 #11
0
        /// <summary>
        /// Gets the textual representation of a class of tokens.
        /// </summary>
        /// <param name="tokenID">The family's ID</param>
        /// <returns>A string</returns>
        public static string ToString(TokenID tokenID)
        {
            switch (tokenID)
            {
            case TokenID.Comma:
                return(",");

            case TokenID.Dot:
                return(".");

            case TokenID.SemiColon:
                return(";");

            case TokenID.Colon:
                return(":");

            case TokenID.DoubleColon:
                return("::");

            case TokenID.Question:
                return("?");

            case TokenID.DoubleQuestion:
                return("??");

            case TokenID.LeftParenthesis:
                return("(");

            case TokenID.RightParenthesis:
                return(")");

            case TokenID.LeftBracket:
                return("[");

            case TokenID.RightBracket:
                return("]");

            case TokenID.LeftBrace:
                return("{");

            case TokenID.RightBrace:
                return("}");

            case TokenID.Equal:
                return("=");

            case TokenID.DoubleEqual:
                return("==");

            case TokenID.TripleEqual:
                return("===");

            case TokenID.Exclamation:
                return("!");

            case TokenID.ExclamationEqual:
                return("!=");

            case TokenID.ExclamationDoubleEqual:
                return("!==");

            case TokenID.LessThan:
                return("<");

            case TokenID.LessThanEqual:
                return("<=");

            case TokenID.GreaterThan:
                return(">");

            case TokenID.GreaterThanEqual:
                return(">=");

            case TokenID.Plus:
                return("+");

            case TokenID.DoublePlus:
                return("++");

            case TokenID.PlusEqual:
                return("+=");

            case TokenID.Minus:
                return("-");

            case TokenID.DoubleMinus:
                return("--");

            case TokenID.MinusEqual:
                return("-=");

            case TokenID.Asterisk:
                return("*");

            case TokenID.AsteriskEqual:
                return("*=");

            case TokenID.DoubleAsterisk:
                return("**");

            case TokenID.DoubleAsteriskEqual:
                return("**=");

            case TokenID.Slash:
                return("/");

            case TokenID.SlashEqual:
                return("/=");

            case TokenID.Percent:
                return("%");

            case TokenID.PercentEqual:
                return("%=");

            case TokenID.Tilda:
                return("~");

            case TokenID.Ampersand:
                return("&");

            case TokenID.DoubleAmpersand:
                return("&&");

            case TokenID.AmpersandEqual:
                return("&=");

            case TokenID.VerticalBar:
                return("|");

            case TokenID.DoubleVerticalBar:
                return("||");

            case TokenID.VerticalBarEqual:
                return("|=");

            case TokenID.Circumflex:
                return("^");

            case TokenID.CircumflexEqual:
                return("^=");

            case TokenID.Arrow:
                return("=>");

            case TokenID.DoubleLessThan:
                return("<<");

            case TokenID.DoubleLessThanEqual:
                return("<<=");

            case TokenID.DoubleGreaterThan:
                return(">>");

            case TokenID.DoubleGreaterThanEqual:
                return(">>=");

            case TokenID.Identifier:
            case TokenID.TypeName:
            case TokenID.Scope:
            case TokenID.Modifier:
            case TokenID.LineComment:
            case TokenID.BlockComment:
            case TokenID.EndOfFile:
                return("[" + tokenID + "]");

            case TokenID.LT_Boolean:
            case TokenID.LT_Integer:
            case TokenID.LT_Long:
            case TokenID.LT_Float:
            case TokenID.LT_Decimal:
            case TokenID.LT_String:
            case TokenID.LT_Date:
                return("[" + tokenID.ToString().Substring(3) + "]");

            default:
                return(tokenID.ToString().Substring(3).ToLower());
            }
        }
예제 #12
0
 override public string ToString()
 {
     return((tokenID.ToString(), token).ToString());
 }