World’s first Forth compiler for the.NET platform Valer BOCAN, PhD.

Slides:



Advertisements
Similar presentations
INFIX, PREFIX, & POSTFIX EXPRESSIONS. Infix Notation We usually write algebraic expressions like this: a + b This is called infix notation, because the.
Advertisements

PbForth + sum ! By Josh Jennings Ratnakar Kamath.
Infix, Postfix and Stacks
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
Arithmetic Expressions
Forth Lecture L7.1. A Brief History of Programming Languages
Reverse Polish Notation (RPN) & Stacks CSC 1401: Introduction to Programming with Java Week 14 – Lecture 2 Wanda M. Kunkle.
Programming Languages From FORTRAN to WHYP. A Brief History of Programming Languages
Infix, Postfix, Prefix.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Chapter 8 . Sequence Control
Cellular Programming Air Forth 1 Ilan Kadar & Ofry Ram
A Programming Language for the FC16 Forth Core
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Lecture 18 Last Lecture Today’s Topic Instruction formats
Chapter 1 Algorithm Analysis
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Forth A stack language.
Exam 1 –Monday June 25 th –open Book / Open Notes –No Electronic Devices (calculators, laptops, etc) –Room Number: W –Time: 5:30pm to 8:00pm.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
Topic 3 The Stack ADT.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
1 CSC 222: Computer Programming II Spring 2005 Stacks and recursion  stack ADT  push, pop, peek, empty, size  ArrayList-based implementation, java.util.Stack.
Stack Applications.
1 Stacks Chapter 4 2 Introduction Consider a program to model a switching yard –Has main line and siding –Cars may be shunted, removed at any time.
SUNY Oneonta Data Structures and Algorithms Visualization Teaching materials Generation Group.
CSC 205 Programming II Postfix Expressions. Recap: Stack Stack features Orderly linear structure Access from one side only – top item Stack operations.
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
Computer Science Department Data Structure & Algorithms Problem Solving with Stack.
DATA STRUCTURE & ALGORITHMS CHAPTER 3: STACKS. 2 Objectives In this chapter, you will: Learn about stacks Examine various stack operations Discover stack.
CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)
Chapter 8 Intermediate Code Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University.
CIS 068 Welcome to CIS 068 ! Lesson 11: Data Structures 2.
Linear Data Structures LIFO – Polish notation Context Saving.
Expressions and Statements. Expressions Literals and identifiers are expressions More complex expressions are built from simple expressions by the application.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues (part 2)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t.
1 Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
Wednesday, March 2 Homework #2 is posted Homework #2 is posted Due Friday, March 4 (BOC) Due Friday, March 4 (BOC) Program #5 is posted Program #5 is posted.
CHP-3 STACKS.
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CPS Review of Data Structures l We’ve studied concrete data structures/type (CDT)  Vectors Homogeneous aggregates supporting random access  Linked.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
PHY 201 (Blum)1 Stacks Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
Review Use of Stack Introduction Stack in our life Stack Operations
Overview of Instruction Set Architectures
MEMORY REPRESENTATION OF STACKS
The Forth Language CSC 507 – Roy Ford November 22, 2005.
Stack as an ADT.
The Stack ADT. 3-2 Objectives Define a stack collection Use a stack to solve a problem Examine an array implementation of a stack.
Stacks Chapter 4.
PART II STACK APPLICATIONS
Chapter 8 Central Processing Unit
Forth A stack language.
Languages and Compilers (SProg og Oversættere)
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
(Part 2) Infix, Prefix & Postfix
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

