Paradox Community

Items in pnews.paradox-dos

Subject:Re: Operator precedence
Date:Fri, 8 Sep 2017 07:53:24 +1000
From:Bernie van't Hof <berniev@bje.com.au>
Newsgroups:pnews.paradox-dos
	a = 1
	b = 2
	c = a *-b
becomes
	$a = 1;
	$b = 2;
	$c = $a *- $b;
         // I should probably tidy up the positioning of the '-'
and correctly produces -2

But you had me going there for a moment!

-B
On 8/9/17 2:28 am, Michael Kennedy wrote:
> Bernie, that looks very good - but my opinion here is worthless! I'm not 
> tuned in to all the "NOT" details, not very familiar with PHP, etc.
> 
> One other interesting find: I looked through the "help" system on 
> PlayRightPro (PDox-DOS), and found "precedence", and... its list is 
> exactly as I posted yesterday, but it also has that #$%#$%#$% Unary 
> Minus as a separate item in the list, just after the first "()" entry!
> 
> Which, IMO, is good news.
> 
> So, seems the PDox Exp-Eval code does recognise that special "-", and 
> handles it separately. And, presumably the PHP evaluator behaves 
> identically?
> 
>    - Mike
> 
> 
> On 07/09/2017 07:16, Bernie van't Hof wrote:
>> What I came up with ..
>>
>> public function Parser()
>> {
>>      $out = '';
>>      while ( ! $this->lexer->Eof()) {
>>          switch($this->lexer->Next()->type){
>>              case whatever:
>>                  $out .= $this->Expression();
>>          }
>>      }
>>      return $out;
>> }
>>
>> public function Expression()
>> {
>>      $exp = '';
>>      do{
>>          $exp .= $this->SubExpr();
>>      } while ($this->lexer->Peek()->type == 'logical');
>>      return $exp;
>> }
>> private function SubExpr()
>> {
>>      $exp = '';
>>      do{
>>          switch($this->Peek()->type){
>>              case 'logical':
>>                  // PAL's NOT, AND, OR
>>                  // use php's && and || instead of AND and
OR
>>                  // (higher precedence than ops)
>>                  $exp .= $this->lexer->Next()->val . '(' .

>> Expression() . ')';
>>                  break;
>>              case 'op':
>>                  // PAL's +-*/%=<>
>>                  switch($this->lexer->Next()->val)
>>                  {
>>                      // etc
>>                  }
>>              //etc (dozens of 'em)
>>          }
>>      } while($this->lexer->Peek()->type == 'op');
>>      return $exp;
>> }
>>
>> - B
>> On 7/9/17 7:54 am, Michael Kennedy wrote:
>>> Wow - that's real nasty! But you seem to have resolved it.
>>>
>>> Back, maybe 20-25 years ago, I recall writing an expression-evaluator 
>>> from scratch, and I still recall major hassle with that damn "-" and 
>>> with "NOT" - probably the same issue with both. I don't remember the 
>>> details, nor good examples, but maybe something like:
>>>
>>>    A * -B --> A * (-B) --> A * (0-B)
>>>
>>> So the meaning of each "-" had to be determined first, before 
>>> deciding how/when to evaluate it.
>>>
>>> Maybe the same approach was/is needed for NOT?
>>>
>>>    - Mike
>>>
>>>
>>> On 06/09/2017 18:56, Bernie van't Hof wrote:
>>>> Thanks, Mike.
>>>>
>>>> What I realised in the mean-time ..
>>>>
>>>> php has precedence of ! (NOT) above all those on your list except ()
>>>> So
>>>>      IF NOT Retval = "Esc" ; which works fine
>>>> does not become
>>>>      if( ! $Retval == 'Esc') // valid php but wrong result!
>>>> it should be
>>>>      if( ! ($Retval == 'Esc'))
>>>>
>>>> I used the above pal construct only twice in 30k lines of pal, more 
>>>> commonly using
>>>>      IF Retval <> "Esc"
>>>> which converts nicely to
>>>>      if($Retval <> 'Esc')
>>>> so I didn't spot it in earlier run-time testing.
>>>>
>>>>
>>>> -B
>>>>
>>>> On 7/9/17 2:10 am, Michael Kennedy wrote:
>>>>> The manuals say:
>>>>>   () - Inner pairs first
>>>>>   (All the following are Left-to-Right]...
>>>>>   * /
>>>>>   + -
>>>>>   = <> < <= > >=
>>>>>   NOT
>>>>>   AND
>>>>>   OR
>>>>>
>>>>> ...all as expected...
>>>>>
>>>>> There's no mention of that darn "unary minus", nor of different 
>>>>> contexts of "NOT", etc...
>>>>>
>>>>> I assume that PDoxDOS represents (1=2), [False], internally as 0, 
>>>>> but I don't recall how it represents (1=1) [True, = NOT False]. I 
>>>>> think most systems use "-1", but some systems use just "1", and 
>>>>> maybe some use "any non-zero value"?.....
>>>>>
>>>>>    - Mike
>>>>>
>>>>>
>>>>> On 04/09/2017 18:40, Bernie van't Hof wrote:
>>>>>> Anyone have handy a operator precedence list for PDOX DOS?
>>>>>>
>>>>>> Having an issue with 'NOT' and darned if I can see why.
>>>>>>
>>>>>> Thanks,
>>>>>> B


Copyright © 2004 thedbcommunity.com