Beispiel #1
0
def p_BooleanOperator(p):
    '''BooleanOperator : AND
                       | OR
                       | BOOL_EQUALS
                       | BOOL_NOT_EQUALS
                       | GREATER_THAN
                       | GREATER_THAN_EQ
                       | LESS_THAN
                       | LESS_THAN_EQ
                       '''

    if (p[1] == 'and'):
        p[0] = AstNode(AST_AND,p.lineno(1),p.lexpos(1));
    elif(p[1] == 'or'):
        p[0] = AstNode(AST_OR,p.lineno(1),p.lexpos(1));
    elif(p[1] == '=='):
        p[0] = AstNode(AST_BOOL_EQUALS,p.lineno(1),p.lexpos(1));
    elif(p[1] == '!='):
        p[0] = AstNode(AST_BOOL_NOT_EQUALS,p.lineno(1),p.lexpos(1));
    elif(p[1] == '>'):
        p[0] = AstNode(AST_GREATER_THAN,p.lineno(1),p.lexpos(1));
    elif(p[1] == '>='):
        p[0] = AstNode(AST_GREATER_THAN_EQ,p.lineno(1),p.lexpos(1));
    elif(p[1] == '<'):
        p[0] = AstNode(AST_LESS_THAN,p.lineno(1),p.lexpos(1));
    elif(p[1] == '<='):
        p[0] = AstNode(AST_LESS_THAN_EQ,p.lineno(1),p.lexpos(1));        
    else:
        errPrint('\nIncorrect boolean operator: ' + p[1] + '\n');
        assert(False);
Beispiel #2
0
def p_MultDivOperator(p):
    '''MultDivOperator : MULTIPLY
                       | DIVIDE'''

    if (p[1] == '*'):
        p[0] = AstNode(AST_MULTIPLY, p.lineno(1),p.lexpos(1));
    elif(p[1] == '/'):
        p[0] = AstNode(AST_DIVIDE, p.lineno(1),p.lexpos(1));
    else:
        errPrint('\nIncorrect number of matches in MultDivOperator\n');
        assert(False);
Beispiel #3
0
def p_PlusMinusOperator(p):
    '''PlusMinusOperator : PLUS
                         | MINUS'''

    if (p[1] == '+'):
        p[0] = AstNode(AST_PLUS, p.lineno(1),p.lexpos(1));
    elif(p[1] == '-'):
        p[0] = AstNode(AST_MINUS, p.lineno(1),p.lexpos(1));
    else:
        errPrint('\nIncorrect number of matches in PlusMinusOperator\n');
        assert(False);
Beispiel #4
0
def p_FunctionBody(p):
    '''FunctionBody : FunctionBody FunctionBodyStatement
                    | FunctionBodyStatement'''
    p[0] = AstNode(AST_FUNCTION_BODY, p[1].lineNo,p[1].linePos);
    if (len(p) == 3):
        p[0].addChildren(p[1].getChildren());
        p[0].addChild(p[2]);
    elif (len(p) == 2):
        p[0].addChild(p[1]);
    else:
        errPrint('\nError statement length mismatch in FunctionBody\n');
        assert(False);
Beispiel #5
0
def p_MultDivStatement(p):
    '''MultDivStatement : OperatableOn MultDivOperator MultDivStatement
                        | OperatableOn'''

    if(len(p) == 4):
        p[0] = p[2];
        p[0].addChildren([p[1],p[3]]);
    elif(len(p) == 2):
        p[0] = p[1];
    else:
        errPrint('\nIncorrect number of matches in MultDivStatement\n');
        assert(False);
Beispiel #6
0
def p_ParenthesizedExpression(p):
    '''ParenthesizedExpression : NOT ReturnableExpression
                               | InExpression
    '''
    
    if (len(p) == 3):
        p[0] = AstNode(AST_NOT_EXPRESSION, p.lineno(1),p.lexpos(1));
        p[0].addChild(p[2]);
    elif(len(p) == 2):
        p[0] = p[1];
    else:
        errPrint('\nIncorrect matching in ReturnableExpression\n');
        assert(False);
Beispiel #7
0
def p_ElseStatement(p):
    '''ElseStatement : Empty
                     | ELSE SingleLineOrMultilineCurliedBlock '''

    if (len(p) == 3):
        p[0] = AstNode(AST_ELSE_STATEMENT,p.lineno(0),p.lexpos(0));
        p[0].addChild(p[2]);
    elif(len(p) == 2):
        p[0] = AstNode(AST_ELSE_STATEMENT,p[1].lineNo,p[1].linePos);

    else:
        errPrint('\nIncorrect match count in ElseStatement.\n');
        assert(False);
Beispiel #8
0
def p_FunctionTypeList(p):
    '''
    FunctionTypeList : Type
                     | FunctionTypeList COMMA Type
    '''
    p[0] = AstNode(AST_FUNCTION_TYPE_LIST,p[1].lineNo,p[1].linePos);
    if (len(p) == 4):
        p[0].addChildren(p[1].getChildren());
        p[0].addChild(p[3]);
    elif(len(p) == 2):
        p[0].addChild(p[1]);
    else:
        errPrint('\nError in TypeList.  Unexpected length to match\n');
        assert(False);
Beispiel #9
0
def p_StructSection(p):
    '''
    StructSection : Struct
                  | StructSection Struct
    '''
    
    p[0] = AstNode(AST_STRUCT_SECTION,p[1].lineNo,p[1].linePos)
    if len(p) == 3:
        p[0].addChildren(p[1].getChildren())
        p[0].addChild(p[2])
    elif len(p) == 2:
        p[0].addChild(p[1])
    else:
        errPrint('\nError in StructSection.  Unexpected length to match.\n')
