Share via


VB and C# grammar for VS2010

Here is language grammar for Visual Basic 10 and for C# 4.0. These are the versions of the languages which shipped with Visual Studio 2010.

Visual Basic 10

vb10.html

 

C# 4.0

csharp4.html

Please click on the pictures and explore!

You can save a copy of the html files to your computer. But please link or bookmark this page (rather than the html files directly), since their URLs will change when I update them.

 

How to use these grammars

  • C#: A quick 5-minute video tour of the C# grammar [awaiting processing]
  • VB: A quick 5-minute video tour of the VB grammar
     
  • These grammars make a fun way to learn the languages. You can look for particular keywords, say, and see how they're used.
     
  • If you want to learn the languages inside-out and top-to-bottom, you can find every way that a given keyword is used -- such as the new dynamic keyword in C#4, or the new ArrayLiteralExpression in VB10.
     
  • As language-designers, we used these hyperlinked grammars to discover how to add new syntax to the languages without introducing ambiguity, and to generate comprehensive test suites.

 

Machine-readable grammar for VB and C#

  • Download: grammar.zip [154k]
     
  • This download contains the VB10 and C#4 grammars in ANTLR format, and also in standard EBNF format (ISO-14977). These are both easily machine-readable.
     
  • It also contains source code for a command-line program which reads these formats, performs simple analysis on them, and generates the hyperlinked HTML format. You might adapt this tool if you want to perform your own analyses, or if you want to write your own language and make a hyperlinked grammar for it. Run the program at the command-line, e.g. "VBGrammarAnalyzer.exe csharp4.g", to read the antlr.g format of the csharp4 grammar, analyze it, and produce csharp4.ebnf and csharp4.html.
     
  • The analysis program is open-source, under the MS-PL Microsoft Public License.
     
  • Caveat: although the grammars are written in Antlr format, that doesn’t imply that Antlr can generate a parser for them! They’re way too complex for poor Antlr, and for lex/yacc. The goal here was to present the grammars exactly as written in the language-specifications: not to write a new parser. (that said, I suspect that a GLR parser could handle these grammars).

 

If you have questions about these grammars or about the analysis tool, please post them as comments here.

Comments

  • Anonymous
    June 24, 2010
    "404 - File or directory not found." Could you upload again this files?

  • Anonymous
    July 02, 2010
    Hi. Sorry about that. I've re-uploaded them correctly.

  • Anonymous
    October 18, 2011
    In fact, it doesn't work with Antlr.

  • Anonymous
    November 14, 2011
    Thank yoU :)

  • Anonymous
    February 10, 2012
    Lucien, left you a comment over at the video:  msdn.microsoft.com/.../ff635852. g.

  • Anonymous
    October 01, 2014
    ANTLR 3 or 4 would not handle these grammars since they are not well written grammars.  For one thing there is only parser rule in the grammar.  All of the rest are lexer rules.  Secondly, many (most? Almost all?) of these rules are mutually left recursive.   I suspect that the author does not understand ANTLR and how it works.  There have been visual basic and c# grammars written for ANTLR that can handle those languages just fine.  Is this grammar too complex for ANTLR to handle? No.  Is it incorrect and therefore ANTLR wont handle it? Yes.   This is not an attack on the author (Hello Lucian!).  Its merely an observation.  I came across this while researching a language construct I am modeling in an ANTLR grammar.  I felt compelled to put my 2 cents in.

  • Anonymous
    April 28, 2018
    142214 3693Hi there! Fantastic stuff, please do tell me when you finally post something like that! 406762