[antlr-interest] program with ast grammar

Михаил Юрушкин yurushkin at rambler.ru
Tue Nov 3 04:18:05 PST 2009


good day,
fortran supports "if construct" with following syntax:

[name:] if (..) then
 [block]

else if (..) [name:] then
 [block]....

else if (..) [name:] then
 [block]
else [name:]
 [block]
end if [name]

for example:
 firstIf : if (a>10) then
 a = 10
 else if (b>10) : secondIf then
 b = 10;
 else secondif:
 b = 20;

 else firstif:
 a = 20;
 endif firstif

My parser:
 if_construct : if_then_stmt block? (else_if_stmt block)* (else_stmt 
block)? endif_stmt
 -> "if_construct "

if_then_stmt, else_if_stmt, else_stmt and endif_stmt contain "name" 
attribute...
so... i gave you an example, when my parser creates second if_stmt with 
!!! 2 else stmt's (not one) !!! it context-sensitive place of grammar. 
it depends on the "name" attribute. if it name= firstif then "else_if" 
it belongs to first if_stmt.
if name=secondif, it belongs to second if_stmt...

how can I modify the grammar, to get right AST. how to analize [name] 
attribute at make right desicion?


More information about the antlr-interest mailing list