[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grammar questions



Hi Indrek.

Here's something to look at.  I think it does implement correctly the
"match the closest if" (regardless of form) rule.  Hopefully it will
help you, and maybe you will contribute back your PHP grammar to us...

Etienne
-- 
----------------------------------------------------------------------
Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                             http://www.sablecc.org/
and SableVM:                                   http://www.sablevm.org/
Tokens

  blank = (' ' | 10 | 13)*;

  semicolon = ';';
  if = 'if';
  exp = 'exp';
  colon = ':';
  else = 'else';
  elseif = 'elseif';
  endif = 'endif';

Ignored Tokens
  blank;

Productions

program = stmt*;

stmt = 
  {empty} semicolon |
  {if} if exp stmt |
  {ifelseif} if exp stmt_noif elseif_stmt_noif* elseif_stmt |
  {ifelse} if exp stmt_noif elseif_stmt_noif* else stmt |
  {ifcolon} if exp colon stmt* endif semicolon |
  {ifcolonelseif} if exp colon stmt_list_noif elseifcolon_stmt_noif* elseifcolon_stmt endif semicolon |
  {ifcolonelse} if exp colon stmt_list_noif elseifcolon_stmt_noif* else stmt* endif semicolon;

elseif_stmt =  
  elseif exp stmt;

elseifcolon_stmt = 
  elseif exp colon stmt*;

stmt_noif = 
  {empty} semicolon |
  {ifelse} if exp [l]:stmt_noif elseif_stmt_noif* else [r]:stmt_noif |
  {ifcolon} if exp colon stmt* endif semicolon |
  {ifcolonelseif} if exp colon stmt_list_noif elseifcolon_stmt_noif* elseifcolon_stmt endif semicolon |
  {ifcolonelse} if exp colon stmt_list_noif elseifcolon_stmt_noif* else stmt* endif semicolon;

elseif_stmt_noif =  
  elseif exp stmt_noif;

elseifcolon_stmt_noif = 
  elseif exp colon stmt_list_noif;

stmt_list_noif =
  {empty} |
  {full} stmt* stmt_noif;