//PHASE1//
//////////

options
{
	MULTI = true;
	//DEBUG_PARSER = true;
}

PARSER_BEGIN(drawphase1)

public class drawphase1{
  public static void main(String args[]) {
   System.out.println("Welcome, please enter a command");
    drawphase1 parser = new drawphase1(System.in);
    try {
      ASTStart p = parser.Start();
      if (args.length == 1 && args[0].equals("-d")) {
        p.dump("");
      } else {
        p.display();
      }
    } catch (ParseException e) {
      System.out.println("drawphase1:  Encountered errors during parse.");
      e.printStackTrace();
    } catch (Exception e1) {
      System.out.println("drawphase1:  Encountered errors during interpretation/tree building.");
      e1.printStackTrace();
    } catch (Error e2) {
      System.out.println("drawphase1:  Encountered errors during interpretation.");
      e2.printStackTrace();
    }
  }}


PARSER_END(drawphase1)

SKIP:
{
	" "
|	"\t"
|	"\n"
|	"\r"

}

TOKEN:
{
	<LBRACE: "{" >
|	<RBRACE: "}">
|	<LSQBRACKET: "[">
|	<RSQBRACKET: "]">	
|	<RECTANGLETEXT: "rectangle" >
|	<LINETEXT: "line"  >
|	<TRIANGLETEXT: "triangle" >
|	<SQUARETEXT:  "square">
|	<POLYGONTEXT:  "polygon" >
|	<TEXTTEXT: "text">
|	<CIRCLETEXT:  "circle">
|	<ELLIPSETEXT:  "ellipse" >
|	<PICTURETEXT:  "picture"  >
|     <COLOURTEXT: "colour">

}

TOKEN : /* INTEGERS */
{
  < INT:  <NUM> (<NUM>)* >
|
  < #NUM: ["0"-"9"]>
}

TOKEN : /* colours*/
{
  <COLOURNAME: <COLOUR> > 
|  
  <#COLOUR:  "black" | "white" | "blue" | "red" | "green" >  		
}

TOKEN : /* letters (and numbers) for message */
{
  <MESSAGE: "\""(<LETTER>)+ "\"" > 
|  
  <#LETTER: ["A"-"Z"] | ["a" - "z"] | ["0"-"9"]| ([" "])*>  		
}

TOKEN : /* x,y co-ordianates*/
{
  < COORD: <INT> <INT> >
}

ASTStart Start() : {}
{
	<PICTURETEXT> <LSQBRACKET> intValue() intValue() <RSQBRACKET> (draw())* <EOF>
	{return jjtThis;}
}

void draw () #void: {}  {brace() | shape() }	

void shape() #void: {} {line() | rectangle() | square() | ellipse() | circle() | triangle() | polygon() | text() }

void brace() #void: {} {<LBRACE> draw() (draw())*  <RBRACE> }

void line(): {} {<LINETEXT> <LSQBRACKET> intValue() intValue() intValue() intValue() <RSQBRACKET> }

void rectangle(): {} {<RECTANGLETEXT> <LSQBRACKET> intValue() intValue() intValue() intValue() <RSQBRACKET> }

void square(): {} {<SQUARETEXT> <LSQBRACKET> intValue() intValue() intValue() <RSQBRACKET> }

void ellipse(): {} {<ELLIPSETEXT> <LSQBRACKET> intValue() intValue() intValue() intValue() <RSQBRACKET> }

void circle(): {} {<CIRCLETEXT> <LSQBRACKET> intValue() intValue() intValue() <RSQBRACKET> }

void triangle(): {} {<TRIANGLETEXT> <LSQBRACKET> intValue() intValue() intValue() intValue() intValue() intValue() <RSQBRACKET> }

void polygon(): {} {<POLYGONTEXT> <LSQBRACKET>  coordValue() coordValue() (coordValue())* <RSQBRACKET> }

void coordValue() #void : {}
{ 
   intValue() intValue()   
}

void text(): {} {<TEXTTEXT> <LSQBRACKET> intValue() intValue() intValue() strMessage() <RSQBRACKET> }

void intValue() #void :{Token t;}
{
 (
  t=<INT>
    {
       jjtThis.val = Integer.parseInt(t.image);
    }
 )#intValue
}

void strMessage() #void :{Token s;}
{
 (
  s=<MESSAGE>
    {
       jjtThis.str = s.image;
    }
 )#strMessage
}