functional Programming help!! 
Author Message
 functional Programming help!!

I am new to SML, using mosml and i have an exercise which is driving me up
the wall as i have no idea how to make any progress. the idea is to
implement a small programming language (scooby) using SML. there are only 6
types of statements in the language:
1-Variable declaration
2-Assignment statement
3-Unconditional go to
4-Conditional go to
5-Write statement
6-stop statement
an example i wrote to test my nonexistant programme looks like this:
             1 int n = 5
             2 write n
             3 int fac = 1
             4 if0 n goto 8
             5 fac := fac * n
             6 n := n - 1
             7 goto 4
             8 write fac
             9 Stop
the lexical analysis and the compiling have been done for me, i now have to
define a function, 'run' which will complete the scooby language.
any help would be greatfully received, thanks.


Fri, 19 Aug 2005 10:16:40 GMT  
 functional Programming help!!

Quote:

> I am new to SML, using mosml and i have an exercise which is driving me up
> the wall as i have no idea how to make any progress. the idea is to
> implement a small programming language (scooby) using SML. there are only 6
> types of statements in the language:
> 1-Variable declaration
> 2-Assignment statement
> 3-Unconditional go to
> 4-Conditional go to
> 5-Write statement
> 6-stop statement
> an example i wrote to test my nonexistant programme looks like this:
>              1 int n = 5
>              2 write n
>              3 int fac = 1
>              4 if0 n goto 8
>              5 fac := fac * n
>              6 n := n - 1
>              7 goto 4
>              8 write fac
>              9 Stop
> the lexical analysis and the compiling have been done for me, i now have to
> define a function, 'run' which will complete the scooby language.

I assume you mean "lexical analysis and parsing", so what you have is
a data-structure representing the program.

For writing the 'run' function, you should think about this:

 1) How do I represent the run-time state of the program?  For a
    starter, what exactly _is_ the run-time state of the program?

 2) What is the initial state of the program.

 3) How does each type of statement read and modify this state?

Once you have these in place, the rest should be trivial.

        Torben



Fri, 19 Aug 2005 22:05:56 GMT  
 functional Programming help!!

Quote:

> the lexical analysis and the compiling have been done for me, i now have to
> define a function, 'run' which will complete the scooby language.
> any help would be greatfully received, thanks.

Pattern matching over the datatype constructors used in the abstract
syntax tree, probably.  Then just fill in the blanks.

Otherwise go talk to your instructor/teaching assistant/whatever they are
called at your academic institution.

-Peter

A theory has only the alternatives of being wrong or right. A model has a
third possibility: It may be right but irrelevant.
 --Manfred Eigen



Sun, 21 Aug 2005 04:11:07 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Functional programming help! (Haskell)

2. functional.py 0.6 - Functional Programming in Python

3. functional.py 0.7 - Functional programming in Python

4. functional.py - functional programming in Python

5. functional.py 0.7 - Functional programming in Python

6. functional.py 0.6 - Functional Programming in Python

7. functional.py - functional programming in Python

8. Need help learning functional programming

9. Functional programming terms [was: Help with leaks]

10. HELP: functional programming!

11. HELP: functional programming in scm

12. US PhD programs strong on functional programming?

 

 
Powered by phpBB® Forum Software