Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /trunk/src/parser/diderot.grm
ViewVC logotype

View of /trunk/src/parser/diderot.grm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (download) (annotate)
Mon Feb 8 22:51:42 2010 UTC (10 years, 7 months ago) by jhr
File size: 3085 byte(s)
  Working on Diderot parser
(* diderot.grm
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *)

%name Diderot;

%tokens
  : KW_actor		("actor")
  | KW_bool		("bool")
  | KW_die		("die")
  | KW_else		("else")
  | KW_field		("field")
  | KW_if		("if")
  | KW_image		("image")
  | KW_input		("input")
  | KW_int		("int")
  | KW_kernel		("kernel")
  | KW_new		("new")
  | KW_real		("real")
  | KW_stabilize	("stabilize")
  | KW_string		("string")
  | KW_tensor		("tensor")
  | KW_vec		("vec")
  | OP_eq		("=")
  | OP_orelse		("||")
  | OP_andalso		("&&")
  | OP_lt		("<")
  | OP_lte		("<=")
  | OP_eqeq		("==")
  | OP_neq		("!=")
  | OP_gte		(">=")
  | OP_gt		(">")
  | OP_plus		("+")
  | OP_minus		("-")
  | OP_star		("*")
  | OP_slash		("/")
  | OP_at		("@")
  | LP			("(")
  | RP			(")")
  | LB			("[")
  | RB			("]")
  | LCB			("{")
  | RCB			("}")
  | COMMA		(",")
  | SEMICOLON		(";")
  | HASH		("#")
  | INT of IntInf.int
  | FLOAT of FloatLit.float
  | STRING of string
  | ID of Atom.atom
  ;

%defs (
(* apply a mark constructor to a span and a tree *)
  fun mark cons (span : AntlrStreamPos.span, tr) = cons{span = span, tree = tr}

);

File
	: Decl+
	;

Decl
	: InputDecl
	| GlobalDecl
	| ActorDecl
	;


(***** Inputs *****)

InputDecl
	: "input" Type ID ( "=" Expr )? ";"
	;

(***** Global declarations *****)

GlobalDecl
	: Type ID "=" Expr ";"
	;


(***** Actors *****)

ActorDecl
	: "actor" ID "(" Params ")" "{" ActorState* ActorMethod+ "}"
	;

Params
	: ( Param ( "," Param )* )?
	;

Param
	: Type ID
	;

ActorState
	: Type ID "=" Expr ";"
	;

ActorMethod
	: ID Block
	;

Block
	: "{" Stmt* "}"
		=> (markStmt(FULL_SPAN, PT.S_Block Stmt))
	;

Stmt
	: AtomicStmt
		=> (AtomicStmt)
	| %try "if" "(" Expr ")" Stmt "else" Stmt
		=> (markStmt(FULL_SPAN, PT.S_IfThenElse(Expr, Stmt1, Stmt2)))
	| %try "if" "(" Expr ")" Stmt
		=> (markStmt(FULL_SPAN, PT.S_IfThen(Expr, Stmt)))
	;

AtomicStmt
	: Block
		=> (Block)
	| "stabilize" ";"
		=> (markStmt(FULL_SPAN, PT.S_Stabilize))
	| "die" ";"
		=> (markStmt(FULL_SPAN, PT.S_Die))
	| "new" ID "(" Arguments ")" ";"
		=> (markStmt(FULL_SPAN, PT.S_New(ID, Arguments)))
	| Type ID "=" Expr ";"
		=> (markStmt(FULL_SPAN, PT.S_Decl(Type, ID, Expr)))
	| ID "=" Expr ";"
		=> (markStmt(FULL_SPAN, PT.S_Assign(ID, Expr)))
	;

Arguments
	: ( Expr ("," Expr)* )?
	;


(***** Types *****)

Type	: "image" "<" Dimensions ">"
	| "tensor" "<" Dimensions ">"
	| "field" "#" Dimension "<" Dimensions ">"
	| "kernel" "#" Dimension
	| "vec" "<" Dimension ">"
	| "bool"
	| "int"
	| "real"
	| "string"
	;

Dimensions
	: ( Dimension ("," Dimension)* )?
	;

Dimension
	: INT
	;

(***** Expressions *****)

Expr
	: Expr1 ( "||" Expr1 )*
	;

Expr1
	: Expr2 ( "&&" Expr2 )*
	;

Expr2
	: Expr3 ( CmpOp Expr3 )*
	;

CmpOp
	: "<" | "<=" | "==" | ">=" | ">"
	;

Expr3
	: Expr4 ( AddOp Expr4 )*
	;

AddOp
	: "+" | "-"
	;

Expr4
	: Expr5 ( MulOp Expr5 )*
	;

MulOp
	: "*" | "/"
	;

Expr5
	: Expr6 ( "@" Expr6 | "[" Expr "]" )*
	;

Expr6
	: AtomExp
	| "-" AtomExp
	;

AtomExp
	: ID
	| INT
	| FLOAT
	| STRING
	| "(" Expr ("," Expr)* ")"
	;

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0