On Tue, Mar 04, 2025 at 06:35:03PM +0000, Martin Baker wrote:
> 
> Although you have explained what I need for coding, just for my own
> curiosity, I am curious about the root cause of the issues with compiler
> warnings. Is it because FriCAS uses a 'Pratt parser' and therefore does
> not have a formal syntax and so the warnings can only be generated from
> a set of ad hoc rules?

It is due to simplicity or rather lack of information in compiler
data structures.  For example modern compiler typicaly when seeing
an identifier remember its position in source text.  Spad compiler
does not store positions.  In case of 'if' is it matter of managing
compiler data structurs.  Each assignment first checks that variable
is known and appropriate type, this is done via lookup in compiler
symbol table.  The assigment adds information that variable is
initialized.  At the end of 'if' compiler needs to combine
information from both branches of 'if'.  Apparently this code
has a bug, only using information coming from 'if' (namely that
in one branch there is no assignment to 'x') and misses fact
that 'x' has global definition.

Contributing factor is that compiler works in recursive way
and sometimes must backtrack, that throw away part of work
and restart from earlier place.  Since in many cases compiler
uses destructive modificantion in principle it is possible
that failed case did some modifications to compiler data
structures and this modification is not valid for the case
after backtracking.

Concerning Spad syntax, while it is rather inconvenient to
specify Spad syntax using a context free grammar, syntax
is precisely defined by priorities.  Parser produces parse
tree and for later stages syntax is mostly irrelevant, for
example in principle users could write syntax tree as a Lisp
S-expression (however, later stages depend on getting correct
syntax tree, there are no checks for malformed systax tree
after parsing).

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/Z8ddesrMixAItKY6%40fricas.org.

Reply via email to