Open pelson opened 5 years ago
match
process access to the current state of the parse tree. However, that change requires some serious re-engineering. Since this ticket was created, we have added symbol-table functionality which helps with some of the issues. It will help even more if we associate each symbol table with the corresponding node in the parse tree. This is not ideal but is a relatively quick way for us to make use of the global state held in symbol tables in order to see where we are in the tree.
Fortran is not a context free grammar, where even simple language tokenization requires additional context/state (e.g.
if(i.le.20.and.j.le.10)
and the challenge with tokenizing"20.and"
). Fparser2 can already handle this tokenization example well, but there are Fortran parse rules which are sensitive to high-level program context which are harder to deal with.For example, take the following code:
The line containing the print statement will be parsed using R912 (
PRINT format [, output-item-list]
), and the singleoutput-item-list
will be parsed with:At this point, parsing the expression depends on the previously seen context - if
my_struct_mod
is uncommented then we would parse this statement with R701 (structure-constructor
) whereas ifmy_func_mod
is uncommented we would parse it with R701 (function-reference
).182 raised a number of cases of these extra contextual information being needed for parsing of the Primary type:
test_C701_no_assumed_size_array
)test_C702_no_assumed_size_array
)test_Function_Reference
)test_Type_Param_Inquiry
)Further to the parse context of
print*, item(id=2)
example, one could imagine a parser which fails to parseitem(id=2)
unlessitem
has already been defined as astructure-constructor
or afunction-reference
. It may therefore make sense for the parser to raise aSyntaxError
/NoMatchError
as soon as it is realised that there is no appropriate match, rather than the existing behaviour of producing astructure-constructor
. Naturally, this would be a breaking change to the existing behaviour, and would need to be managed appropriately.