comparison src/luan/CmdLine.java @ 11:b7d7069fee58

add assignment statement and CmdLine git-svn-id: https://luan-java.googlecode.com/svn/trunk@12 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Thu, 22 Nov 2012 10:51:56 +0000
parents
children 9cea1aea5eef
comparison
equal deleted inserted replaced
10:8217d8485715 11:b7d7069fee58
1 package luan;
2
3 import java.util.List;
4 import java.util.Scanner;
5 import org.parboiled.Parboiled;
6 import org.parboiled.errors.ErrorUtils;
7 import org.parboiled.parserunners.ReportingParseRunner;
8 import org.parboiled.support.ParsingResult;
9 import luan.interp.Expressions;
10 import luan.interp.Stmt;
11 import luan.interp.LuaParser;
12 import luan.lib.BasicLib;
13
14
15 public class CmdLine {
16
17 public static void main(String[] args) throws Exception {
18 LuaParser parser = Parboiled.createParser(LuaParser.class);
19 LuaState lua = new LuaState();
20 while( true ) {
21 System.out.print("> ");
22 String input = new Scanner(System.in).nextLine();
23 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(input);
24 if( result.hasErrors() ) {
25 System.out.println("Parse Errors:\n" + ErrorUtils.printParseErrors(result));
26 } else {
27 Object resultValue = result.resultValue;
28 if( resultValue instanceof Expressions ) {
29 Expressions expressions = (Expressions)resultValue;
30 List vals = expressions.eval(lua);
31 if( !vals.isEmpty() )
32 BasicLib.print( vals.toArray() );
33 } else {
34 Stmt stmt = (Stmt)resultValue;
35 stmt.eval(lua);
36 }
37 }
38 }
39 }
40 }