Page 1 sur 1
parser problem
Publié : mar. juin 28, 2022 7:27 pm
par lukamar
These two lines should evaluate to the same expression, but the second one fails:
It seems that '=' gets parsed in advance to at_equal, but the single quotes do not pertain to =.
Re: parser problem
Publié : mer. juin 29, 2022 5:11 am
par parisse
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.
Re: parser problem
Publié : mer. juin 29, 2022 8:10 am
par lukamar
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".
Re: parser problem
Publié : mer. juin 29, 2022 2:29 pm
par parisse
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.
Re: parser problem
Publié : ven. juil. 01, 2022 12:29 pm
par parisse
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;
< }
Re: parser problem
Publié : mer. juil. 06, 2022 6:19 am
par lukamar
Great, it works now!