home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.compilers      Compiler construction, theory, etc. (Mod      2,753 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 973 of 2,753   
   Mohitz to All   
   Grammar for optional elements   
   12 Jun 07 02:21:31   
   
   From: coolmohitz@gmail.com   
      
   Hi,   
      
   I need to create a parser for a language something like this.   
      
   attribute1: value;   
   attribute2: value;   
   attribute3: value;   
      
   All the attributes are optional but can occur only once...   
      
   One way is to specify the grammar as follows: This doesn't do the   
   'SINGLE occurence check'   
   Can a grammar be designed which ensures that each attribute can be   
   entered only once.   
      
   attribute_list : attribute_list attribute | attribute   
   attribute :  ATTRIBUTE1 ':' IDENTIFIER | ATTRIBUTE2 ':' IDENTIFIER |   
   ATTRIBUTE3 ':' IDENTIFIER   
      
   [You can do it but you'll have a huge ugly grammar.  You're much   
   better off with a grammar that accepts any list of attributes, and   
   reject duplicates in your semantic code. -John]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca