01: package fri.patterns.interpreter.parsergenerator.semantics.examples;
02:
03: import java.io.*;
04: import fri.patterns.interpreter.parsergenerator.*;
05: import fri.patterns.interpreter.parsergenerator.lexer.*;
06: import fri.patterns.interpreter.parsergenerator.syntax.Syntax;
07: import fri.patterns.interpreter.parsergenerator.syntax.builder.*;
08: import fri.patterns.interpreter.parsergenerator.semantics.TreeBuilderSemantic;
09:
10: /**
11: TreeBuilderSemantic example that shows the instance tree of
12: the EBNF file <i>syntax/builder/examples/SyntaxBuilder.syntax</i<.
13: */
14:
15: public class TreeBuilderExample {
16: /** Test output of SyntaxBuilder syntax tree. */
17: public static void main(String[] args) {
18: try {
19: Reader input = new InputStreamReader(
20: Parser.class
21: .getResourceAsStream("syntax/builder/examples/SyntaxBuilder.syntax"));
22: Syntax syntax = new Syntax(StandardLexerRules.lexerSyntax);
23: SyntaxSeparation separation = new SyntaxSeparation(syntax);
24: LexerBuilder builder = new LexerBuilder(separation
25: .getLexerSyntax(), separation.getIgnoredSymbols());
26: Lexer lexer = builder.getLexer(input);
27: Parser p = new Parser(new SyntaxBuilderParserTables());
28: if (p.parse(lexer, new TreeBuilderSemantic())) {
29: TreeBuilderSemantic.Node n = (TreeBuilderSemantic.Node) p
30: .getResult();
31: System.err.println("got result: " + n);
32: System.out.println(n.toString(0));
33: }
34: } catch (Exception e) {
35: e.printStackTrace();
36: }
37: }
38:
39: }
|