BNF for PseuCo.jjt

TOKENS

<DEFAULT> SKIP : {
" "
| "\t"
| "\n"
| "\r"
| "\f"
}

   
<DEFAULT> SPECIAL : {
<SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")>
| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
}

   
<DEFAULT> TOKEN : {
<BOOL: "bool">
| <BREAK: "break">
| <CASE: "case">
| <CONTINUE: "continue">
| <_DEFAULT: "default">
| <DO: "do">
| <ELSE: "else">
| <FALSE: "false">
| <FOR: "for">
| <IF: "if">
| <INT: "int">
| <RETURN: "return">
| <TRUE: "true">
| <VOID: "void">
| <WHILE: "while">
| <AGENT: "agent">
| <SELECT: "select">
| <STRING: "string">
| <START: "start">
| <MUTEX: "mutex">
| <LOCK: "lock">
| <UNLOCK: "unlock">
| <INTCHAN: "intchan" (<INTEGER_LITERAL>)?>
| <BOOLCHAN: "boolchan" (<INTEGER_LITERAL>)?>
| <STRINGCHAN: "stringchan" (<INTEGER_LITERAL>)?>
| <WAIT: "waitForCondition">
| <SIGNAL: "signal">
| <SIGNALALL: "signalAll">
| <JOIN: "join">
| <PRINTLN: "println">
| <CONDITION: "condition">
| <MONITOR: "monitor">
| <STRUCT: "struct">
| <MAINAGENT: "mainAgent">
| <WITH: "with">
| <IMPORT: "import">
}

   
<DEFAULT> TOKEN : {
<INTEGER_LITERAL: ["1"-"9"] (["0"-"9"])* | "0">
| <STRING_LITERAL: "\"" (~["\"","\\","\n","\r"] | "\\" (["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] (["0"-"7"])? | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* "\"">
}

   
<DEFAULT> TOKEN : {
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
| <#LETTER: ["$","A"-"Z","_","a"-"z","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u00ff","\u0100"-"\u1fff","\u3040"-"\u318f","\u3300"-"\u337f","\u3400"-"\u3d2d","\u4e00"-"\u9fff","\uf900"-"\ufaff"]>
| <#DIGIT: ["0"-"9","\u0660"-"\u0669","\u06f0"-"\u06f9","\u0966"-"\u096f","\u09e6"-"\u09ef","\u0a66"-"\u0a6f","\u0ae6"-"\u0aef","\u0b66"-"\u0b6f","\u0be7"-"\u0bef","\u0c66"-"\u0c6f","\u0ce6"-"\u0cef","\u0d66"-"\u0d6f","\u0e50"-"\u0e59","\u0ed0"-"\u0ed9","\u1040"-"\u1049"]>
}

   
<DEFAULT> TOKEN : {
<LPAREN: "(">
| <RPAREN: ")">
| <LBRACE: "{">
| <RBRACE: "}">
| <LBRACKET: "[">
| <RBRACKET: "]">
| <SEMICOLON: ";">
| <COMMA: ",">
| <DOT: ".">
}

   
<DEFAULT> TOKEN : {
<ASSIGN: "=">
| <GT: ">">
| <LT: "<">
| <BANG: "!">
| <COLON: ":">
| <EQ: "==">
| <LE: "<=">
| <GE: ">=">
| <NE: "!=">
| <SC_OR: "||">
| <SC_AND: "&&">
| <INCR: "++">
| <DECR: "--">
| <PLUS: "+">
| <MINUS: "-">
| <STAR: "*">
| <SLASH: "/">
| <REM: "%">
| <QUEST: "?">
| <PLUSASSIGN: "+=">
| <MINUSASSIGN: "-=">
| <STARASSIGN: "*=">
| <SLASHASSIGN: "/=">
| <SENDOP: "<!">
| <RECIEVEOP: "<?">
}

   

NON-TERMINALS

/*****************************************
 * THE PSEUCO LANGUAGE GRAMMAR STARTS HERE *
 *****************************************/

/*
 * Program structuring syntax follows.
 */
exitWithError ::= java code
Program ::= Import ( Monitor | Struct | MainAgent | Procedure | DeclStatement | exitWithError )+ <EOF>
Import ::= ( <IMPORT> <STRING_LITERAL> ";" )*
MainAgent ::= "mainAgent" StmtBlock
Procedure ::= ResultType <IDENTIFIER> ( FormalParameters | missingToken ) StmtBlock
FormalParameters ::= "(" ( FormalParameter ( "," FormalParameter )* )? ")"
FormalParameter ::= Type <IDENTIFIER>
Monitor ::= "monitor" <IDENTIFIER> "{" MonitorCode "}"
MonitorCode ::= ( Procedure | ConditionDeclStmt | DeclStatement )*
Struct ::= "struct" <IDENTIFIER> "{" StructCode "}"
StructCode ::= ( Procedure | DeclStatement )*
// This production is to determine lookahead only.
ProcedureDeclarationLookahead ::= ResultType <IDENTIFIER> "("
Decl ::= Type VariableDeclarator ( "," VariableDeclarator )*
ConditionDeclStmt ::= <CONDITION> <IDENTIFIER> "with" Expression ";"
DeclStatement ::= Decl ";"
VariableDeclarator ::= <IDENTIFIER> ( "=" VariableInitializer )?
VariableInitializer ::= "{" ( VariableInitializer ( "," VariableInitializer )* )? ( "," )? "}"
| Expression
/*
 * Type, name and expression syntax follows.
 */
Type ::= PrimitiveType ( "[" <INTEGER_LITERAL> "]" )*
PrimitiveType ::= <BOOL>
| <INT>
| <STRING>
| <MUTEX>
| <AGENT>
| Chan
| <IDENTIFIER>
MonitorTypeLookAhead ::= <IDENTIFIER> ( "[" <INTEGER_LITERAL> "]" )* <IDENTIFIER>
Chan ::= ( <INTCHAN> | <BOOLCHAN> | <STRINGCHAN> )
ResultType ::= "void"
| Type
/*
 * Expression syntax follows.
 */
Expression ::= StartExpression
| Assignment
| Send
| ConditionalExpression
ExpressionList ::= Expression ( "," Expression )*
StartExpression ::= "start" ( MonCall | ProcCall | missingToken )
Assignment ::= AssignDestination AssignmentOperator Expression
AssignDestination ::= <IDENTIFIER> ( "[" Expression "]" )*
AssignmentOperator ::= "="
| "*="
| "/="
| "+="
| "-="
Send ::= CallExpression "<!" ( Expression | missingToken )
ConditionalExpression ::= ConditionalOrExpression ( "?" ( Expression | missingToken ) ( ":" | missingToken ) ( ConditionalExpression | missingToken ) )?
ConditionalOrExpression ::= ConditionalAndExpression ( "||" ( ConditionalAndExpression | missingToken ) )*
ConditionalAndExpression ::= EqualityExpression ( "&&" ( EqualityExpression | missingToken ) )*
EqualityExpression ::= RelationalExpression ( ( "==" | "!=" ) ( RelationalExpression | missingToken ) )*
RelationalExpression ::= AdditiveExpression ( ( "<" | ">" | "<=" | ">=" ) ( AdditiveExpression | missingToken ) )*
AdditiveExpression ::= MultiplicativeExpression ( ( "+" | "-" ) ( MultiplicativeExpression | missingToken ) )*
MultiplicativeExpression ::= UnaryExpression ( ( "*" | "/" | "%" ) ( UnaryExpression | missingToken ) )*
UnaryExpression ::= ( "+" | "-" | "!" ) ( UnaryExpression | missingToken )
| PostfixExpression
| ReceiveExpression
PostfixExpression ::= AssignDestination ( "++" | "--" )
ReceiveExpression ::= ( "<?" )* CallExpression
CallExpression ::= MonCall
| ProcCall
| ArrayExpression
// LOOKAHEAD only.. supressing javacc warning!
CallableLookAhead ::= <IDENTIFIER> "("
| PrimaryExpression "."
ProcCall ::= <IDENTIFIER> Arguments
Arguments ::= "(" ( ExpressionList )? ")"
MonCall ::= ( ProcCall | PrimaryExpression ) ( "." ProcCall )+
ArrayExpression ::= PrimaryExpression ( "[" Expression "]" )*
PrimaryExpression ::= Literal
| <IDENTIFIER>
| "(" Expression ")"
Literal ::= <INTEGER_LITERAL>
| <STRING_LITERAL>
| BooleanLiteral
BooleanLiteral ::= "true"
| "false"
/*
 * Statement syntax follows.
 */
Statement ::= StmtBlock
| StatementExpression ";"
| SelectStatement
| IfStatement
| WhileStatement
| DoStatement
| ForStatement
| "break" ";"
| "continue" ";"
| ReturnStatement
| PrimitiveStatement
| Println
| ";"
StmtBlock ::= "{" ( BlockStatement )* ( "}" | exitWithError )
BlockStatement ::= Procedure
| DeclStatement
| ConditionDeclStmt
| Statement
StatementExpression ::= StartExpression
| Assignment
| Send
| PostfixExpression
| CallExpression
| ReceiveExpression
StatementExpressionList ::= StatementExpression ( "," ( StatementExpression | missingToken ) )*
SelectStatement ::= "select" "{" ( Case )+ "}"
Case ::= "case" StatementExpression ":" Statement
| "default" ":" Statement
IfStatement ::= "if" "(" ( Expression | missingToken ) ( ")" | missingToken ) Statement ( "else" Statement )?
WhileStatement ::= "while" "(" ( Expression | missingToken ) ( ")" | missingToken ) Statement
DoStatement ::= "do" Statement "while" "(" ( Expression | missingToken ) ( ")" | missingToken ) ";"
missingExpression ::= java code
missingToken ::= java code
ForStatement ::= "for" "(" ( ForInit )? ( ";" | missingToken ) ( Expression )? ( ";" | missingToken ) ( ForUpdate )? ( ")" | missingToken ) Statement
ForInit ::= ( Decl | StatementExpression ) ( "," ( Decl | StatementExpression ) )*
ForUpdate ::= StatementExpressionList
ReturnStatement ::= "return" ( Expression )? ";"
PrimitiveStatement ::= ( ( "join" | "lock" | "unlock" | "waitForCondition" | "signal" ) Expression | "signalAll" ( Expression )? ) ";"
Println ::= "println" "(" ExpressionList ")" ";"