Exemple #1
0
 private void Expacc()
 {
     _currentNode.AddChild(new ParseNode(ParseEnum.ExpressionAccent));
     _currentNode = _currentNode.GetChildren()[_currentNode.GetChildren().Count - 1];
     if (_current is AddSub)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Operator, _current.GetValue()));
         if (!_lex.EndOfInput)
         {
             _current = _lex.GetNextToken();
         }
         Term();
         Expacc();
     }
     else if (_current is Equals)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Equals));
         if (!_lex.EndOfInput)
         {
             _current = _lex.GetNextToken();
         }
         Expressie();
     }
     else
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Empty));
     }
     _currentNode = _currentNode.GetParent();
 }
Exemple #2
0
        public void Init()
        {
            _testTree = new ParseNode(ParseEnum.Start);
            _testTree.AddChild(new ParseNode(ParseEnum.Expression));
            _testTree.GetChildren()[0].AddChild(new ParseNode(ParseEnum.Term));
            _testTree.GetChildren()[0].AddChild(new ParseNode(ParseEnum.ExpressionAccent));
            ParseNode node = _testTree.GetChildren()[0].GetChildren()[0];
            node.AddChild(new ParseNode(ParseEnum.Factor));
            node.AddChild(new ParseNode(ParseEnum.TermAccent));
            node.GetChildren()[0].AddChild(new ParseNode(ParseEnum.Number, "3"));
            node.GetChildren()[1].AddChild(new ParseNode(ParseEnum.Empty));

            node = _testTree.GetChildren()[0].GetChildren()[1];
            node.AddChild(new ParseNode(ParseEnum.Operator, "+"));
            node.AddChild(new ParseNode(ParseEnum.Term));
            node.AddChild(new ParseNode(ParseEnum.ExpressionAccent));
            ParseNode termNode = node.GetChildren()[1];

            termNode.AddChild(new ParseNode(ParseEnum.Factor));
            termNode.AddChild(new ParseNode(ParseEnum.TermAccent));
            termNode.GetChildren()[0].AddChild(new ParseNode(ParseEnum.Number, "4"));
            termNode.GetChildren()[1].AddChild(new ParseNode(ParseEnum.Empty));

            node.GetChildren()[2].AddChild(new ParseNode(ParseEnum.Empty));
        }
Exemple #3
0
 private void Factor()
 {
     _currentNode.AddChild(new ParseNode(ParseEnum.Factor));
     _currentNode = _currentNode.GetChildren()[_currentNode.GetChildren().Count - 1];
     if (_current is OpenParenthesis)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.OpenParenthesis));
         _current = _lex.GetNextToken();
         Expressie();
         if (_current is CloseParenthesis)
         {
             _currentNode.AddChild(new ParseNode(ParseEnum.CloseParenthesis));
             if (!_lex.EndOfInput)
             {
                 _current = _lex.GetNextToken();
             }
         }
     }
     else if (_current is Variable)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Variable, _current.GetValue()));
         if (!_lex.EndOfInput)
         {
             _current = _lex.GetNextToken();
         }
     }
     else if (_current is Number)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Number, _current.GetValue()));
         if (!_lex.EndOfInput)
         {
             _current = _lex.GetNextToken();
         }
     }
     else
     {
         Console.WriteLine("Syntaxfout.");
         Stop();
     }
     _currentNode = _currentNode.GetParent();
 }
Exemple #4
0
 private void Termacc()
 {
     _currentNode.AddChild(new ParseNode(ParseEnum.TermAccent));
     _currentNode = _currentNode.GetChildren()[_currentNode.GetChildren().Count - 1];
     if (_current is Operator)
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Operator, _current.GetValue()));
         if (!_lex.EndOfInput)
         {
             _current = _lex.GetNextToken();
         }
         Factor();
         Termacc();
     }
     else
     {
         _currentNode.AddChild(new ParseNode(ParseEnum.Empty));
     }
     _currentNode = _currentNode.GetParent();
 }