private object GetEqualsValue(Token pToken)
        {
            object result = null;

            if (pToken is NonterminalToken)
            {
                NonterminalToken NT = (NonterminalToken)pToken;

                //<RecodeValue> ::= <Literal> | Boolean | Identifier

                string dataTypeIdentifier = NT.Rule.Rhs[0].ToString();

                switch (dataTypeIdentifier)
                {
                case "<Literal>":
                    result = this.GetCommandElement(NT.Tokens, 0).Replace("\"", "").Trim();
                    break;

                case "DecLiteral":
                    result = this.GetCommandElement(NT.Tokens, 0).Replace("\"", "").Trim();
                    break;

                default:
                    result = this.ExtractTokens(NT.Tokens).Replace("\"", "").Trim();
                    break;
                }
            }
            else
            {
                TerminalToken TT = (TerminalToken)pToken;
                result = TT.ToString();
            }

            return(result);
        }
        private object GetRecodeValue(Token token)
        {
            object result = null;

            if (token is NonterminalToken)
            {
                NonterminalToken nonterm = (NonterminalToken)token;
                string           os      = Environment.OSVersion.VersionString;

                //<RecodeValue> ::= <Literal> | Boolean | Identifier

                string name       = nonterm.Tokens[0].ToString();
                string symbolName = nonterm.Symbol.Name;

                switch (symbolName)
                {
                case "Real_Number":
                case "Decimal_Number":
                    string commandElementString = this.GetCommandElement(nonterm.Tokens, 0).Replace("\"", "").Trim();
                    double commandElementDouble = double.NaN;
                    System.Double.TryParse(commandElementString, out commandElementDouble);
                    if (commandElementDouble != double.NaN)
                    {
                        result = commandElementDouble;
                    }
                    break;

                case "Literal_Date":
                    result = DateTime.Parse(name);
                    break;

                case "Literal_String":
                case "RecodeValue":
                case "Recoded_Value":
                    result = this.GetCommandElement(nonterm.Tokens, 0).Replace("\"", "").Trim();
                    break;
                }
            }
            else
            {
                TerminalToken TT = (TerminalToken)token;
                result = TT.ToString();
            }

            return(result);
        }
        public Rule_Graph(Rule_Context pContext, NonterminalToken pToken) : base(pContext)
        {
            _commandText = this.ExtractTokens(pToken.Tokens);

            string caseSymbol = string.Empty;

            foreach (Token token in pToken.Tokens)
            {
                if (token is NonterminalToken)
                {
                    NonterminalToken nonterminalToken = (NonterminalToken)token;

                    caseSymbol = nonterminalToken.Symbol.ToString();

                    switch (caseSymbol)
                    {
                    case "<Graph_Type>":
                        _graphType = nonterminalToken.Tokens[0].ToString();
                        break;

                    case "<Graph_Interval>":
                        string intervalText = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString();
                        intervalText = intervalText.Trim(new char[] { '"' });
                        string[] intervalArray = intervalText.Split(' ');
                        _graphInterval      = intervalArray[0];
                        _graphIntervalUnits = intervalArray[1];
                        break;

                    case "<Graph_StartFrom>":
                        _graphStartFrom = this.GetCommandElement(nonterminalToken.Tokens, 2);
                        break;

                    case "<Graph_Variable>":
                        _independentVariableList = nonterminalToken.Tokens[0].ToString().Trim(new char[] { '[', ']' });
                        break;

                    case "<Graph_Variable_List>":
                        this.SetIdentifierList(nonterminalToken);
                        break;

                    case "<Graph_CrossTab>":
                        _graphCrossTab = nonterminalToken.Tokens[0].ToString().Trim(new char[] { '[', ']' });
                        break;

                    case "<Graph_Option_List>":
                        this.SetOptionList(nonterminalToken);
                        break;

                    case "<Graph_Title>":
                        _graphTitle = this.GetCommandElement(nonterminalToken.Tokens, 2);
                        break;

                    case "<Graph_XAxisLabel>":
                        _graphXAxisLabel = this.GetCommandElement(nonterminalToken.Tokens, 2);
                        break;

                    case "<Graph_YAxisLabel>":
                        _graphYAxisLabel = this.GetCommandElement(nonterminalToken.Tokens, 2);
                        break;

                    case "<Graph_StrataVar>":
                        _strataVar = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString();
                        break;

                    case "<Graph_DateFormat>":
                        _graphDateFormat = (((NonterminalToken)nonterminalToken).Tokens[2]).ToString();
                        break;

                    case "<Graph_WeightVar>":
                        object tokenObject = (((NonterminalToken)nonterminalToken).Tokens[2]);

                        if (tokenObject is TerminalToken)
                        {
                            _weightVar = ((TerminalToken)tokenObject).Text.Trim(new char[] { '[', ']' });
                        }
                        else
                        {
                            _aggregateFunction = this.GetCommandElement(((NonterminalToken)tokenObject).Tokens, 0);

                            Token tok = null;

                            if (((NonterminalToken)tokenObject).Tokens.Length == 1)
                            {
                                tok = ((NonterminalToken)tokenObject).Tokens[0];

                                if (_aggregateFunction.ToUpperInvariant() == "PERCENT()")
                                {
                                    _aggregateFunction = _aggregateFunction.TrimEnd(new char[] { '(', ')' });
                                    _weightVar         = _independentVariableList.Trim(new char[] { ',' });
                                    break;
                                }
                            }
                            else
                            {
                                tok = ((NonterminalToken)tokenObject).Tokens[2];
                                tok = ((NonterminalToken)(tok)).Tokens[0];
                            }

                            _weightVar = ((TerminalToken)(tok)).Text;
                            _weightVar = _weightVar.Trim(new char[] { '[', ']' });
                        }
                        break;
                    }
                }
                else
                {
                    TerminalToken terminalToken = (TerminalToken)token;
                    switch (terminalToken.Symbol.ToString())
                    {
                    case "Identifier":
                        _independentVariableList = terminalToken.ToString().Trim(new char[] { '[', ']' });
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
 public override string ToString()
 {
     return(this.GetType().FullName + ": " +
            Localization.SyntaxErrorDescriptionFormat(token.ToString()));
 }