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 923 of 2,753   
   Dmitry A. Kazakov to Ivan Boldyrev   
   Re: Grammar for roman numerals   
   01 Apr 07 08:55:42   
   
   From: mailbox@dmitry-kazakov.de   
      
   On 29 Mar 2007 23:05:56 -0400, Ivan Boldyrev wrote:   
      
   > On 9791 day of my life msully wrote:   
   >> One of the exercises I am doing is writing a grammar for roman   
   >> numerals.   
   > ...   
   >> Comments?   
   >   
   > Now rewrite the grammar as a regular expression :)   
      
   Not in "regulars", but the following more or less obvious pattern   
      
   NOEMPTY   
   ( ['M'['M'['M']]]   
     ['C'['D'|'M'|'C'['C']] | 'D'['C'['C'['C']]]]   
     ['X'['L'|'C'|'X'['X']] | 'L'['X'['X'['X']]]]   
     ['I'['V'|'X'|'I'['I']] | 'V'['I'['I'['I']]]]   
   )   
      
   should do the trick. More complex were to use immediate assignments for   
   evaluation of the numeral's value it gets matched. But it is also doable.   
   Though a hand-written scanner would be faster and cleaner.   
      
   --   
   Regards,   
   Dmitry A. Kazakov   
   http://www.dmitry-kazakov.de   
      
   --- 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