Forth Lecture L7.1. A Brief History of Programming Languages

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
PbForth + sum ! By Josh Jennings Ratnakar Kamath.
World’s first Forth compiler for the.NET platform Valer BOCAN, PhD.
History of Microprocessors and Microcontrollers Lecture 1.1.
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
Return Stack Lecture 8.4 A VHDL Forth Core for FPGAs: Sect. 5.
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
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell WHYP -- An Extensible Language Chapter 4.
The FC16 Forth Core Lab 7 Module F4.1. Lab 7 Hex OpcodeNameFunction 0000NOP No operation 0001DUP Duplicate T and push data stack. N
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Cellular Programming Air Forth 1 Ilan Kadar & Ofry Ram
Return Stack Lecture L7.3. A 32 x 16 Stack Same as used in the Data Stack in Lab 7.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
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.
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell Subroutine and Stacks Chapter 2.
Class 4: Stacks. cis 335 Fall 2001 Barry Cohen What is a stack? n A stack is an ordered sequence of items, of which only the last (‘top’) item can be.
Other WC16 Instructions Lecture L7.4. OpcodeNameFunctionNumber of Clock Cycles Fetch the byte at address T in RAM and load it into T1 Fetch.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Forth A stack language.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
Stack Applications.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
CIS 068 Welcome to CIS 068 ! Lesson 11: Data Structures 2.
Linear Data Structures LIFO – Polish notation Context Saving.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
PZ07A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07A - Expressions Programming Language Design and Implementation.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 2)
Algorithms: Branching and Iteration (in Scratch)
Chapter 4: Elementary Number Theory and Methods of Proof 4.8 Application: Algorithms 1 Begin at the beginning…and go on till you come to the end: then.
1 Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CHP-3 STACKS.
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
5.3 EVALUATION OF POSTFIX EXPRESSION For example, consider the evaluation of the following postfix expression using stacks: abc+d*f/- where, a=6, b=3,
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Lecture - 6(Stacks) On Data structures. Prepared by, Jesmin Akhter, Lecturer, IIT,JU Lecture Outline What is a Stack? Array implementation of stacks Operations.
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Review Use of Stack Introduction Stack in our life Stack Operations
Operators And Expressions
MEMORY REPRESENTATION OF STACKS
The Forth Language CSC 507 – Roy Ford November 22, 2005.
Stack as an ADT.
STACK IMPLEMENTATION Adam M.B..
Programming Fundamentals
More about Numerical Computation
Compiling Control Statements
Forth A stack language.
Intro to Programming CURIE 2011.
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chap 7. Advanced Control Statements in Java
OPERATORS in C Programming
Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Return Stack Lab 8.
REPETITION Why Repetition?
OPERATORS in C Programming
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:

Forth Lecture L7.1

A Brief History of Programming Languages

How would you have a computer evaluate this expression? X = A*B + (C – D)/(E + F) Reverse Polish Notation (RPN) Postfix AB*CD-EF+/+

Forth

WHYP Pronounced “whip” “Words to Help You Program” Subroutine-threaded Forth for Embedded Systems –68HC11 (16-bit) –68332 (32-bit) –68HC12 (16-bit)

WHYP is developed from scratch in the book: Design of Embedded Systems Using 68HC12/11 Microcontrollers by Richard E. Haskell Prentice Hall, 2000

FORTH is a programming language that --- was invented by Charles Moore in the early 70’s is extensible keeps all definitions in a dictionary is extremely compact is recursive can be programmed in RAM, PROM, or ROM is structured uses a stack and postfix notation

Chuck Moore reading Haskell’s WHYP book

WHYP Colon Definitions : squared( n -- n**2) DUP * ; : cubed( n -- n**3) DUP\ n n squared \ n n**2 * ;\ n**3

Branching and Looping in WHYP IF…ELSE…THEN FOR…NEXT BEGIN…AGAIN BEGIN…UNTIL BEGIN…WHILE…REPEAT

IF…ELSE…THEN IF ELSE THEN is either TRUE (-1) or FALSE (0)

WHYP Conditional Words <( n1 n2 -- f )(“less-than”) >( n1 n2 -- f )(“greater-than”) =( n1 n2 -- f )(“equals”) <>( n1 n2 -- f )(“not-equals”) <=( n1 n2 -- f )(“less-than or equal”) >=( n1 n2 -- f )(“greater-than or equal”) 0<( n -- f)(“zero-less”) 0>( n -- f)(“zero-greater”) 0=( n -- f)(“zero-equal”) U<( u1 u2 -- f )(“U-less-than”) U>( u1 u2 -- f )(“U-greater-than”) U<=( u1 u2 -- f )(“U-less-than or equal”) U>=( u1 u2 -- f )(“U-greater-than or equal”)

Do different things depending what is in T : checkT( n -- ) DUP 1 =\ n f IF\ n DO1\ ELSE\ n DUP 2 =\ n f IF\ n DO2 ELSE\ n DUP 3 =\ n f IF\ n DO3 ELSE\ n DO4 THEN\ THEN THEN ;

>R Decrement top of return stack and branch back to if not equal to zero. Therefore, are executed n times. FOR…NEXT Loop n FOR NEXT drjne

BEGIN…AGAIN BEGIN AGAIN

BEGIN…UNTIL BEGIN UNTIL is either TRUE or FALSE usually from some WHYP conditional word

: GET.BTN ( -- n ) BEGIN 0= UNTIL BEGIN UNTIL CHECKT AGAIN ;

BEGIN…WHILE…REPEAT BEGIN WHILE REPEAT

x = 1 i = 2 DO WHILE i <= n x = x * i i = i + 1 ENDDO factorial = x : factorial ( n -- n! ) 1 2 ROT \ x i n BEGIN \ x i n 2DUP <= \ x i n f WHILE \ x i n -ROT TUCK \ n i x i * SWAP \ n x i 1+ ROT \ x i n REPEAT \ x i n 2DROP ; \ x Factorial