Ejemplo n.º 1
0
 public Selection(Element elementlist)
 {
     ElementList = elementlist;
 }
Ejemplo n.º 2
0
 internal Tab(Element element)
 {
     ElementList = element;
 }
Ejemplo n.º 3
0
        internal void Push(Token token)
        {
            int wordtype;
            switch (token.ValueType)
            {
                case SyntaxType.Number:
                case SyntaxType.Boolean:
                    wordtype = (int)SyntaxType.String;
                    break;

                default:
                    wordtype = (int)token.ValueType;
                    break;
            }

            var action = _action[_stateStack[_stateStack.Count - 1]][wordtype];
            if (action == null)
            {
                IsLoopingForReduce = false;
                throw new ParseException($"Grammar error at line {token.Line}");
            }
            else if (action[0] == 'A')
            {
                IsAccepted = true;
                IsLoopingForReduce = false;
                switch (action[1])
                {
                    case '1'://ACC for elements
                        Block = new Tab(_tokenStack[_tokenStack.Count - 1] as Element);
                        break;

                    case '2'://ACC for settings
                        Block = new Setting(_tokenStack[_tokenStack.Count - 1] as Attribute);
                        break;

                    case '3'://ACC for content
                        Block = new Content(_tokenStack[_tokenStack.Count - 1].Value);
                        break;
                }
            }
            else if (action[0] == 'S')
            {
                var statestring = "";
                for (var i = 1; i < action.Length; i++)
                {
                    statestring += action[i];
                }
                var nextstate = int.Parse(statestring);
                _stateStack.Add(nextstate);
                _tokenStack.Add(token);
                IsLoopingForReduce = false;
            }
            else
            {
                IsLoopingForReduce = true;
                var reducestring = "";
                for (var i = 1; i < action.Length; i++)
                {
                    reducestring += action[i];
                }
                var reducerule = int.Parse(reducestring);
                switch (reducerule)
                {
                    //case 1:// Block -> Type Bracket Elements Bracket
                    //    break;
                    //case 2:// Block -> Settings
                    //    break;
                    //case 3:// Block -> Content
                    //    break;
                    case 4:// Elements -> Element
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][2];
                        break;

                    case 5:// Elements -> Elements Element
                        var nextele = _tokenStack[_tokenStack.Count - 1] as Element;
                        var preele = _tokenStack[_tokenStack.Count - 2] as Element;
                        nextele.Next = preele;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextele);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][2]);
                        break;

                    case 6:// Element -> Sharp Ename Equals Value Break
                        var eName = _tokenStack[_tokenStack.Count - 4].Value;
                        var eType = (ElementTypes)System.Enum.Parse(typeof(ElementTypes), eName);
                        var setele = new Element(_tokenStack[_tokenStack.Count - 5].Line, eType, _tokenStack[_tokenStack.Count - 2].Value);
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(setele);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][3]);
                        break;

                    case 7:// Element -> EName Bracket Atts Bracket
                        var elementName = _tokenStack[_tokenStack.Count - 4].Value;
                        var elementType = (ElementTypes)System.Enum.Parse(typeof(ElementTypes), elementName);
                        var atts = _tokenStack[_tokenStack.Count - 2] as Attribute;
                        var element = new Element(atts.Line, elementType, atts);
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(element);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][3]);
                        break;

                    case 8:// Settings -> Setting
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][0];
                        break;

                    case 9:// Settings -> Settings Setting
                        var nextset = _tokenStack[_tokenStack.Count - 1] as Attribute;
                        var preset = _tokenStack[_tokenStack.Count - 2] as Attribute;
                        nextset.Next = preset;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextset);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][0]);
                        break;
                    //case 10:// Content -> USD Value Break
                    //    break;
                    case 11:// Setting -> Sharp Att
                        if (_tokenStack[_tokenStack.Count - _popCount[reducerule - 1]].Value.Contains("define"))
                        {
                            (_tokenStack[_tokenStack.Count - 1] as Attribute).IsGlobal = true;
                        }
                        _tokenStack.RemoveAt(_tokenStack.Count - _popCount[reducerule - 1]);
                        _stateStack.RemoveAt(_stateStack.Count - _popCount[reducerule - 1]);
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][1];
                        break;

                    case 12:// Atts -> Att
                        _stateStack[_stateStack.Count - 1] = _goto[_stateStack[_stateStack.Count - 2]][4];
                        break;

                    case 13:// Atts -> Atts Att
                        var nextatt = _tokenStack[_tokenStack.Count - 1] as Attribute;
                        var preatt = _tokenStack[_tokenStack.Count - 2] as Attribute;
                        nextatt.Next = preatt;
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(nextatt);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][4]);
                        break;

                    case 14:// Att -> Name Equals Value Break
                        AttributeValueType valueType = AttributeValueType.String;
                        switch ((_tokenStack[_tokenStack.Count - 2] as Token).ValueType)
                        {
                            case SyntaxType.Number:
                                valueType = AttributeValueType.Number;
                                break;

                            case SyntaxType.Boolean:
                                valueType = AttributeValueType.Boolean;
                                break;
                        }
                        AttributeTypes attType = (AttributeTypes)System.Enum.Parse(typeof(AttributeTypes), _tokenStack[_tokenStack.Count - 4].Value);
                        Attribute att = new Attribute
                            (
                                _tokenStack[_tokenStack.Count - 2].Line,
                                attType,
                                _tokenStack[_tokenStack.Count - 2].Value,
                                valueType
                            );
                        _tokenStack.RemoveRange(_tokenStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _stateStack.RemoveRange(_stateStack.Count - _popCount[reducerule - 1], _popCount[reducerule - 1]);
                        _tokenStack.Add(att);
                        _stateStack.Add(_goto[_stateStack[_stateStack.Count - 1]][5]);
                        break;
                }
            }
        }