
-----------------------------------
Ratinho
Mon Jun 07, 2010 5:03 pm

&quot;Prototype&quot; of functions
-----------------------------------
What is it you are trying to achieve?
I want to call 2 functions: one from each other


What is the problem you are having?
The compiler doesnt "know" the function if it defined lower then the place i try to call it, and i cant defined two function mixed:S
its like one of the reason for function`s prototype in c/c/++


Describe what you have tried to solve this problem
i tried export and things like that...


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Plz dont suggest me other solutions...im trying to build compiler, and i need that to implement my grammer...



function term () : boolean
    var retVal : boolean
    retVal := false
    put : outF, ""
    if (integerConstant () or stringConstant () or keywordConstant ()) then
        nextTok ()
    elsif (varName ()) then
        nextTok ()
        if (cur_tok = '
Notice to the relationship between term() and expression()
Please specify what version of Turing you are using
the newest



Thank you very much guys :)

-----------------------------------
TerranceN
Mon Jun 07, 2010 5:20 pm

RE:&quot;Prototype&quot; of functions
-----------------------------------
You can do this using the forward and body keywords like this:

forward proc foo()

proc bar()
    foo()
end bar

bar()

body proc foo()
    put "Win!!!"
end foo

-----------------------------------
Cezna
Tue Jun 08, 2010 5:39 am

RE:&quot;Prototype&quot; of functions
-----------------------------------
If you are OK using procedures (at least for one of the things), then use forward procedure for the declaration at the top, and body procedure for the actual procedure.

I don't think there's any way to do this with functions.

By the way, TerranceN, how do you have everything in the code formatted right.
Did you just do it manually by tagging everything a certain way?

-----------------------------------
TerranceN
Tue Jun 08, 2010 6:21 am

Re: &quot;Prototype&quot; of functions
-----------------------------------
I know you can do this with functions, I have done it before. I'm on Ubuntu (linux, no Turing) at the moment so forgive me if my syntax is wrong:


forward fcn GimmeAWin() : string

proc Main()
    put GimmieAWin()
end Main

Main()

body fcn GimmeAWin() : string
    result "Win!!!"
end GimmeAWin


As for the formatting use syntax tags

% your code here
[/code]

-----------------------------------
Cezna
Tue Jun 08, 2010 10:50 am

RE:&quot;Prototype&quot; of functions
-----------------------------------
Ok, so you can do it with functions.
So Ratinho, all you have to do is put this at the top:

forward function function_name


and this at the function


body function function_name

end function_name


The forward function line acts as the declaration statement, so as long as this is above any calls to the function, there shouldn't be any problems.


-----------------------------------
Ratinho
Sun Jun 20, 2010 2:12 pm

RE:&quot;Prototype&quot; of functions
-----------------------------------
hey guys tnx!
it was great solution (the forward and body :))
i used it in the day after u post it, sry that i reply only now =]
u r really useful guys!

-----------------------------------
Cezna
Sun Jun 20, 2010 6:58 pm

RE:&quot;Prototype&quot; of functions
-----------------------------------
Maybe useful enough for +bits or +karma?
:)

-----------------------------------
Monduman11
Sun Jun 20, 2010 7:24 pm

Re: RE:&quot;Prototype&quot; of functions
-----------------------------------
Maybe useful enough for +bits or +karma?
:)
lol quick question what are bits and karma used for anyways?

-----------------------------------
TerranceN
Sun Jun 20, 2010 7:39 pm

RE:&quot;Prototype&quot; of functions
-----------------------------------
umm... Feeling badass?

I don't think its used for anything.

-----------------------------------
USEC_OFFICER
Sun Jun 20, 2010 7:42 pm

RE:&quot;Prototype&quot; of functions
-----------------------------------
It used for giving to people as a way of saying 'Great job' or 'You're awsome' or something like that.

-----------------------------------
Cezna
Sun Jun 20, 2010 7:45 pm

Re: &quot;Prototype&quot; of functions
-----------------------------------
Go [url=http://compsci.ca/v3/viewtopic.php?t=3974]here to read about bits.
Karma is just to show how helpful/unhelpful a person is in general.
