public override void EndNode(ParserContext context)
        {
            switch (context.NodeKind)
            {
                case SyntaxNodeKind.UnaryOperator:
                    result.Add(FormatResult("unaryop", context.Span));
                    break;
                case SyntaxNodeKind.Operator:
                    result.Add(FormatResult("op", context.Span));
                    break;
                case SyntaxNodeKind.Constant:
                    result.Add(FormatResult("num", context.Span));
                    break;
                case SyntaxNodeKind.ExpressionIdentifier:
                    result.Add(FormatResult("identifier", context.Span));
                    break;
                case SyntaxNodeKind.ExpressionLeftParenthesis:
                    result.Add("(");
                    break;
                case SyntaxNodeKind.ExpressionRightParenthesis:
                    result.Add(")");
                    break;

            }
        }
 public override void EndNode(ParserContext context)
 {
     switch (context.NodeKind)
     {
         case SyntaxNodeKind.LineNumber:
             EndLineNumber(context);
             break;
         case SyntaxNodeKind.Mnemonic:
             EndMnemonic(context);
             break;
         case SyntaxNodeKind.Instruction:
             EndInstruction(context);
             break;
         case SyntaxNodeKind.Label:
             EndLabel(context);
             break;
         case SyntaxNodeKind.AbsoluteOperand:
             operand = FormatResult("absolute", context.Span);
             break;
         case SyntaxNodeKind.ImpliedOperand:
             operand = "implied";
             break;
         case SyntaxNodeKind.AccumulatorOperand:
             operand = "accumulator";
             break;
         case SyntaxNodeKind.IndirectOperand:
             operand = FormatResult("indirect", context.Span);
             break;
         case SyntaxNodeKind.ImmediateOperand:
             operand = FormatResult("immediate", context.Span);
             break;
         case SyntaxNodeKind.OperandIndexer:
             indexer = FormatResult("indexer", context.Span);
             break;
         case SyntaxNodeKind.Macro:
             result.Add(FormatResult("macro", macroName));
             break;
         case SyntaxNodeKind.DirectiveOperands:
             directive.AppendFormat(", {0}", context.Span.Text);
             break;
         case SyntaxNodeKind.Literal:
             directive.AppendFormat(", {0}", context.Span.Text);
             break;
         case SyntaxNodeKind.MacroName:
             macroName = context.Span.Text;
             break;
         case SyntaxNodeKind.Directive:
             directive.Append(">");
             result.Add(directive.ToString());
             break;
         case SyntaxNodeKind.DirectiveName:
             directive.Append(context.Span.Text);
             break;
     }
 }
 public override void EndNode(ParserContext context)
 {
     if (context.Span.Start + regionOfInterestSpan.Start.Position <=  regionOfInterestSpan.End.Position)
     {
         IClassificationType type;
         if (classificationTypes.TryGetValue(context.NodeKind, out type))
         {
             classifications.Add(new ClassificationSpan(
                 new SnapshotSpan(regionOfInterestSpan.Snapshot, context.Span.Start + regionOfInterestSpan.Start, context.Span.Length), type));
         }
     }
 }
 public override void EndNode(ParserContext context)
 {
     switch (context.NodeKind)
     {
         case SyntaxNodeKind.LineNumber:
             EndLineNumber(context);
             break;
         case SyntaxNodeKind.Mnemonic:
             EndMnemonic(context);
             break;
     }
 }
        private void EndMnemonic(ParserContext context)
        {
            if (context.Span.End >= cursorPosition)
            {
                if (context.Span.Length == 0)
                    suggestion = instructions.First();

                var enteredMnemonic = context.Span.Text.Substring(0,
                    (context.Span.Length >= 3) ? 3 : context.Span.Length);

                suggestion = instructions.FirstOrDefault(i => i.StartsWith(enteredMnemonic));
            }
        }
 public override void StartNode(ParserContext context)
 {
     switch (context.NodeKind)
     {
         case SyntaxNodeKind.Line:
             instruction.Clear();
             directive.Clear();
             indexer = null;
             break;
         case SyntaxNodeKind.Directive:
             directive.Append("directive<");
             break;
     }
 }
        public override void StartNode(ParserContext context)
        {
            expressionResolver.StartNode(context);

            switch (context.NodeKind)
            {
                case SyntaxNodeKind.Line:
                    lineNumber++;
                    indexer = null;
                    directiveName = null;
                    labelName = null;
                    mnemonic = null;
                    break;
                case SyntaxNodeKind.Instruction:
                    if (labelName != null)
                    {
                        AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count));
                        labelName = null;
                    }
                    break;
            }
        }
        public override void EndNode(ParserContext context)
        {
            expressionResolver.EndNode(context);

            switch (context.NodeKind)
            {
                case SyntaxNodeKind.Label:
                    labelName = context.Span.Text;
                    break;

                case SyntaxNodeKind.MacroName:
                    currentMacroName = context.Span.Text;
                    break;

                case SyntaxNodeKind.Macro:
                    currentMacro = new Macro(currentMacroName);
                    break;

                case SyntaxNodeKind.DirectiveName:
                    directiveName = context.Span.Text;
                    if (labelName != null && directiveName != "=")
                    {
                        AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count));
                        labelName = null;
                    }
                    break;

                case SyntaxNodeKind.Directive:
                    ProcessDriective();
                    break;

                case SyntaxNodeKind.Instruction:
                    ProcessInstruction();
                    break;

                case SyntaxNodeKind.ImpliedOperand:
                    operandKind = OperandKind.Implied;
                    break;

                case SyntaxNodeKind.AbsoluteOperand:
                    ProcessAbsoluteOperand();
                    break;

                case SyntaxNodeKind.ImmediateOperand:
                    operandValue = (byte) expressionResolver.Evaluate();
                    operandKind = OperandKind.Immediate;
                    break;

                case SyntaxNodeKind.IndirectOperand:
                    ProcessIndirectOperand();
                    break;

                case SyntaxNodeKind.OperandIndexer:
                    ProcessOperandIndexer(context.Span.Text);
                    break;

                case SyntaxNodeKind.Mnemonic:
                    mnemonic = context.Span.Text;
                    break;

                case SyntaxNodeKind.DirectiveOperands:
                    directiveOperands.Enqueue(expressionResolver.Evaluate());
                    break;

                case SyntaxNodeKind.Literal:
                    foreach (var b in AtasciiEncoding.Instance.GetBytes(context.Span.Text))
                    {
                        directiveOperands.Enqueue(b);
                    }
                    break;

                case SyntaxNodeKind.Line:
                    if (labelName != null)
                    {
                        AddLabel(new Label(labelName, currentChunkStartAddress + opcodes.Count));
                        labelName = null;
                    }
                    break;

            }
        }
 private void EndLineNumber(ParserContext context)
 {
     if (context.Span.End <= cursorPosition)
         suggestion = instructions.First();
 }
