1 / 12

ASCL – Another Simple Calculator Language

ASCL – Another Simple Calculator Language. Ryan Blace Spring 2007. Outline. Review of requirements Quick introduction to ASCL Features and examples Design and implementation details References that were used in development Conclusion. Review of Requirements. Floating point calculations

gigi
Download Presentation

ASCL – Another Simple Calculator Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASCL – Another Simple Calculator Language Ryan Blace Spring 2007

  2. Outline • Review of requirements • Quick introduction to ASCL • Features and examples • Design and implementation details • References that were used in development • Conclusion

  3. Review of Requirements • Floating point calculations • Mathematical ad boolean expressions • Number storage and recall • Input and output of numbers and strings

  4. Quick Intro to ASCL Global variable declarations int $globalInt; string $globalString; Function declarations void #foo() { int $localInt = 5; $globalInt = $localInt; } Entry point entry() { string $text = “hi”; #foo(); if($globalInt == 5) { print($text); } }

  5. Quick Intro to ASCL

  6. Datatypes : boolean, integer, double, string Variables Global and local Local overriding allowed Scoping by function and block Simple methods Support recursion Each method has its own local variables No parameters or return vals  If-then and If-then-else While() {} loops Input and output functions Operators Equality/inequality/comparison Boolean and, or, xor, not Positive and negative unary qualifiers All common arithmetic operators Trigonometric functions Square root, exponents Logarithms Factorial ASCL Features

  7. More code

  8. Design and Implementation • Language parser that builds an abstract syntax tree • Tree parser that implements the language and executes the program • Abstract Value class • Extend Value to make IntValue, DoubleValue, StringValue, BooleanValue • Operators are functions on the class • Polymorphism handles routing method calls for specific data types • Methods, flow control, and looping all enabled using tree node indexes and seek() function on the TreeNodeStream object in the ANTLR tree grammar

  9. Design and Implementation • Global variables stored in hash map • Function id’s and code block tree node indexes stored in hash map • Manage a stack of “Function Contexts” • Each time we enter a new function, push • Each time we exit a function, pop • Function context contains a stack of “Block Contexts” • Same as before • Variable references are resolved by traversing the block context stack of the current function context from top to bottom. If none found, check the global variable hash.

  10. Helpful References • Definitive ANTLR Reference • If you need to work with ANTLR again, buy the online book. It was only $30 or so... Totally worth it. • www.antlr.org • Contains a lot of useful info if you dig deep enough • Antlr-interest email list • www.antlr.org:8080/pipermail/antlr-interest • Tons of good discussions on the new features of ANTLR 3.0

  11. Conclusions… ASCL is a very simple and quick to learn language It takes very little programming to do very complex things It provides a programmer with everything needed to build a calculator like the MS application (except the UI stuff) Future work… Methods with parameters and return types Function overloading Structs and maybe classes For loops Exception handling (yikes!) Conclusion and Future Work

More Related