World’s first Forth compiler for the.NET platform Valer BOCAN, PhD

 What is Forth anyway?  Reverse Polish Notation  Stack-based programming  Delta Forth.NET  Demonstration

 Procedural, stack-based language that is compiled and interpreted at the same time  Developed by Chuck Moore at the US National Radio Astronomy Observatory in the early 1970s  Procedures are called words that are grouped in vocabularies.  Forth is a meta-language, as new words can form new specialized Forth-like languages

 Popular for developing embedded systems.  Implemented on RISC processors  Open Firmware boot ROMs used by Apple, IBM, and Sun Microsystems  First stage boot controller for FreeBSD  Software that controlled the robotic arm that repaired the Hubble Space Telescope

 50-70% of a typical Forth implementation is written in… Forth  Implementation effort is small; a single developer can create a Forth system on a new platform in months  Delta Forth.NET was implemented in just 5 weeks

 What is Forth anyway?  Reverse Polish Notation  Stack-based programming  Delta Forth.NET  Demonstration

 Invented by Charles Hamblin in 1950’s to enable zero-address memory stores  In postfix notation, the operators follow their operands, i.e becomes  RPN obviates the needs for parentheses otherwise required by infix notation  Reading from left to right, calculations can occur as soon as an operator is read

* 6 42  Take infix expression (2 + 5) * (10 – 4)  This translates to postfix expression *  See how the postfix expression is evaluated using a stack-based algorithm

 What is Forth anyway?  Reverse Polish Notation  Stack-based programming  Delta Forth.NET  Demonstration

 Unusual programming style, close to machine  Forth uses two stacks:  Parameter stack, used to transmit parameters between words  Return stack, used to hold the return address of the word caller and some counter for loop functions  There are some powerful primitives to handle the stacks

 DUP – duplicates the topmost element on the stack

 DROP – drops the topmost element on the stack

 SWAP – swaps the two topmost elements on the stack

 OVER – duplicates the second topmost element on the stack

 ROT – rotates the three topmost elements on the stack

 What is Forth anyway?  Reverse Polish Notation  Stack-based programming  Delta Forth.NET  Demonstration

 Sequel of the Delta Forth for Java project (1997)  C# command-driven application  This dialect is not interpreted, the generated code is fully managed  Supports Forth at the.NET consumer level (i.e. no new.NET classes can be derived)  Supports interoperability with other.NET libraries

 Perhaps the most odd looking Hello World out there : main\ Entry point."Hello World" ; : main\ Entry point."Hello World" ;

 Finding prime numbers (up to 400 in this case) 400 constant limit : isprime\ Returns 1 if the number on top of stack is a prime number 2 begin over over mod 0= 0= rot rot dup >r over 2 / > 0= rot and r> swap while 1+ repeat over 2 / > ; : main\ Entry point."Prime numbers up to " limit..": " limit 1 do i isprime if i. space then loop ; 400 constant limit : isprime\ Returns 1 if the number on top of stack is a prime number 2 begin over over mod 0= 0= rot rot dup >r over 2 / > 0= rot and r> swap while 1+ repeat over 2 / > ; : main\ Entry point."Prime numbers up to " limit..": " limit 1 do i isprime if i. space then loop ;

 Euclid’s algorithm 4330 constant num1\ The first number 8235 constant num2\ The second number ( Word to test if value on top of stack is equal to or less than 0 ) : ZeroLessEqual dup 0= swap 0< or ; : gcd(num1 num ) over ZeroLessEqual if(num1 is <= 0) drop drop else dup ZeroLessEqual if(num2 is <= 0) drop drop else begin over over = if(We've got the result). else over over > if swap then over - 0 then until then ; : main\ Entry point."GCD of " num1.." and " num2.." is " num1 num2 gcd cr ; 4330 constant num1\ The first number 8235 constant num2\ The second number ( Word to test if value on top of stack is equal to or less than 0 ) : ZeroLessEqual dup 0= swap 0< or ; : gcd(num1 num ) over ZeroLessEqual if(num1 is <= 0) drop drop else dup ZeroLessEqual if(num2 is <= 0) drop drop else begin over over = if(We've got the result). else over over > if swap then over - 0 then until then ; : main\ Entry point."GCD of " num1.." and " num2.." is " num1 num2 gcd cr ;

 What is Forth anyway?  Reverse Polish Notation  Stack-based programming  Delta Forth.NET  Demonstration