示例#1
0
        private IExpression BuildNumvalExpression(ParseTreeNode node)
        {
            if (node.ChildNodes[1].FirstChild.Term.Name == "hexval")
            {
                var node2 = node.ChildNodes[1].FirstChild;
                var hex1  = Convert.ToByte("0" + node2.FirstChild.FindTokenAndGetText(), 16);

                //if (node2.ChildNodes.Count == 1)
                //{
                //    return new NumvalExpression(hex1);
                //}
                //else
                // ?????????????????????????????????????????????????????????????

                {
                    var operation = node2.ChildNodes[1].FindTokenAndGetText();

                    if (operation == "-")
                    {
                        return(new NumvalExpression(hex1,
                                                    Convert.ToByte("0x" + node2.ChildNodes[1].LastChild.FindTokenAndGetText(), 16)));
                    }
                    else if (operation == ".")
                    {
                        var expression = new NumvalExpression();

                        var hexvalpointstart = node2.ChildNodes[1].FirstChild;

                        expression.Add(hex1);
                        foreach (var hexval1 in hexvalpointstart.ChildNodes)
                        {
                            expression.Add(Convert.ToByte("0x" + hexval1.LastChild.FindTokenAndGetText(), 16));
                        }

                        return(expression);
                    }
                    else
                    {
                        return(new NumvalExpression(hex1));
                    }
                    //else
                    //{
                    //    throw new SemanticErrorException(node, @"Unknow operation in Numval expression", operation);
                    //}
                }
            }

            throw new InvalidProgramException("Dec and Binary const not implemented");
        }
示例#2
0
文件: Builder.cs 项目: vf1/bnf2dfa
        private IExpression BuildNumvalExpression(ParseTreeNode node)
        {
            if (node.ChildNodes[1].ChildNodes[0].Term.Name == "hexval")
            {
                var node2 = node.ChildNodes[1].ChildNodes[0];
                var hex1 = Convert.ToByte("0" + node2.ChildNodes[0].FindTokenAndGetText(), 16);

                //if (node2.ChildNodes.Count == 1)
                //{
                //    return new NumvalExpression(hex1);
                //}
                //else
                // ?????????????????????????????????????????????????????????????

                {
                    var operation = node2.ChildNodes[1].FindTokenAndGetText();

                    if (operation == "-")
                    {
                        return new NumvalExpression(hex1,
                            Convert.ToByte("0x" + node2.ChildNodes[1].ChildNodes[node2.ChildNodes[1].ChildNodes.Count - 1].FindTokenAndGetText(), 16));
                    }
                    else if (operation == ".")
                    {
                        var expression = new NumvalExpression();

                        var hexvalpointstart = node2.ChildNodes[1].ChildNodes[0];

                        expression.Add(hex1);
                        foreach (var hexval1 in hexvalpointstart.ChildNodes)
                            expression.Add(Convert.ToByte("0x" + hexval1.ChildNodes[node2.ChildNodes[1].ChildNodes.Count - 1].FindTokenAndGetText(), 16));

                        return expression;
                    }
                    else
                    {
                        return new NumvalExpression(hex1);
                    }
                    //else
                    //{
                    //    throw new SemanticErrorException(node, @"Unknow operation in Numval expression", operation);
                    //}
                }
            }

            throw new InvalidProgramException("Dec and Binary const not implemented");
        }