playground tweaks

This commit is contained in:
Terence Parr 2012-11-17 16:27:10 -08:00
parent b1a3370934
commit 5e519d0063
3 changed files with 3 additions and 44 deletions

View File

@ -1,26 +0,0 @@
grammar AA;
prog: classDef+ ;
classDef
: 'class' ID '{' member+ '}'
;
member
: 'int' ID ';' {System.out.println("var "+$ID.text);}
| 'int' ID '(' ')' '{' stat '}' {System.out.println("func "+$ID.text);}
;
stat: expr ';'
{System.out.println("found expr: "+$stat.text);}
| ID '=' expr ';'
{System.out.println("found assign: "+$stat.text+$ID.text);}
;
expr: INT
| ID '(' ')'
;
ID : ('a'..'z'|'A'..'Z')+ ;
INT : '0'..'9'+ ;
WS : (' '|'\t'|'\n'|'\r')+ {setChannel(HIDDEN);} ;

View File

@ -509,8 +509,7 @@ statement
| 'while' parExpression statement
| 'do' statement 'while' parExpression ';'
| 'try' block
( catches 'finally' block
| catches
( catches ('finally' block)?
| 'finally' block
)
| 'switch' parExpression '{' switchBlockStatementGroups '}'
@ -537,7 +536,7 @@ formalParameter
;
switchBlockStatementGroups
: (switchBlockStatementGroup)*
: switchBlockStatementGroup* switchLabel*
;
/* The change here (switchLabel -> switchLabel+) technically makes this grammar
@ -545,7 +544,7 @@ switchBlockStatementGroups
appropriate AST, one in which each group, except possibly the last one, has
labels and statements. */
switchBlockStatementGroup
: switchLabel+ blockStatement*
: switchLabel+ blockStatement+
;
switchLabel

View File

@ -1,14 +0,0 @@
import org.antlr.v4.runtime.ANTLRFileStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.RuleContext;
public class TestAA {
public static void main(String[] args) throws Exception {
AALexer t = new AALexer(new ANTLRFileStream(args[0]));
CommonTokenStream tokens = new CommonTokenStream(t);
AAParser p = new AAParser(tokens);
p.setBuildParseTree(true);
RuleContext ctx = p.prog();
//System.out.println("ctx="+ctx.toStringTree(p));
}
}