[12 - Tree Grammar] Add AssignCount grammar and adjust ANTLR build config
This commit is contained in:
@@ -71,7 +71,7 @@ public class AntlrXTreeGrammarMain {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ANTLRInputStream input = new ANTLRInputStream(new ByteArrayInputStream(BEISPIELFOLIEN.getBytes()));
|
||||
ANTLRInputStream input = new ANTLRInputStream(new ByteArrayInputStream(TEST.getBytes()));
|
||||
XLexer lexer = new XLexer(input);
|
||||
XParser parser = new XParser(new CommonTokenStream(lexer));
|
||||
CommonTree tree = parser.program().getTree();
|
||||
@@ -79,9 +79,9 @@ public class AntlrXTreeGrammarMain {
|
||||
// Tut nichts
|
||||
XTreeGrammar treeGrammar = new XTreeGrammar(new CommonTreeNodeStream(tree));
|
||||
tree = treeGrammar.program().getTree();
|
||||
|
||||
// Z<>hle Zuweisungen
|
||||
// TODO
|
||||
|
||||
|
||||
// Zuweisungen
|
||||
AssignCount count = new AssignCount(new CommonTreeNodeStream(tree));
|
||||
System.out.printf("Assign count: %d%n", count.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,24 @@ options {
|
||||
|
||||
}
|
||||
|
||||
decl: ^(DECL ID ('int' | 'float' | 'string') 'read'? 'print'?);
|
||||
decllist: ^(DECLLIST decl*);
|
||||
|
||||
program: 'todo';
|
||||
expr: ^(('+' | '-' | '*' | '/') expr expr)
|
||||
| ^(UMINUS (INTCONST | FLOATCONST))
|
||||
| INTCONST | FLOATCONST | STRINGCONST | ID;
|
||||
|
||||
assignstat: ^(':=' ID expr) { count++; }; // FIXME Zählt nicht in AntlrXTreeGrammarMain, aber in Tests??
|
||||
|
||||
cond: ^(('<' | '>' | '=') expr expr);
|
||||
condstat: ^('if' cond stat stat?);
|
||||
|
||||
whilestat: ^('while' cond stat);
|
||||
forstat: ^('for' assignstat cond assignstat stat);
|
||||
|
||||
stat: assignstat | condstat | whilestat | forstat | statlist;
|
||||
|
||||
statlist: ^(STATLIST stat*);
|
||||
|
||||
program: ^('program' ID decllist statlist);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,6 @@ STRINGCONST=16
|
||||
UMINUS=17
|
||||
WS=18
|
||||
ZERO=19
|
||||
T__46=46
|
||||
'('=20
|
||||
')'=21
|
||||
'*'=22
|
||||
@@ -67,4 +66,3 @@ T__46=46
|
||||
'string'=43
|
||||
'then'=44
|
||||
'while'=45
|
||||
'todo'=46
|
||||
|
||||
Reference in New Issue
Block a user