1. How to tell the difference bewteen comparing and assigning
- Posted by jbrown105 at speedymail.org May 12, 2002
- 453 views
I'm thinking about writing a preprocessor which supports making refrences to variables, but i need to be able to tell the difference when the program is using = to assign to a variable and using = to compare a variable to something. Any ideas on how to do this? TIA, jbrown -- http://fastmail.fm/ - Access your email from home and the web
2. Re: How to tell the difference bewteen comparing and assigning
- Posted by stabmaster_ at HOTMAIL.COM May 12, 2002
- 437 views
One way to spot comparisons (although it probably doesn't cover _all_ possible comparisons) are when '=' is used after 'if' or 'while' if 1=0 then... while 0=1 do... etc.
3. Re: How to tell the difference bewteen comparing and assigning
- Posted by jbrown105 at speedymail.org May 12, 2002
- 435 views
On 0, stabmaster_ at HOTMAIL.COM wrote: > > One way to spot comparisons (although it probably doesn't cover _all_ > possible comparisons) are when '=' is used after 'if' or 'while' > > if 1=0 then... > > while 0=1 do... > > etc. > Aside from not covering all situations, what do i do about this: if a > b then a = b else b = a end if i could try looking only between the "if" and "then" tokens (and ditto for while..do) but it would be hard to do that for all possible situations: ?(a=b) --check for ( ?a[b=b] --check for [ ? a=b --check for ? a = a = b --check for previous = etc etc etc as there are too many exceptions and to make a parser which takes care of this cleanly would be quite difficult. i was thinking about making my preprocessor use == for comparision and := for assignment and ignore the = sign completely. (Perhaps even make the = sign an illegal token, although that would be going to the extreme.) I'd prefer not to do that however, so if you or anyone else has an idea on how this could be done, it would be greatly appreciated. TIA, jbrown -- http://fastmail.fm Quick as a click
4. Re: How to tell the difference bewteen comparing and assigning
- Posted by Kat <gertie at PELL.NET> May 12, 2002
- 431 views
On 12 May 2002, at 23:18, jbrown105 at speedymail.org wrote: > > On 0, stabmaster_ at HOTMAIL.COM wrote: > > > > One way to spot comparisons (although it probably doesn't cover _all_ > > possible comparisons) are when '=' is used after 'if' or 'while' > > > > if 1=0 then... > > > > while 0=1 do... > > > > etc. > > > > Aside from not covering all situations, what do i do about this: > > if a > b then a = b else b = a end if > > i could try looking only between the "if" and "then" tokens (and ditto > for > while..do) but it would be hard to do that for all possible situations: > > ?(a=b) --check for ( > ?a[b=b] --check for [ > ? a=b --check for ? > a = a = b --check for previous = > etc etc etc > > as there are too many exceptions and to make a parser which takes care > of this > cleanly would be quite difficult. Ok, automagically make a short program, set up the vars in that line, and send it to one of the Eu interpreters in the archives. When the line ends, check the vars to see if they changed. Sounds like a good reason for using == or := ? Kat
5. Re: How to tell the difference bewteen comparing and assigning
- Posted by mistertrik at hotmail.com May 13, 2002
- 450 views
Also, a comparison can be used inside a statement. Ie. ... x = 3 + a*(y = 0) x is a+3 for y = 0 3 for all other values of y Just check to see whether there are brackets enclosing the = sign.... for an assignment, there shouldn't be. Just remember to look for 'or', 'and' and 'then' as well as what you put below, and you should be right. Summary: For comparison '=' if*=*then if*=*or ... or*=*then and*=*then not*=*then while*=*do (*=*) IF and WHILE must be at the beginning, THEN and DO must be at the end, OR NOT AND can be either. With the brackets, it's a little more difficult, because a comparison '=' could be hidden inside a larger one.... ie x = 4*( z = (4*b+c)) ie x = 4 if z = 4b + c, or x = 0 otherwise. I think that's all bases covered... ask the Creator, if he's in. ----------------- MrTrick >From: stabmaster_ at HOTMAIL.COM >Reply-To: EUforum at topica.com >To: EUforum <EUforum at topica.com> >Subject: Re: How to tell the difference bewteen comparing and assigning >Date: Sun, 12 May 2002 20:33:43 +0000 > > >One way to spot comparisons (although it probably doesn't cover _all_ >possible comparisons) are when '=' is used after 'if' or 'while' > >if 1=0 then... > >while 0=1 do... > >etc. > > > >
6. Re: How to tell the difference bewteen comparing and assigning
- Posted by jbrown105 at speedymail.org May 13, 2002
- 427 views
On 0, irv at take.maxleft.com wrote: > > jbrown105 at speedymail.org wrote: > > On 0, stabmaster_ at HOTMAIL.COM wrote: > > > > > > One way to spot comparisons (although it probably doesn't cover _all_ > > > possible comparisons) are when '=' is used after 'if' or 'while' > > > > > > if 1=0 then... > > > > > > while 0=1 do... > > > > > > etc. > > Why don't you download Dave Cuny's Py interpreter > and see how he did it? > IIRC it uses = as both an assignment operator and > a comparison operator. For atoms AND sequences. > > Regards, > Irv > That would work perfectly ... if I was using Py's parser (Ox) instead of the parser use by Dot. At this time I would rather not implement such a heavy rewrite (although I probably will one day anyways) so this is not really an option (at least not a simple one). (When I do finally give in and attempt a rewrite of Dot, I will most definitly consider looking at Py and Ox to use as the parser for the new program however.) jbrown -- http://fastmail.fm - 100% lightning
7. Re: How to tell the difference bewteen comparing and assigning
- Posted by "Carl W." <euphoria at cyreksoft.yorks.com> May 13, 2002
- 443 views
jbrown wrote: > Aside from not covering all situations, what do i do about this: > > if a > b then a = b else b = a end if > > i could try looking only between the "if" and "then" tokens (and ditto > for while..do) but it would be hard to do that for all possible > situations: > > ?(a=b) --check for ( > ?a[b=b] --check for [ > ? a=b --check for ? > a = a = b --check for previous = > etc etc etc > > as there are too many exceptions and to make a parser which takes care > of this cleanly would be quite difficult. i was thinking about making my > preprocessor use == for comparision and := for assignment and ignore the > = sign completely. > (Perhaps even make the = sign an illegal token, although that would be > going to the extreme.) I'd prefer not to do that however, so if you or > anyone else has an idea on how this could be done, it would be greatly > appreciated. I think what you need to do is parse the source by context. i.e. Judge what you need to do by what has gone before. There's only one statement form using '=' that is an assignment; All others are boolean statements. Assignments *always* begin with a variable or a sequence index, so you can safely ignore 'what comes next' even if it does contain a second equals sign. In fact, the *only* valid statements _beginning_ with a variable are assignments. Here's a little euphoria-like pseudocode: while Parsing_Source do get next token end get look for a typename, if there is one, it's a variable declaration store variable declarations in a symbol table for future ref. end look parse other syntax -- Any '=' found in here is part of a boolean expression. end parse look for so-far-unmatched token in the symbol table. if found: -- must be an assignment get next non-whitespace char end get check for a '['; if it is: -- skip sequence subscript skip past the next ']' get next non-whitespace char end get end check check to see if it's an '='; fail with error if not. get an expression -- Any '=' found here is part of a boolean expression. end get end look end while HTH, Carl -- [ Carl R White -=- aka -=- Cyrek the Illogical ] [ () E-mail...: cyrek{}cyreksoft.yorks.com ] [ /\ URL......: http://www.cyreksoft.yorks.com ]
8. Re: How to tell the difference bewteen comparing and assigning
- Posted by jbrown105 at speedymail.org May 13, 2002
- 461 views
On 0, irv at take.maxleft.com wrote: > > jbrown105 at speedymail.org wrote: > > On 0, stabmaster_ at HOTMAIL.COM wrote: > > > > > > One way to spot comparisons (although it probably doesn't cover _all_ > > > possible comparisons) are when '=' is used after 'if' or 'while' > > > > > > if 1=0 then... > > > > > > while 0=1 do... > > > > > > etc. > > Why don't you download Dave Cuny's Py interpreter > and see how he did it? > IIRC it uses = as both an assignment operator and > a comparison operator. For atoms AND sequences. > > Regards, > Irv > That would work perfectly ... if I was using Py's parser (Ox) instead of the parser use by Dot. At this time I would rather not implement such a heavy rewrite (although I probably will one day anyways) so this is not really an option (at least not a simple one). (When I do finally give in and attempt a rewrite of Dot, I will most definitly consider looking at Py and Ox to use as the parser for the new program however.) jbrown -- http://fastmail.fm - 100% lightning