Author |
Message |
Ratinho
|
Posted: Mon Jun 07, 2010 5:03 pm Post subject: "Prototype" 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...
Turing: |
function term () : boolean
var retVal : boolean
retVal := false
put : outF, "<term>"
if (integerConstant () or stringConstant () or keywordConstant ()) then
nextTok ()
elsif (varName ()) then
nextTok ()
if (cur_tok = '[') then
nextTok ()
if (expression ()) then
nextTok ()
if (cur_tok = ']') then
nextTok ()
retVal := true
end if
end if
end if
elsif (subroutineCall ()) then
retVal := true
elsif (cur_tok = '(') then
nextTok ()
if (expression ()) then
nextTok ()
if (cur_tok = ')') then
nextTok ()
retVal := true
end if
end if
elsif (unaryOp ()) then
nextTok ()
if (term ()) then
nextTok ()
retVal := true
end if
else
retVal := false
end if
put : outF, "</term>"
result retVal
end term
function expression () : boolean
put : outF, "<expression>"
if ( ~term ()) then
result false
end if
loop
exit when ( ~ (op () and term ()))
end loop
put : outF, "</expression>"
result true
end expression
|
Notice to the relationship between term() and expression()
Please specify what version of Turing you are using
the newest
Thank you very much guys ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TerranceN
|
Posted: Mon Jun 07, 2010 5:20 pm Post subject: RE:"Prototype" of functions |
|
|
You can do this using the forward and body keywords like this:
Turing: | forward proc foo()
proc bar()
foo()
end bar
bar()
body proc foo()
put "Win!!!"
end foo |
|
|
|
|
|
![](images/spacer.gif) |
Cezna
![](http://compsci.ca/v3/uploads/user_avatars/9406831824c097251d4bb4.gif)
|
Posted: Tue Jun 08, 2010 5:39 am Post subject: RE:"Prototype" 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? |
|
|
|
|
![](images/spacer.gif) |
TerranceN
|
Posted: Tue Jun 08, 2010 6:21 am Post subject: Re: "Prototype" 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:
Turing: |
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
code: | [syntax="Turing"]
% your code here
[/syntax] |
|
|
|
|
|
![](images/spacer.gif) |
Cezna
![](http://compsci.ca/v3/uploads/user_avatars/9406831824c097251d4bb4.gif)
|
Posted: Tue Jun 08, 2010 10:50 am Post subject: RE:"Prototype" of functions |
|
|
Ok, so you can do it with functions.
So Ratinho, all you have to do is put this at the top:
Turing: |
forward function function_name
|
and this at the function
Turing: |
body function function_name
<function code here>
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.
|
|
|
|
|
![](images/spacer.gif) |
Ratinho
|
Posted: Sun Jun 20, 2010 2:12 pm Post subject: RE:"Prototype" 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! |
|
|
|
|
![](images/spacer.gif) |
Cezna
![](http://compsci.ca/v3/uploads/user_avatars/9406831824c097251d4bb4.gif)
|
Posted: Sun Jun 20, 2010 6:58 pm Post subject: RE:"Prototype" of functions |
|
|
Maybe useful enough for +bits or +karma?
![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Monduman11
![](http://compsci.ca/v3/uploads/user_avatars/1960741284bee0b481d3b8.jpg)
|
Posted: Sun Jun 20, 2010 7:24 pm Post subject: Re: RE:"Prototype" of functions |
|
|
Cezna @ Sun Jun 20, 2010 6:58 pm wrote: Maybe useful enough for +bits or +karma?
![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif)
lol quick question what are bits and karma used for anyways? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TerranceN
|
Posted: Sun Jun 20, 2010 7:39 pm Post subject: RE:"Prototype" of functions |
|
|
umm... Feeling badass?
I don't think its used for anything. |
|
|
|
|
![](images/spacer.gif) |
USEC_OFFICER
![](http://compsci.ca/v3/uploads/user_avatars/16624966004bb548179e82e.png)
|
Posted: Sun Jun 20, 2010 7:42 pm Post subject: RE:"Prototype" of functions |
|
|
It used for giving to people as a way of saying 'Great job' or 'You're awsome' or something like that. |
|
|
|
|
![](images/spacer.gif) |
Cezna
![](http://compsci.ca/v3/uploads/user_avatars/9406831824c097251d4bb4.gif)
|
Posted: Sun Jun 20, 2010 7:45 pm Post subject: Re: "Prototype" of functions |
|
|
Go here to read about bits.
Karma is just to show how helpful/unhelpful a person is in general. |
|
|
|
|
![](images/spacer.gif) |
|