----- Original Message -----
From: "Gerard Cote" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, June 17, 2005 8:48 PM
Subject: [REBOL] Nedd to use an indirection like operation during parsing


 Hello list,

 Below is some relatively easy parsing rules even if it took long for me to put 
pieces in place.
 The object of these rules is to recognize between different representations of 
numbers.
 Up to now I succeeded to let REBOL distinguish between the followinf reps: a 
binary number, an octal number, a decimal number, an
hexadecimal number and an identifier too.
 However even if REBOL can catch the identifier I am unable to get the value 
associated with it.
 Can someone help with an explanation or better with a solution to get the 
requested value.

 Thanks in advance!
 Gerard

 issue-rules: make object! [

      expr: [copy my-num1  bin-number (print-info my-num1 "bin") to end |
          copy my-num2  oct-number (print-info my-num2 "oct") to end |
          copy my-num3  hex-number (print-info my-num3 "hex") to end |
          copy my-num4  dec-number (print-info my-num4 "dec") to end |
          copy my-ident identifier (print-info my-ident "ident") to end
      ]
      letter-b: charset "bB"
      letter-o: charset "oO"
      letter-x: charset "xX"
      bin-digit: charset "01"
      bin-digits: [some bin-digit]
      bin-number: [bin-digits letter-b]
      oct-digit: charset "01234567"
      oct-digits: [some oct-digit]
      oct-number: [oct-digits letter-o]
      dec-digit:  charset "0123456789"
         hex-digit: union charset "abcdefABCDEF" dec-digit
         hex-digits: [some hex-digit]
         hex-number: [hex-digits letter-x]
         dec-number:  [0 1 "-" [unsigned-integer | decimal-number | 
scientific-notation-decimal-number]]
         unsigned-integer: [some digit]
      decimal-number: [0 1 unsigned-integer decimal-fraction]
      decimal-fraction: ["." unsigned-integer]
      scientific-notation-decimal-number: [mantissa "E" ["+" | "-" | none] 
exponent]
      mantissa: [unsigned-integer | decimal-number]
      exponent: [unsigned-integer]
      identifier: [letter any [digit | letter | letter-sep]]
         letter:  charset [#"A" - #"Z" #"a" - #"z"]
      letter-sep: charset "_-"
      digit:   charset "0123456789"

      print-info: func [info info-type][
            either any [info-type = "bin" info-type = "oct" info-type = "hex"][
             info-num: remove back tail info
             info-num: head info
            ][
             info-num: info
            ]
            either [info-type = "ident"][
             print :info
            ][
             print info
            ]
            print info-type

      ]
 ]

 ; Calls to the above parsing rules follow for each "data representation" (Bin, 
oct, hex, dec, Ident)
 ; The only remaining problem - for the moment - is : I can't get the Ident 
value in addition
 ; to its name and type as was done for the other datatypes

  nom: 250
 parse to-string [43.21] issue-rules/expr
 parse to-string [1.23E4] issue-rules/expr
 parse to-string [#c2x] issue-rules/expr
 parse to-string [#123o] issue-rules/expr
 parse to-string [#0101b] issue-rules/expr
 parse to-string [var-name] issue-rules/expr

 Here is an exec of the above code:
 >> nom: 250
 == 250
 >> parse to-string [43.21] issue-rules/expr
 43
 dec
 == true
 >> parse to-string [1.23E4] issue-rules/expr
 12300
 dec
 == true
 >> parse to-string [#c2x] issue-rules/expr
 c2
 hex
 == true
 >> parse to-string [#123o] issue-rules/expr
 123
 oct
 == true
 >> parse to-string [#0101b] issue-rules/expr
 0101
 bin
 == true
 >> parse to-string [var-name] issue-rules/expr
 var-name
 ident
 == true
>

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to