From: Lyn A Headley <laheadle@midway.uchicago.edu>
To: caml-list@inria.fr
Subject: lexing strings
Date: Sun, 01 Jun 1997 18:53:12 -0500 [thread overview]
Message-ID: <199706012353.SAA06495@kimbark.uchicago.edu> (raw)
hi,
I pored over the flex/bison manuals without finding an answer,
so I hope this question is nontrivial.
I'm having a rough time lexing strings with ocamllex, just using
the normal read-eval-print interpreter whose main grammar rule is:
expr EOL { $1 }
with one of the 'expr' rules like this:
| STRING { (O.String $1) }
My lex file has a rule like this:
| '\'' { slurp lexbuf }
recursively lexing strings according to rule 'slurp'. slurp's main
regex looks like this:
[^'\n']*[^'\\']'\''
which should match any sequence of non-newlines until it reaches a '
not preceded by a backslash. slurp returns the token: STRING(!build)).
My intent, when reading a string, is for the lexer to see the first ',
jump into 'slurp,' eat up the string and return it as the STRING token,
then have the parser read a newline and return EOL, thus matching the
main grammar rule and printing the result. This almost works, but not
until the user types _two_ newlines will the "interpreter" respond
by printing the expression value! i.e., typing
'hi' [newline]
at the prompt is not enough; two newlines are required. Other than
that, the expected value is returned. Does this mean that the first
newline is interpreted as part of the STRING? Why would my regex match
the newline?
any help appreciated,
Lyn Headley
next reply other threads:[~1997-06-02 14:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-06-01 23:53 Lyn A Headley [this message]
1997-06-02 15:35 ` Pierre Weis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199706012353.SAA06495@kimbark.uchicago.edu \
--to=laheadle@midway.uchicago.edu \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox