Unformatted text preview:

Joel Christner jec2160 COMS W4115 Spring 2009 Minimalistic Basic Compiler MBC Project Final Report Rev 1 0 5 14 2009 Table of Contents Table of Contents 2 Introduction 4 Language Status and Open Defects 4 Language Status 4 Open Defects 4 Language Tutorial 4 Language Goals 4 Language Features 5 How to Use MBC 5 Mathematics Example 5 Iteration For Loop Example 5 Iteration While Loop Example 6 Decision If Then Else Example 6 Language Reference Manual 6 Language Overview 6 Styles Used 7 Lexical Conventions and Program Structure 7 Program Termination 7 Whitespace 7 Program Structure 7 Comments 7 Tokens 7 Identifiers 7 Keywords 8 Numerical Literals 8 Miscellaneous 8 Operations 8 Multiplicative Operators 8 Additive Operators 8 Relational Operators 9 Assignment Operators 9 Iteration Statements and Program Control 9 While Loops 9 For Loops 9 If Then Statements 9 End Statements 10 Display Operations 10 Exceptions 10 Project Plan 10 Processes 10 Programming Style 11 Planned Project Timeline 11 Roles and Responsibilities 11 Software Development Environment and Tools 11 Project Log 12 Architectural Design 12 Block Diagram of Major Components 12 Interfaces Between Components 13 Component Ownership 14 Test Plan 14 Example Source Programs and Target Languages 14 Translator Test Suites 15 Test Case Reasoning 15 Automation 15 Component Ownership 15 Lessons Learned 15 Most Important Learnings 15 Advice for Future Teams 16 Appendix 16 Complete Code Listing 16 scanner mll 16 parser mly 17 ast mli 18 mbc ml 18 makefile 21 End of Document 22 Introduction This document is the final project report for the Minimalistic Basic Compiler MBC project as completed by Joel Christner UNI jec2160 for COMS W4115 Spring 2009 semester Professor Stephen Edwards MBC was designed to provide people with a compiler that would take simple BASIC like source code and compile it into C source code MBC does not implement all of the BASIC language and restrictions exist on how the BASIC programs must be implemented which will be discussed in this document Language Status and Open Defects This section provides a status on the language and a list of open defects Language Status MBC is largely implemented but has a handful of open defects The open defects were unable to be resolved by the time the project needed to be submitted Open Defects The following are the open defects in MBC at time of submission ID 1 Description Standalone mathematical expressions are not printed with a trailing semicolon in the resultant C code Behavior not problematic for expressions in for while and if statements but is problematic for standalone mathematical expressions Requires parser AST and backend modification 2 No differentiation between assignment and comparison in use of equals operator Only a single equals is used rather than a double equals Requires parser AST and backend modification 3 Incorrect expressions are being accepted by the parser i e 20 A and keywords are being allowed as identifiers Numerical literals are being accepted as expressions Requires parser AST and backend modification 4 Errors not being thrown when problem encountered to allow the user to understand what line of code is causing a problem Rather a Parser error is generated Backend modification required to correct to include try and raise statements to support exceptions Fatal error exception Parsing Parse error 5 REM statements are currently not functioning as expected Requires parser AST and backend modification Language Tutorial This section provides a high level overview of MBC and how to use it Language Goals The goal of MBC was to provide a simple tool that allowed simplistic BASIC programs to be compiled to C With the introduction of DOS and eventually Windows operating systems BASIC in its original form lost mindshare rapidly Although dated BASIC provides a solid programming foundation for those who are looking to learn a simple language that is not overwhelming or daunting in any way MBC helps bridge the gap between learning BASIC and learning a more advanced language such as C Language Features MBC supports integer data types All BASIC statements must be contained within a single line and can not span lines MBC supports certain BASIC program control loop and iteration statements including END FOR NEXT IF THEN ELSE and WHILE How to Use MBC MBC is easy to use Once compiled simply run MBC from a command line and pass a BASIC source code file to it as input For instance mbc source bas The following examples show you how MBC works with various types of programs Note that portions of text have been removed to keep the examples simple Mathematics Example File basicmath bas a 10 b a 2 c b 2 d c 4 print d Compiler output mbc examples math bas include stdlib h include stdio h int int int int a b c d void main a 10 b a 2 c b 2 d c 4 printf a Iteration For Loop Example File forloop bas for a 1 to 10 print a next for b 1 to 5 print b next Compiler output mbc examples forloop bas include stdlib h include stdio h int a int b void main for a 1 i 10 i printf a for b 1 i 5 i printf b Iteration While Loop Example File whileloop bas while a 10 do a a 1 loop while b 100 do b b 20 loop Compiler output mbc examples whileloop bas include stdlib h include stdio h int a int b void main while a 10 a a 1 while b 100 b b 20 Decision If Then Else Example File ifthen bas a 50 if a 100 then print a else print 100 if a 100 then print a else print 100 if a 50 then print a Compiler output mbc examples ifthen bas include stdlib h include stdio h int a void main a if if if 50 a 100 printf a else printf 100 a 100 printf a else printf 100 a 50 printf a Language Reference Manual This section includes the language reference manual LRM The LRM presented here has been updated from the LRM that was provided earlier in the semester and reflects the current state of MBC as a language Language Overview Minimalistic BASIC Compiler MBC provides a simple means of compiling small BASIC programs and supports many of the commonly used commands and features of the BASIC language MBC will output C compatible code which the user can then compile with a C compiler and execute Styles Used This document uses three primary styles to visualize concepts Standard document text as shown in this paragraph is in the Cambria font 12 point Text that shows an example of a line of MBC code is shown in Courier New 9 point Text contained within an example of a line of MBC code that should be considered a container for user


View Full Document

Columbia COMS W4115 - Minimalistic Basic Compiler (MBC)

Documents in this Course
YOLT

YOLT

13 pages

Lattakia

Lattakia

15 pages

EasyQL

EasyQL

14 pages

Photogram

Photogram

163 pages

Espresso

Espresso

27 pages

NumLang

NumLang

6 pages

EMPATH

EMPATH

14 pages

La Mesa

La Mesa

9 pages

JTemplate

JTemplate

238 pages

MATVEC

MATVEC

4 pages

TONEDEF

TONEDEF

14 pages

SASSi

SASSi

16 pages

JTemplate

JTemplate

39 pages

BATS

BATS

10 pages

Synapse

Synapse

11 pages

c.def

c.def

116 pages

TweaXML

TweaXML

108 pages

Load more
Loading Unlocking...
Login

Join to view Minimalistic Basic Compiler (MBC) and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Minimalistic Basic Compiler (MBC) and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?