Visual Basic

Mixing in Assembly Language

One of the easiest ways to build in Assembler is to build in C, because C allows you to write in Assembler using an _asm directive. This directive tells the compiler that it's about to see Assembler, so it doesn't do anything with your code. The reason for this is that the C compiler's natural output is Assembler; this is then assembled, during the last pass of the compiler, into machine code. Most C compilers work like this, so it's very easy for any C compiler to support the inclusion of Assembler. The really great thing about doing your Assembler work in C is that you can provide all the boilerplate code using straight C (which saves you from having to fathom and then write all the necessary prologue and epilogue code for the call and parameter resolution stuff). You can then tell the compiler to generate Assembler from C. This process allows you to rough out the bare bones in C and then fine tune the code in the Assembler generated by the compiler. It's also a great way to learn about Assembler programming.

Other Languages

I opened this chapter talking about COBOL, so I guess I'd better briefly describe how you get to it from within Visual B++. The first step is to find a COBOL compiler that can create DLL code-Micro Focus' COBOL Workbench version 4 will do nicely (version 3.4 is the latest 16-bit version). The rest of the steps are pretty obvious. (See Q103226 in the Microsoft Knowledge Base for more information.) You're going to call into the DLL to get at your heritage code. Why rewrite when you can re-position?

Maybe you have a bunch of scientific routines to write and your language of choice for these is FORTRAN (DIGITAL Visual Fortran 5.0 is a good choice here-MLP is especially easy with Visual Fortran 5.0 as it's based on Microsoft's Developer Studio).

Building your own little language

I'm getting off the topic a bit so I'll be brief here. Specialized, so_called "little languages" (actually some aren't so little) can be easily created using tools such as lex and yacc. (These tools can be used to build type 2 (context-free) languages as classified by the Chomsky language hierarchy). These tools came from the UNIX world originally but are now widely available for other operating systems, including Windows and DOS. The tool lex builds lexical analyzers and yacc (which stands for Yet Another Compiler Compiler) builds parsers. For example, lex can build a program that can break down code like x = a * b * c() / 3 into identifiable chunks, and yacc can build a program that can check that the chunks make syntactic sense, in the order identified by lex (which is as they're written above). As well as syntax checking your code, yacc normally generates output code to perform whatever it is that your grammar has just described, in this case math.

Note that yacc can generate any kind of code-it can output C, C++, Assembler, COBOL, or Visual B++. So by using lex and yacc you can create grammars and language compilers to perform specialized tasks. If you want to learn more about these tools see the Mortice Kern Systems Inc. Web site at