parser problem

Bugs

Modérateur : xcasadmin

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

parser problem

Message par lukamar » mar. juin 28, 2022 7:27 pm

These two lines should evaluate to the same expression, but the second one fails:

Code : Tout sélectionner

eval('output' = 'id');
eval('output'='id')
It seems that '=' gets parsed in advance to at_equal, but the single quotes do not pertain to =.

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: parser problem

Message par parisse » mer. juin 29, 2022 5:11 am

This can unfortunately not be easily modified, because I want to be able to enter '=' as an object (e.g. as an argument of a command) and it seems I can only do that by adding a line in the lexer (input_lexer.ll), rules in the parser do not work.

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: parser problem

Message par lukamar » mer. juin 29, 2022 8:10 am

OK, it's not a big deal. But maybe a fix would be to print the equal-symbolic expression with spaces around = when unary_function_ptr is detected in both sides of the equality? I'm suggesting this for programmatic use of giac, where gen::print is called to write an expression to a string which is supposed to be converted back with e.g. "expr".

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: parser problem

Message par parisse » mer. juin 29, 2022 2:29 pm

I tried that but some regression tests fail. Some diffs are obviously OK (because printing =), but some are not and I do not understand why.

parisse
Messages : 5734
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: parser problem

Message par parisse » ven. juil. 01, 2022 12:29 pm

Ok, I think I have a fix, at pre lexer step add a space in '=' if the number of quotes is odd

Code : Tout sélectionner

diff input_lexer.ll input_lexer.ll~
1042,1043c1042,1043
< 	// stupid match of bracket then parenthesis then quotes
< 	int l=s.size(),nb=0,np=0,nq=0;
---
> 	// stupid match of bracket then parenthesis
> 	int l=s.size(),nb=0,np=0;
1047,1053d1046
< 	    if (!instring && s[i]=='\''){
< 	      nq++;
< 	      if (nq%2==1 && i>2 && s[i-2]=='\'' && s[i-1]=='='){
< 		s.insert(s.begin()+i-1,' ');
< 		++l;
< 	      }

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: parser problem

Message par lukamar » mer. juil. 06, 2022 6:19 am

Great, it works now!

Répondre