Got these examples into unit tests. :) feeling good.
Ter
// simple, no AST
a : a ID
| ID ;
-------------
declarator
: declarator '['^ e ']'!
| declarator '['^ ']'!
| declarator '('^ ')'!
| '*'^ declarator
| '('! declarator ')'!
| ID
;
declarator
: declarator '[' e ']' -> ^('[' declarator e)
| declarator '[' ']' -> ^('[' declarator)
| declarator '(' ')' -> ^('(' declarator)
| '*' declarator -> ^('*' declarator)
| '(' declarator ')' -> declarator
| ID -> ID
;
String[] tests = {
"a", "a",
"*a", "(* a)",
"**a", "(* (* a))",
"a[3]", "([ a 3)",
"b[]", "([ b)",
"(a)", "a",
"a[]()", "(( ([ a))",
"a[][]", "([ ([ a))",
"*a[]", "(* ([ a))",
"(*a)[]", "([ (* a))",
};
---------------
e : e '.'^ ID
| e '.'^ 'this'
| '-'^ e
| e '*'^ e
| e ('+'^|'-'^) e
| INT
| ID
;
String[] tests = {
"a", "a",
"1", "1",
"a+1", "(+ a 1)",
"a*1", "(* a 1)",
"a.b", "(. a b)",
"a.this", "(. a this)",
"a+b*c", "(+ a (* b c))",
"a.b+1", "(+ (. a b) 1)",
"-a", "(- a)",
"-a+b", "(+ (- a) b)",
"-a.b", "(- (. a b))",
};
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.