O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Toy Compiler for Arithmetic Expressions

LCG can be an endless source of fun for those who are into writing compilers (toy or otherwise). Although expression trees are the ideal abstraction for code generation nowadays (as you will see later in the “Expression Trees” section), use of raw LCG can be instructive to see the essentials of code generation starting from an object model.

In this section, we examine a very simple toy compiler for arithmetic expressions, starting from an object model for an abstract syntax tree with simple nodes such as constants, parameters, and arithmetic operators. To create a real language on top, you would have to build a lexer and a parser to turn textual input into such a tree format, which we won’t do here. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required