Beispiel #10
0
 private void EndLabel(ParserContext context)
 {
     result.Add(FormatResult("label", context.Span));
 }
Beispiel #11
0
 private void CallHandler(ParserContext context, Action<ParserHandler, ParserContext> handlerMethod)
 {
     if (handler != null)
     {
         handlerMethod(handler, context);
     }
 }
 public override void StartNode(ParserContext context)
 {
     switch (context.NodeKind)
     {
         case SyntaxNodeKind.Expression:
             operatorStack.Push(new ExpressionOperation(ExpressionOperationKind.Expression));
             break;
         case SyntaxNodeKind.Line:
             lineNumber++;
             break;
     }
 }
        public override void EndNode(ParserContext context)
        {
            switch (context.NodeKind)
            {
                case SyntaxNodeKind.Expression:
                    while (operatorStack.Count > 0)
                    {
                        var op = operatorStack.Pop();
                        if (op.Kind == ExpressionOperationKind.Expression)
                            break;
                        outputQueue.Enqueue(op);
                    }
                    break;
                case SyntaxNodeKind.UnaryOperator:
                    var unaryOp = new ExpressionOperation(ConvertUnaryToOperationKind(context.Span));
                    EnqueOperation(unaryOp);
                    break;
                case SyntaxNodeKind.Operator:
                    var op1 = new ExpressionOperation(ConvertToOperationKind(context.Span));
                    EnqueOperation(op1);
                    break;
                case SyntaxNodeKind.Constant:
                    outputQueue.Enqueue(
                        new ExpressionOperation(ExpressionOperationKind.Number, ToNumber(context.Span.Text)));
                    break;
                case SyntaxNodeKind.ExpressionIdentifier:
                    Label label;
                    var labelName = context.Span.Text;
                    var found = labelStore.TryGetLabel(labelName, out label);

                    var topOperatorKind = operatorStack.Peek().Kind;

                    switch (topOperatorKind)
                    {
                        case ExpressionOperationKind.Def:
                            labelStore.AddReferencedLabel(labelName, lineNumber);
                            operatorStack.Pop();
                            outputQueue.Enqueue(new ExpressionOperation(ExpressionOperationKind.Number, found ? 1 : 0));
                            break;
                        case ExpressionOperationKind.Ref:
                            operatorStack.Pop();
                            ISet<int> referencingLines;
                            
                            bool anyReference = labelStore.TryGetReferencingLines(labelName, out referencingLines);
                            int refOperatorResult = (anyReference &&
                                                (referencingLines.Count != 1 || !referencingLines.Contains(lineNumber)))
                                ? 1
                                : 0;
                            outputQueue.Enqueue(new ExpressionOperation(ExpressionOperationKind.Number, refOperatorResult));
                            break;
                        default:
                            labelStore.AddReferencedLabel(labelName, lineNumber);
                            outputQueue.Enqueue(
                                found
                                    ? new ExpressionOperation(ExpressionOperationKind.Number, label.Value)
                                    : new ExpressionOperation(ExpressionOperationKind.Number, 0));
                            break;
                    }
                    break;
            }
        }
Beispiel #14
0
 private void EndMnemonic(ParserContext context)
 {
     instruction.Append(FormatResult("mnemonic", context.Span));
 }
Beispiel #15
0
 private void EndLineNumber(ParserContext context)
 {
     result.Add(FormatResult("line", context.Span));
 }
Beispiel #16
0
 public virtual void StartNode(ParserContext context) { }
Beispiel #17
0
 public virtual void EndNode(ParserContext context) { }
Beispiel #18
0
 private void EndInstruction(ParserContext context)
 {
     result.Add(indexer == null
         ? string.Format("instruction<{0}, {1}>", instruction, operand)
         : string.Format("instruction<{0}, {1}, {2}>", instruction, operand, indexer));
 }