Beispiel #10
0
def p_NonBooleanStatement(p):
    '''NonBooleanStatement : MultDivStatement PlusMinusOperator NonBooleanStatement
                           | MultDivStatement
                           | NonOperatableOn
                           '''

    if(len(p) == 4):
        p[0] = p[2];
        p[0].addChildren([p[1],p[3]]);
    elif(len(p) == 2):
        p[0] = p[1];
    else:
        errPrint('\nIncorrect number of matches in NonBooleanStatement\n');
        assert(False);
Beispiel #11
0
def p_BooleanStatement(p):
    '''BooleanStatement : NonBooleanStatement BooleanOperator BooleanStatement
                        | NonBooleanStatement'''

    #skip over internal_returnable_expression label
    if (len(p) == 2):
        p[0] = p[1];
    elif (len(p) == 4):
        p[0] = p[2];
        p[0].addChild(p[1]);
        p[0].addChild(p[3]);
    else:
        errPrint('\nIn BooleanStatement, incorrect number of matches\n');
        assert(False);
Beispiel #12
0
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;
Beispiel #13
0
def p_FunctionDeclArgList(p):
    '''FunctionDeclArgList : FunctionDeclArg 
                           | FunctionDeclArgList COMMA FunctionDeclArg
                           | Empty'''

    p[0] = AstNode(AST_FUNCTION_DECL_ARGLIST,p[1].lineNo,p[1].linePos);
    if (len(p) == 4):
        p[0].addChildren(p[1].getChildren());
        p[0].addChild(p[3]);
    elif(len(p) == 2):
        if (not isEmptyNode(p[1])):
            p[0].addChild(p[1]);
    else:
        errPrint('\nError in FunctionDeclArgList.  Unexpected length to match\n');
        assert(False);
Beispiel #14
0
def p_ReturnableExpression(p):
    '''ReturnableExpression : LEFT_PAREN ReturnableExpression RIGHT_PAREN BinaryOperator ReturnableExpression
                            | ParenthesizedExpression
                            | LEFT_PAREN ReturnableExpression RIGHT_PAREN 
    '''

    if (len(p) == 6):
        p[0] = p[4];
        p[4].addChildren([p[2],p[5]]);
    elif(len(p) == 2):
        p[0] = p[1];
    elif(len(p) == 4):
        p[0] = p[2];
    else:
        errPrint('\nIncorrect number of matches in ReturnableExpression\n');
        assert(False);
Beispiel #15
0
def p_SingleLineOrMultilineCurliedBlock(p):
    '''SingleLineOrMultilineCurliedBlock :  FunctionBodyStatement
                                         |  CURLY_LEFT FunctionBody CURLY_RIGHT
                                         |  CURLY_LEFT CURLY_RIGHT
    '''; 
    

    if (len(p) == 2):
        p[0] = AstNode(AST_FUNCTION_BODY,p[1].lineNo,p[1].linePos);
        p[0].addChild(p[1]);        
    elif(len(p) == 4):
        p[0] = p[2];
    elif(len(p) == 3):
        p[0] = AstNode(AST_EMPTY);
    else:
        errPrint('\nIncorrect match vector in SingleLineOrMultilineCurliedBlock\n');
        assert(False);
Beispiel #16
0
def p_OperatableOnCommaList(p):
    '''
    OperatableOnCommaList : OperatableOn
                          | OperatableOnCommaList COMMA OperatableOn
                          | Empty
    '''

    p[0] = AstNode(AST_OPERATABLE_ON_COMMA_LIST,p[1].lineNo,p[1].linePos);
    if (len(p) == 4):
        p[0].addChildren(p[1].getChildren());
        p[0].addChild(p[3]);
    elif(len(p) == 2):
        if (not isEmptyNode(p[1])):
            p[0].addChild(p[1]);
    else:
        errPrint('\nError in OperatableOnCommaList.  Unexpected length to match\n');
        assert(False);
Beispiel #17
0
def p_ListLiteralItemList(p):
    '''ListLiteralItemList : ReturnableExpression 
                           | ReturnableExpression COMMA ListLiteralItemList 
                           | Empty'''

    # this will produce a reversed list.  ensure to re-reverse when
    # use in list.
    p[0] = AstNode(AST_LIST_INTERMEDIATE,p[1].lineNo,p[1].linePos);
    if (len(p) == 4):
        # second line
        p[0].addChildren(p[3].getChildren());
        p[0].addChild(p[1]);
    elif(len(p) == 2):
        if (not isEmptyNode(p[1])):
            # first line
            p[0].addChild(p[1]);
    else:
        errPrint('\nError in ListLiteralItemList.  Unexpected length to match\n');
        assert(False);
Beispiel #18
0
def p_EndpointBodySection(p):
    '''EndpointBodySection : EndpointGlobalSection EndpointFunctionSection
                           | EndpointFunctionSection
                           | EndpointGlobalSection
                           '''

    p[0] = AstNode(AST_ENDPOINT_BODY_SECTION,p[1].lineNo,p[1].linePos);
    if (len(p) == 3):
        p[0].addChildren([p[1],p[2]]);
    elif len(p) == 2:
        # check that had no globals, but had a function:
        if p[1].label == AST_ENDPOINT_FUNCTION_SECTION:
            # means that we had no globals.  add them
            p[0].addChild(AstNode(AST_ENDPOINT_GLOBAL_SECTION, p[1].lineNo,p[1].linePos));
            p[0].addChild(p[1]);
        else:
            # menas that there were globals, but no functions.  add
            # empty functions.
            p[0].addChild(p[1]);
            p[0].addChild(AstNode(AST_ENDPOINT_FUNCTION_SECTION,p[1].lineNo,p[1].linePos));
    else:
        errPrint('\nError in endpoint body section.  Got an unusual number of arguments.\n');
        assert(False);