3

I want to add support for syntax highlighting for lex and yacc-files in Visual Studio 2010. How can I do this?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
wattele
  • 61
  • 1
  • 10

2 Answers2

0

Following the given link to Syntax Coloring leads to another, more pertinent page Implementing Syntax Coloring, where it is noted

Visual Studio does not specify a parser interface, and parser implementation is completely up to you. However, a default parser implementation is provided in the Visual Studio Language Package project. For managed code, the managed package framework (MPF) provides complete support for colorizing text.

Depending on what you want:

  • trivial, coloring only the C code portions of the lex/yacc files
  • much harder, coloring the patterns so that one can make sense of them

you could in principle make a parser using just lex (yacc isn't necessary). For yacc files, that's not so hard, but for lex there's the complication of regular expressions. vi-like-emacs does that and while the interface differs in detail, conceptually it's similar. Reading the lexers might give you some ideas how to apply that approach:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
-1

There is documentation from Microsoft on integrating yacc/bison & flex/lex with Visual Studio. Although a URL only link is discouraged on SO, its best to go to the source for this kind of detailed information:

https://msdn.microsoft.com/en-us/library/aa730877(VS.80).aspx#vccustombr_topic3

It lays out all the steps necessary for integrating with the build tools. Syntax highlighting is covered elsewhere as described in Add a new language to Visual Studio 2010 with syntax highlighting and intellisense. In particular the guidance for syntax colouring can be found here: https://msdn.microsoft.com/en-us/library/bb166778(v=vs.100).aspx.

However, I'm not aware of anyone who has published extra colouring rules for the grammar specific components of flex and yacc. However, most of the body of flex and yacc files are written in C or C++ for which there are syntax highlighting rules that can be applied, and suit most peoples needs.

Community
  • 1
  • 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129