Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Writing Your First Visual Studio Language Service

, 11 Dec 2009
A guide to writing a language service for Visual Studio using Irony.
CSLanguage_Service.zip
bottles-v11-long.mycs
CSLanguageService
CSLanguageService.csproj.user
Integration
Key.snk
Properties
Resources
Package.ico
Irony
Compiler
AST
Grammar
LALR
NLALR
Scanner
Terminals
TokenFilters
EditorServices
Key.snk
Microsoft
MS-PubLicense.Rtf
Properties
Runtime
IronyLanguageServicePackage.zip
Integration
Key.snk
MyTemplate.vstemplate
Properties
Resources
Irony.dll
Irony.GrammarExplorer.exe
__TemplateIcon.ico
IronyLanguageServiceTemplate.zip
IronyLanguageServicePackage.zip
IronyLanguageServiceWizard.dll
Wizard.dll
MyCLanguageService.zip
MyCLanguageService
MyCLanguageService
bin
Debug
Irony.dll
Irony.GrammarExplorer.exe
MyCLanguageService.dll
MyCLanguageService.pkgdef
Integration
Key.snk
MyCLanguageService.csproj.user
Properties
Resources
Irony.dll
Irony.GrammarExplorer.exe
Test Files
short.myc
thing.myc
#region License
/* **********************************************************************************
 * Copyright (c) Roman Ivantsov
 * This source code is subject to terms and conditions of the MIT License
 * for Irony. A copy of the license can be found in the License.txt file
 * at the root of this distribution. 
 * By using this source code in any fashion, you are agreeing to be bound by the terms of the 
 * MIT License.
 * You must not remove this notice from this software.
 * **********************************************************************************/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Runtime;

namespace Irony.Compiler.AST {
  public class BinExprNode : AstNode {
    public AstNode Left;
    public string Op;
    public AstNode Right;
    CallDispatcher _dispatcher;


    public BinExprNode(NodeArgs args, AstNode left, string op, AstNode right) : base(args) {
      ChildNodes.Clear();
      Left = left;
      AddChild("Arg", Left);
      Op = op; 
      Right = right;
      AddChild("Arg", Right);
      //Flags |= AstNodeFlags.TypeBasedDispatch;
    }
    public BinExprNode(NodeArgs args) 
      : this(args, args.ChildNodes[0], args.ChildNodes[1].GetContent(), args.ChildNodes[2]) {  }

    public override void OnCodeAnalysis(CodeAnalysisArgs args) {
      switch (args.Phase) {
        case CodeAnalysisPhase.Binding:
          _dispatcher = args.Context.Runtime.GetDispatcher(Op);
          if (_dispatcher == null)
            args.Context.ReportError(this.Location, "Operator " + Op + " not defined.");
          break;
      }//switch
      base.OnCodeAnalysis(args);
    }

    protected override void DoEvaluate(EvaluationContext context) {
      try {
        Left.Evaluate(context);
        object arg1 = context.CurrentResult;
        Right.Evaluate(context);
        context.Arg2 = context.CurrentResult;
        context.Arg1 = arg1;
        _dispatcher.Evaluate(context);
      } catch (RuntimeException e) {
        e.Location = this.Location;
        throw; 
      }
    }

    public override string ToString() {
      return Op + " (binary operation)";
    }
    protected override void XmlSetAttributes(System.Xml.XmlElement thisElement) {
      base.XmlSetAttributes(thisElement);
      thisElement.SetAttribute("Operation", this.Op); 
    }
  }//class
}//namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ben Morrison
Software Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 11 Dec 2009
Article Copyright 2009 by Ben Morrison
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid