Commits

Steven! Ragnarök committed d37eec4

First GREEN stage of Red-Green-Refactor.

  • Participants
  • Parent commits b0c2703

Comments (0)

Files changed (3)

     test(" define F ( X  return 3 return 3");
     test(" define F ( X ] return 3 return 3");
     test(" define F  X ) return 3 return 3");
-/*    test(" F ( X ) return 3 return 3");
+    test(" F ( X ) return 3 return 3");
     test(" define F ( U V ) set Y 5 return ( + Y ( F 3 4 ) )");
     test(" define F ( X ) return 3 return - ( F 4 ) )");
     test(" set F ( X ) return 3 return 3 ");
          "      define K ( WW ) return ( + WW 10 ) " + 
          "      return ( H ( + W 1 ) ) " + 
          "   return ( G ( +  U 2 ) ) " + 
-         " return ( F 1 )");*/
+         " return ( F 1 )");
          
    
    }

src/A1Grammar.java

 		this.tokenStream = tokenStream;
 	}
 
+	public OrderedTree<Token> start()
+	{
+		OrderedTree<Token> prog = program();
+		match(TokenType.EOF);
+		return prog;
+	}
 
-	public OrderedTree<Token> start()
+
+	private OrderedTree<Token> program()
 	{
 		LinkedList<OrderedTree<Token>> kids = new
 			LinkedList<OrderedTree<Token>>();
 		LinkedList<OrderedTree<Token>> args = al();
 		LinkedList<OrderedTree<Token>> dec = new LinkedList<OrderedTree<Token>>();
 		dec.add(new OrderedTree<Token>(fname, args));
-		dec.add(start());
+		dec.add(program());
 		return new OrderedTree<Token>(def, dec);
 	}
 

src/TokenType.java

 {
 	PROGRAM("^program$"), SET("^set$"), MATH_OP("^[-+/*]$"),
 		RETURN("^return$"), DEFINE("^define$"), LPAREN("^\\($"),
-		RPAREN("^\\)$"), IDENT("^[a-zA-Z][a-zA-Z0-9_]*$"),
+		RPAREN("^\\)$"), IDENT("^[A-Z][a-zA-Z0-9_]*$"),
 		INT_LIT("^-?[0-9]+$"), EOF("^\\$$");
 
 	private final Pattern pattern;