1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 * This file is free software, which comes along with NIT. This software is
4 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 * is kept unaltered, and a notification of the changes is added.
8 * You are allowed to redistribute it and sell it, alone or is a part of
12 package org
.nitlanguage
.gen
;
15 import java
.nio
.file
.*;
17 import org
.nitlanguage
.gen
.lexer
.*;
18 import org
.nitlanguage
.gen
.parser
.*;
19 import org
.nitlanguage
.gen
.analysis
.*;
20 import org
.nitlanguage
.gen
.node
.*;
22 public class TestParser
extends DepthFirstAdapter
{
23 public static void main(String
[] args
) throws Exception
{
24 if (args
.length
== 0) {
25 BufferedReader ir
= new BufferedReader(new InputStreamReader(System
.in));
28 for(int i
=0; i
<args
.length
; i
++) {
29 //System.out.println(args[i]);
31 //Here we use "ISO-8859-1" because we want to opaquely treat Bytes as characters.
32 //Unfortunately "US-ASCII" does not seems to do the job for values>127.
33 BufferedReader ir
= new BufferedReader(new InputStreamReader(new FileInputStream(args
[i
]), "ISO-8859-1"));
40 public static void work(BufferedReader ir
) {
41 TestParser testParser
= new TestParser();
43 PushbackReader r
= new PushbackReader(ir
, 1024);
44 Parser parser
= new Parser(new Lexer(r
));
45 Node syntaxTree
= parser
.parse();
46 syntaxTree
.apply(testParser
);
47 } catch (LexerException e
) {
48 System
.out
.println(e
.getMessage() + ".");
49 } catch (ParserException e
) {
50 System
.out
.println(e
.getMessage() + ".");
51 } catch (IOException e
) {
52 System
.out
.println(e
.getMessage() + ".");