def p_Type(p): ''' Type : NUMBER_TYPE | STRING_TYPE | BOOL_TYPE | NOTHING_TYPE | FunctionType | ListType | MapType | StructType | ENDPOINT | EXTERNAL StructType | EXTERNAL NUMBER_TYPE | EXTERNAL STRING_TYPE | EXTERNAL BOOL_TYPE | EXTERNAL ListType | EXTERNAL MapType ''' p[0] = AstNode(AST_TYPE,p.lineno(1),p.lexpos(1)); if len(p) == 2: typeIndex = 1; else: typeIndex = 2; if isinstance(p[typeIndex],basestring): p[0].value = p[typeIndex]; else: # means that has function, list type, or struct type p[0] = p[typeIndex]; if len(p) == 3: p[0].external = True;
def p_MessageReceiveSequenceFunction(p): """ MessageReceiveSequenceFunction : Identifier DOT Identifier CURLY_LEFT CURLY_RIGHT | Identifier DOT Identifier CURLY_LEFT FunctionBody CURLY_RIGHT | Identifier DOT Identifier LEFT_PAREN FunctionDeclArgList RIGHT_PAREN CURLY_LEFT CURLY_RIGHT | Identifier DOT Identifier LEFT_PAREN FunctionDeclArgList RIGHT_PAREN CURLY_LEFT FunctionBody CURLY_RIGHT | OnCompleteFunction """ if len(p) == 2: # means it was an on complete function. just use that directly p[0] = p[1] return p[0] = AstNode(AST_MESSAGE_RECEIVE_SEQUENCE_FUNCTION, p[1].lineNo, p[1].linePos) # specifically parsing for error of putting parens at end of message receive statement if (len(p) == 9) or (len(p) == 10): funcName = p[1].value + p[2] + p[3].value errMsg = '\nError in MessageSequence on "' + funcName + '". ' errMsg += "Only the first function can take in arguments. " errMsg += "Subsequent functions are automatically called by " errMsg += "the system. You should remove the parentheses at the end of " errMsg += "the function.\n" p[0].value = funcName raise WaldoParseException(p[0], errMsg) p[0].addChildren([p[1], p[3]]) if len(p) == 7: p[0].addChild(p[5]) else: p[0].addChild(AstNode(AST_FUNCTION_BODY, p[1].lineNo, p[1].linePos))
def p_Number(p): '''Number : NUMBER | MINUS NUMBER''' if (len(p) == 2): p[0] = AstNode(AST_NUMBER,p.lineno(1),p.lexpos(1),p[1]); elif(len(p) == 3): p[0] = AstNode(AST_NUMBER,p.lineno(2),p.lexpos(2),'-'+p[2]); else: errMsg = '\nBehram error when parsing for number. Incorrect '; errMsg += 'num statements when matching.\n'; errPrint(errMsg); assert(False); p[0].type = TYPE_NUMBER;
def p_EndpointSection(p): '''EndpointSection : Identifier CURLY_LEFT EndpointBodySection CURLY_RIGHT | Identifier CURLY_LEFT CURLY_RIGHT''' p[0] = AstNode(AST_ENDPOINT,p[1].lineNo,p[1].linePos); p[0].addChild(p[1]); if (len(p) == 5): p[0].addChild(p[3]); elif len(p) == 4: # means that we had nothing defined in the endpoint create # empty versions so that type checking gets what it expects. bodySecChild = AstNode(AST_ENDPOINT_BODY_SECTION,p[1].lineNo,p[1].linePos); bodyGlobSec = AstNode(AST_ENDPOINT_GLOBAL_SECTION,p[1].lineNo,p[1].linePos); funcGlobSec = AstNode(AST_ENDPOINT_FUNCTION_SECTION,p[1].lineNo,p[1].linePos); bodySecChild.addChildren([bodyGlobSec,funcGlobSec]); p[0].addChild(bodySecChild);
def p_MultiplyEqual(p): ''' MultiplyEqual : OperatableOn MULTIPLY_EQUAL ReturnableExpression ''' to_assign_to = p[1] to_assign_with = p[3] p[0] = AstNode( AST_ASSIGNMENT_STATEMENT,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to = AstNode( AST_OPERATABLE_ON_COMMA_LIST,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to.addChild(to_assign_to) p[0].addChild(list_to_assign_to); multiplyNode = AstNode(AST_MULTIPLY,p[1].lineNo,p[1].linePos); multiplyNode.addChildren([to_assign_to,to_assign_with]); p[0].addChild(multiplyNode);
def p_PlusEqual(p): ''' PlusEqual : OperatableOn PLUS_EQUAL ReturnableExpression ''' to_assign_to = p[1] to_assign_with = p[3] p[0] = AstNode( AST_ASSIGNMENT_STATEMENT,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to = AstNode( AST_OPERATABLE_ON_COMMA_LIST,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to.addChild(to_assign_to) p[0].addChild(list_to_assign_to); plusNode = AstNode(AST_PLUS,p[1].lineNo,p[1].linePos); plusNode.addChildren([to_assign_to,to_assign_with]); p[0].addChild(plusNode);
def p_DivideEqual(p): ''' DivideEqual : OperatableOn DIVIDE_EQUAL ReturnableExpression ''' to_assign_to = p[1] to_assign_with = p[3] p[0] = AstNode( AST_ASSIGNMENT_STATEMENT,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to = AstNode( AST_OPERATABLE_ON_COMMA_LIST,to_assign_to.lineNo,to_assign_to.linePos) list_to_assign_to.addChild(to_assign_to) p[0].addChild(list_to_assign_to); divideNode = AstNode(AST_DIVIDE,p[1].lineNo,p[1].linePos); divideNode.addChildren([to_assign_to,to_assign_with]); p[0].addChild(divideNode);
def p_Bool(p): '''Bool : TRUE | FALSE''' p[0] = AstNode(AST_BOOL,p.lineno(1),p.lexpos(1),p[1]); p[0].type = TYPE_BOOL;
def p_String(p): '''String : MULTI_LINE_STRING | SINGLE_LINE_STRING'''; p[0] = AstNode(AST_STRING,p.lineno(1),p.lexpos(1),p[1]); p[0].type = TYPE_STRING;