[plt-scheme] rookie question

From: m n (monitor10 at gmail.com)
Date: Fri Apr 29 14:07:32 EDT 2005

Hi:

    I am developping a simple parser. When I run the parser by typing 
(scan&parse "(* 2 6)")
    I get the following error:
. parsing: at line 1: nonterminal <expression> can't begin with
literal-string25 "*"

    The reason that above error occurs is that my parser tries to read
* as a symbol. But the grammar of proc-type-exp also need *, but it
treats * as a string. So scanner confuses. Now I know what causes the
error, but I do not know the solution. So can you give the solution to
me? The followings are my codes:

define the-lexical-spec
  '((whitespace (whitespace)                                          
                                 skip)
    (comment    ("%" (arbno (not #\newline)))                         
                                 skip)
    (identifier ((or letter "_" "-" "?" "+" "-" "*") (arbno (or letter
digit "_" "-" "?" "+" "-" "*"))) symbol)
    (number     (digit (arbno digit))                                 
                                 number)))

(define the-grammar
  '((program (expression) a-program)
    (expression (number) lit-exp)
    (expression ("true") true-exp)
    (expression ("false") false-exp)
    (expression (identifier) var-exp)   
    (expression
      ("if" expression "then" expression "else" expression)
      if-exp)
   (expression
      ("let" (arbno  identifier "=" expression) "in" expression)
      let-exp)
    (expression                         
      ("proc" "(" (separated-list type-exp identifier ",") ")" expression)
      proc-exp)
    (expression
      ("(" expression (arbno expression) ")")
      app-exp)
    (type-exp ("int") int-type-exp)             
    (type-exp ("bool") bool-type-exp)           
    (type-exp                                   
      ("(" (separated-list type-exp "*") "->" type-exp ")")
      proc-type-exp)
    ))

(sllgen:make-define-datatypes the-lexical-spec the-grammar)

(define scan&parse
  (sllgen:make-string-parser the-lexical-spec the-grammar))



Posted on the users mailing list.