Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004330OCamlCamlp4public2007-06-25 13:312008-10-03 17:13
Reporterbrunodefraine 
Assigned Toertai 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.10.0 
Target VersionFixed in Version3.11+dev 
Summary0004330: gramlib parses illegal input for recursive rules
DescriptionWhen defining a recursive rule for a binary operator, gramlib accepts input that illegally ommits a right operand.

For example, with the following grammar definition:

open Camlp4.PreCast ;

value a = Gram.Entry.mk "a" ;
value a_eoi = Gram.Entry.mk "a_eoi" ;

EXTEND Gram
a: [[ "one" -> 1 | x = a; "plus"; y = a -> x+y ]];
a_eoi: [[ x = a; `EOI -> x ]];
END ;

and the following function:

value parse_string entry s =
try
  Gram.parse_string entry (Loc.mk "<string>") s
with [ Loc.Exc_located loc exn ->
begin
  print_endline (Loc.to_string loc);
  print_endline (Printexc.to_string exn);
  failwith "Syntax Error"
end ] ;

The following is correct:

# parse_string a_eoi "one plus one" ;
- : int = 2

While all of the following inputs should be rejected because they are not legal according to the grammar:

# parse_string a_eoi "one plus" ;
- : int = 1
# parse_string a_eoi "one plus plus" ;
- : int = 1
# parse_string a_eoi "one plus one plus" ;
- : int = 2
# parse_string a_eoi "one plus one plus plus" ;
- : int = 2

Curiously, you may only repeat the operator twice. If you specify it three times, gramlib complains.

# parse_string a_eoi "one plus plus plus" ;
File "<string>", line 1, characters 9-13
Stream.Error("EOI expected after [a] (in [a_eoi])")
Exception: Failure "Syntax Error".
# parse_string a_eoi "one plus one plus plus plus" ;
File "<string>", line 1, characters 18-22
Stream.Error("EOI expected after [a] (in [a_eoi])")
Exception: Failure "Syntax Error".
Additional InformationTested with Ocaml 3.10.0 on Mac OS X.
TagsNo tags attached.
Attached Files? file icon gram_rec.ml [^] (427 bytes) 2007-06-25 13:31 [Show Content]

- Relationships

-  Notes
(0004652)
ertai (developer)
2008-10-03 17:13

Thank for the report(s) this bug is now fixed in the CVS HEAD version.

NOTE: PR#4603, PR#4330, PR#4551, PR#4513 are all the same bug.

- Issue History
Date Modified Username Field Change
2007-06-25 13:31 brunodefraine New Issue
2007-06-25 13:31 brunodefraine File Added: gram_rec.ml
2007-11-10 15:03 xleroy Status new => assigned
2007-11-10 15:03 xleroy Assigned To => ertai
2008-10-03 17:13 ertai Note Added: 0004652
2008-10-03 17:13 ertai Status assigned => closed
2008-10-03 17:13 ertai Resolution open => fixed
2008-10-03 17:13 ertai Fixed in Version => 3.11+dev


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker