calculator.lemon
branchcalculator-experiment
changeset 826 59a6a8aa7d87
parent 824 f4b3ba2b435d
equal deleted inserted replaced
825:1ec9b7cc9434 826:59a6a8aa7d87
    76 %destructor calculator { (void) ctx; }  // !!! FIXME: remove this later.
    76 %destructor calculator { (void) ctx; }  // !!! FIXME: remove this later.
    77 calculator ::= expression(B). { parse_complete(ctx, B); }
    77 calculator ::= expression(B). { parse_complete(ctx, B); }
    78 
    78 
    79 // the expression stuff is based on Jeff Lee's ANSI C grammar.
    79 // the expression stuff is based on Jeff Lee's ANSI C grammar.
    80 %type primary_expr { Expression * }
    80 %type primary_expr { Expression * }
    81 primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, &B); }
    81 primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, B.string); }
    82 primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, &B); }
    82 primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, B.i64); }
    83 primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, &B); }
    83 primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, B.dbl); }
    84 primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, &B); }
    84 primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, B.string); }
    85 primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
    85 primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
    86 
    86 
    87 %type postfix_expr { Expression * }
    87 %type postfix_expr { Expression * }
    88 postfix_expr(A) ::= primary_expr(B). { A = B; }
    88 postfix_expr(A) ::= primary_expr(B). { A = B; }
    89 postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, OP_DEREF_ARRAY, B, C); }
    89 postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_binary_expr(ctx, OP_DEREF_ARRAY, B, C); }
    90 postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, NULL); }
    90 postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, NULL); }
    91 postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, C); }
    91 postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, C); }
    92 //postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
    92 //postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
    93 postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, OP_DEREF_STRUCT, B, new_identifier_expr(ctx, &C)); }
    93 postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, OP_DEREF_STRUCT, B, new_identifier_expr(ctx, C.string)); }
    94 postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, OP_POSTINCREMENT, B); }
    94 postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, OP_POSTINCREMENT, B); }
    95 postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, OP_POSTDECREMENT, B); }
    95 postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, OP_POSTDECREMENT, B); }
    96 
    96 
    97 %type argument_expr_list { Expression * }
    97 %type argument_expr_list { Expression * }
    98 argument_expr_list(A) ::= assignment_expr(B). { A = B; }
    98 argument_expr_list(A) ::= assignment_expr(B). { A = B; }