Inheritance: IBfsExpNode
Beispiel #1
0
        private void ConvertExpNodes( BfsExpGroup group, PegNode node )
        {
            HashSet<EBinaryFileSchemaParser> groupnodes = new HashSet<EBinaryFileSchemaParser>(
                new EBinaryFileSchemaParser[] { EBinaryFileSchemaParser.logical, EBinaryFileSchemaParser.bitwise,
                    EBinaryFileSchemaParser.comp, EBinaryFileSchemaParser.shift, EBinaryFileSchemaParser.sum, EBinaryFileSchemaParser.prod });

            for (PegNode startnode = node.child_; startnode != null; startnode = startnode.next_)
            {
                //If the node is an operator: logical, bitwise, comparisson, bitshift, sum or product
                if (groupnodes.Contains(GetNodeId(startnode)))
                {
                    //Recursively generate subgroups
                    BfsExpGroup subgroup = new BfsExpGroup();
                    subgroup.SourceRange = GetSourceRange(startnode);
                    ConvertExpNodes(subgroup, startnode);
                    group.Members.Add(subgroup);
                }
                else
                {
                    switch (GetNodeId(startnode))
                    {
                        case EBinaryFileSchemaParser.number:
                            BfsNumberExp number = new BfsNumberExp();
                            StoreSourceRange(startnode, number);
                            number.Value = long.Parse( GetNodeText(startnode), CultureInfo.InvariantCulture );
                            group.Members.Add( number );
                            break;
                        case EBinaryFileSchemaParser.named_value:
                            BfsUnresolvedVariableExp var = new BfsUnresolvedVariableExp();
                            StoreSourceRange(startnode, var);
                            for (PegNode v = startnode.child_; v != null; v = v.next_)
                                var.NameHierarchy.Add(GetNodeText(v));
                            group.Members.Add(var);
                            break;
                        case EBinaryFileSchemaParser.call:
                            BfsCallExp call = new BfsCallExp();
                            call.SourceRange = GetSourceRange(startnode);
                            call.FunctionName = GetNodeText(startnode.child_);
                            call.NameSourceRange = GetSourceRange(startnode.child_);
                            call.FunctionArgument = GetNodeText(startnode.child_.next_);
                            call.ArgumentSourceRange = GetSourceRange(startnode.child_.next_);
                            group.Members.Add(call);
                            break;
                        //Operators
                        default:
                            BfsOperator op = new BfsOperator();
                            StoreSourceRange(startnode, op);
                            op.Operator = GetNodeText(startnode);
                            group.Members.Add(op);
                            break;
                    }
                }
            }
        }
Beispiel #2
0
 private void CheckOperator(BfsExpGroup group, BfsOperator op)
 {
     //Just a formality check if the operators in the same group actually do belong to the same operator precedence-group
     if (group.OperatorPrecedenceLevel == BfsExpGroupOperatorLevel.Undetermined)
         group.OperatorPrecedenceLevel = op.PrecendenceLevel;
     else if (group.OperatorPrecedenceLevel != op.PrecendenceLevel)
         BfsCompiler.ReportError(op.SourceRange,"Mixed operator-precedence groups! '"
             + op + "' doesn't belong in '"+group.OperatorPrecedenceLevel+"'");
 }