Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About example from Ocaml user manual( section 1.8, genlex) #2776

Closed
vicuna opened this issue Jun 5, 2001 · 2 comments
Closed

About example from Ocaml user manual( section 1.8, genlex) #2776

vicuna opened this issue Jun 5, 2001 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 5, 2001

Original bug ID: 377
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Temofey
Version: ocaml 3.01
OS: RedHat Linux 6.2
Submission from: as1.d-up.max234.ukrpack.net (195.230.153.129)

parse_expr "1+2";;

  • : expression = Sum(Const 1,Const 2)

But

parse_expr "1-2";;

  • : expression = Const 1

This is a bug?

@vicuna
Copy link
Author

vicuna commented Jun 12, 2001

Comment author: administrator

parse_expr "1+2";;

  • : expression = Sum(Const 1,Const 2)

But

parse_expr "1-2";;

  • : expression = Const 1

This is a bug?

No. But it certainly is surprising, so explanations are in order.

The lexer from the Genlex module implements the "longest-match" rule,
meaning that "1-2" is read as "the integer 1" followed by "the integer -2".
parse_expr doesn't have a case for "an integer followed by an integer",
but it has one for "an integer", so it just reads the first integer (1)
and return this.

However, parse_expr "1 - 2" will do what you want, because the spaces
force the lexer to see "the integer 1", "the - sign", and "the integer 2".

This issue has been raised so many times that it should be in the FAQ
or maybe even in the tutorial.

Regards,

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Jul 24, 2001

Comment author: administrator

Added a note in the tutorial explaining this issue. -XL, 2001-07-24

@vicuna vicuna closed this as completed Jul 24, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant