Commit 8b3a083f authored by Jamie A. Jennings's avatar Jamie A. Jennings

Added example from CSC 505

parent 5d8c7a6c
-- example.rpl
--
-- CSC505 HW4 executable example using RPL (https://rosie-lang.org)
-- 'C' is a conditional
-- 'S' is a statement
C = "(" [^)]* ")"
print = "print" "(" [0-9]+ ")"
-- This example is from https://en.wikipedia.org/wiki/Parsing_expression_grammar
grammar
S = ( "if" C "then" S "else" S ) / ( "if" C "then" S ) / print
end
-- test C accepts "()", "(foo)"
-- test C rejects "(())" -- no accomodation for nesting
-- test print accepts "print(0)", "print(01234)"
-- test print rejects "print()", "print(foo)"
-- test S accepts "print(0)"
-- test S accepts "if (foo) then print(0)"
-- test S accepts "if (foo) then print(0) else print(1)"
......@@ -527,4 +527,12 @@ check(rplx, "should compile and load ok")
check_trace('S', "x", true, 1) -- S matches empty string
check_trace('S', "aaa", true, 4) -- S matches entire input
local ok, pkgname, errs = e:loadfile(TEST_HOME .. "/" .. "else-example.rpl")
check(ok, "maybe missing test rpl file?")
local rplx, errs = e:compile('S')
check(rplx, "should compile ok")
check_trace('S', "if (t1) then print(1) else if (t2) then print(2) else print(3)", true, 63)
return test.finish()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment