Parsing Fortran

Joe Krahn krahn@niehs.nih.gov
Mon Jul 17 19:02:00 GMT 2006


Andrew Pinski wrote:
> 
> On Jul 15, 2006, at 5:52 AM, Joe Krahn wrote:
> 
>> In thinking about the problem, I came up with a decent scheme for  
>> getting most of the work done with a YACC style parser.
> 
> 
> Did you know that even the C and C++ parsers in GCC have both moved  
> away from YACC style parsers
> since YACC cannot deal with the error handling?  Also YACC could not  
> express the C++ language at
> all.
> 

That makes sense. One big problem with YACC is that any syntax errors 
are simply viewed by YACC as unidentifiable gibberish. This is not a 
problem using YACC for low-level parsing, where it seems to work well. 
However, maybe it is not useful for a subsequent pass.

In general, my plan is to use YACC for lexing characters into 
context-independent generic expressions. Consider the usual hierarchy of 
expressions and operators, with list-delimiters and "parenthetic 
decorations" handled in a generic, uniform way. The primary caveats are 
handling blank delimiters and the different priority of ':' in top-level 
expressions. In particular, a unary operator following a 'blank' 
delimiter is parsed wrong, and has to be 'patched' afterwards.

Using YACC this way, errors only occur when there really is 
uninterpretable gibberish. For example, if a triplet-spec is seen where 
it is invalid, it still be recognized as a triplet-spec, instead of just 
seeing ':' as an unexpected character.

The next level requires some hand-parsing, but parsing abstract tokens 
is much easier than parsing raw text because it is easy to look ahead. 
And, unlike the typical recursive-descent approach (as I understand it), 
the raw text only gets parsed once.

Joe Krahn



More information about the Fortran mailing list