# Copyright 2005 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ ? def := ; null ? def makeLALR1Parser := # value: ? makeLALR1Parser :DeepFrozen # value: ? def s implements DeepFrozen {}; def l implements DeepFrozen {}; def r implements DeepFrozen {}; def id implements DeepFrozen {}; def star implements DeepFrozen {}; def eq implements DeepFrozen {}; null ? def mapStream := ; null ? def identityValues implements DeepFrozen { to run(s) :any { [s, s] }}; null ? def parser := makeLALR1Parser("from cl-yacc test 4-20", > s, > [id, star, eq], > [[s, [l, eq, r]], > [s, [r]], > [l, [star, r]], > [l, [id]], > [r, [l]]], > ["tokenFunction" => identityValues]) # value: ? parser :DeepFrozen # value: ? parser.parse([star, id, eq, star, star, id].asStream()) # value: [[, [[]]], , [[, [[, [[]]]]]]] ? def broken := parser.parse([eq].asStream()) # value: , ], got > ? def ParseError := makeLALR1Parser.getParseError() > def p :ParseError := Ref.optProblem(broken) # value: problem: parse error: expected one of [, ], got ? [p.getExpected(), p.getFound()] # value: [[, ].asSet(), ] EOF parse errors ? def broken := makeLALR1Parser("_", 1, [2], [[1, [2]]], ["tokenFunction" => identityValues]).parse([2, 2].asStream()) # value: Actions ? def parser := makeLALR1Parser("action test", > "a", > ["c"], > [["a", ["b"], > def _(x) :any {`[$x]`}], > ["b", ["c", "c"], > def _(x,y) :any {`$x $y`}]], > ["tokenFunction" => \ > def _(s) :any { [s(0,1), s] }]) # value: ? parser.parse(["carrots", "celery"].asStream()) # value: "[carrots celery]" quasi-parser ? def lalr1__quasiParser := makeLALR1Parser.getLalr1__quasiParser() # value: > ? def parser := lalr1`"quasi-form cl-yacc test 4-20" := s. > s := l $eq r. > s := r. > l := $star r. > l := $id. > r := l.` # value: ? parser :DeepFrozen # value: ? parser.parse(mapStream(any, [star, id, eq, star, star, id].asStream(), identityValues)) # value: [[, [[]]], , [[, [[, [[]]]]]]] ? def p :ParseError := Ref.optProblem(parser.parse([[eq, eq]].asStream())) # value: problem: parse error: expected one of [, ], got ? [p.getExpected(), p.getFound()] # value: [[, ].asSet(), ] EOF parse errors from quasi-parser ? def broken := lalr1`"eoftest" := ${"x"}.`.parse([["x", null], ["x", null]].asStream()) # value: bad terminal ? lalr1`"_" := ${"x"}.`.parse([["y", null]].asStream()) # problem: "y" is not a terminal symbol in <_ quasi-defined LALR(1) parser> quasi-parser with actions ? def calls(verb) :any { def caller implements DeepFrozen { > match [=="run", [rec] + args] { > E.call(rec, verb, args) }}} > null ? lalr1`"sums" := sum. > sum := ${'1'} => ${calls("getCodepoint")}. > sum := sum ${'+'} sum => ${def _(l,_,r) :any {l + r}}. > `.parse(mapStream(any, "1+1+1".asStream(), identityValues)) # value: 147 Bug: actions were being counted as terminals for the duplicate terminal check ? lalr1`"_" := x. x := ${"y"} => ${"y"}.` # value: <_ quasi-defined LALR(1) parser> XXX parse error details XXX error propagation if the stream fails XXX eof errors XXX quasi's behavior if start symbol is undefined