DC3 Compiler - Interpreter (for developers)
Version 1.0 for All Windows Platforms
DC3 Compiler - Interpreter
DC3 is a complete but limited (because I've neither the time nor the will to enhance it) VB like compiler/interpreter that can be used for learning how to create a complete and fully functional compiler. It comes with its complete source code in Visual Basic 6.
It compiles simple VB like programs and creates a byte code executed by a Virtual Machine, like Java and .NET languages.
DC3 Compiler version 1.0

Source Code (300 Kb)

You can find some features by watching directly the BNF definition file.

it supports:
- only simple VB types like string, integer (hexadecimal, octal), float, boolean
- global and local variables
- functions and subs
- operators like +,-,*,/,\,imp,eqv,xor,or,and,not,>=,<=,>,<,<>,=,&,mod,^ with the VB6 precedence order.
- the 'if' and 'while' statements
- VB functions like 'print', 'msgbox', 'clng', 'cstr', 'inputbox', 'rnd', 'exit'
- recursion

Differences from VB6
- operators like +=,-=,*=,/=,++,--
- variable declaration with direct assignment
- operators only work with the same types (use conversions functions like clng, cstr to switch types)
- parenthesis is always required when calling functions or subs

The language

DC3 language is very similar to VB script; variables have no type and the type is implicit. It recognizes some internal functions: print, msgbox, inputbox, clng, cstr, exit, rnd
You can define variables, functions, variables in the order you want and the compiler is not case sensitive.

dim a="",b,c=&h10

You have declared a string variable 'a', a generic variable 'b' and a numeric variable 'c'.

sub message(a)
   msgbox (a)
end sub
message ("bye bye!")

this small program shows a message box with the "bye bye!" string.

function sum(a,b)
end function
msgbox (sum(10,10)+sum(20,20))

msgbox (sum("a","b"))

this program returns 60 -> 10+10+20+20 and "ab" --> "a" + "b"

dim a="hello "
msgbox (a+"world")

this sample shows "hello world" on the screen

dim a=10
msgbox (a)

this sample returns 11

sub writenum(n)
   if n>0 then
   end if
end sub

this program writes 0,1,2,3,4,5,6,7,8,9,10 to the console using recursion.

dim s
s=inputbox ("Write your name")
msgbox ("Your name is  " + s)

this program writes your name

dim a=0,c=0
while (a<10)
msgbox (c)

this program repeats a sum for 10 times returning 45 as result
Copyright 2002-23 by Lorenzi Davide. All rights reserved.
Site built with Dynamic HTML Editor