Example:
—————————————————–
definition
module Main
exports
context-free start-symbols Expr

context-free syntax

  A B C -> Expr {ast("Foo(<1>, <2>, <3>)")}

  B C   -> Expr {ast("Foo(<1>){<2>}")}

  B C D -> Expr {ast("Foo(<1>){<2>, <3>}")}

  C D   -> Expr {ast("Foo(<1>){Id(<2>)}")}

  D E   -> Expr {ast("<1>{<2>}")}

lexical syntax
“a” -> A
“b” -> B
“c” -> C
“d” -> D
“e” -> E

 [ 	

] -> LAYOUT
—————————————————–

Testsuite:
—————————————————–
testsuite Ast attributes and annotations
topsort Expr

test
“a b c” -> Foo(“a”, “b”, “c”)

test
“b c” -> Foo(“b”){“c”}

test
“b c d” -> Foo(“b”){“c”, “d”}

test
“c d” -> Foo(“c”){Id(“d”)}

test
“d e” -> “d”{“e”}
—————————————————–

Output:
———————————————————————–
executing testsuite Ast attributes and annotations with 5 tests
———————————————————————–
* OK : test 1 (a b c)
* ERROR: test 2 (b c)
- succeeded: Foo(“b”)
- expected: Foo(“b”){“c”}
* ERROR: test 3 (b c d)
- succeeded: Foo(“b”)
- expected: Foo(“b”){“c”,“d”}
* ERROR: test 4 (c d)
- succeeded: Foo(“c”)
- expected: Foo(“c”){Id(“d”)}
* ERROR: test 5 (d e)
- succeeded: “d”
- expected: “d”{“e”}
———————————————————————–
results testsuite Ast attributes and annotations
successes : 1
failures : 4
———————————————————————–

Submitted on 20 March 2007 at 16:10

Log in to post comments