From b0a6585252135383c3a3b594e5937168e58de3a1 Mon Sep 17 00:00:00 2001 From: Jakob Herrmann Date: Thu, 15 Dec 2016 13:35:07 +0100 Subject: [PATCH] Small changes, i.e. RunParser now reads from System.in. --- src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java | 7 +++++-- src/de/dhbwstuttgart/parser/RunParser.java | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java b/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java index 496dd2903..9260bccf5 100644 --- a/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java +++ b/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java @@ -2,11 +2,14 @@ package de.dhbwstuttgart.parser; import org.antlr.v4.runtime.tree.*; import de.dhbwstuttgart.syntaxtree.*; public class CompilationUnitEvaluator extends Java8BaseListener{ + @Override + public void enterCompilationUnit(Java8Parser.CompilationUnitContext ctx) { + System.out.println("Entering compilationUnit..."); + } @Override public void exitCompilationUnit(Java8Parser.CompilationUnitContext ctx) { - // SourceFile result = new SourceFile(new List()); System.out.println("sourceFile("); - System.out.println(ctx.packageDeclaration()); + System.out.println(ctx.packageDeclaration().Identifier()); System.out.println(")"); } } diff --git a/src/de/dhbwstuttgart/parser/RunParser.java b/src/de/dhbwstuttgart/parser/RunParser.java index d4a6a7400..9b1c86539 100644 --- a/src/de/dhbwstuttgart/parser/RunParser.java +++ b/src/de/dhbwstuttgart/parser/RunParser.java @@ -6,13 +6,16 @@ import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.tree.ParseTreeWalker; import de.dhbwstuttgart.syntaxtree.*; +import java.util.Scanner; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; public class RunParser{ public static void main(String[] args){ try{ - String inputString = args[0]; + Scanner sc = new Scanner(System.in); + String inputString = sc.nextLine(); + while(sc.hasNextLine()) inputString = inputString + sc.nextLine(); InputStream stream = new ByteArrayInputStream(inputString.getBytes(StandardCharsets.UTF_8)); ANTLRInputStream input = new ANTLRInputStream(stream); Java8Lexer lexer = new Java8Lexer(input);