calculator.lemon
branchcalculator-experiment
changeset 824 f4b3ba2b435d
parent 823 48757134a880
child 826 59a6a8aa7d87
equal deleted inserted replaced
823:48757134a880 824:f4b3ba2b435d
    70 %right ELSE.
    70 %right ELSE.
    71 
    71 
    72 
    72 
    73 // The rules...
    73 // The rules...
    74 
    74 
       
    75 %type calculator { int }                // !!! FIXME: remove this later.
       
    76 %destructor calculator { (void) ctx; }  // !!! FIXME: remove this later.
    75 calculator ::= expression(B). { parse_complete(ctx, B); }
    77 calculator ::= expression(B). { parse_complete(ctx, B); }
    76 
       
    77 // !!! FIXME: why is this a non-terminal?
       
    78 %type identifier { TokenData }
       
    79 %destructor identifier { (void) ctx; }  // !!! FIXME: remove this later, it's just to shut up the compiler for now.
       
    80 identifier(A) ::= IDENTIFIER(B). { A = B; }
       
    81 
    78 
    82 // 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.
    83 %type primary_expr { Expression * }
    80 %type primary_expr { Expression * }
    84 primary_expr(A) ::= identifier(B). { A = new_identifier_expr(ctx, &B); }
    81 primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, &B); }
    85 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); }
    86 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); }
    87 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); }
    88 primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
    85 primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }
    89 
    86 
    91 postfix_expr(A) ::= primary_expr(B). { A = B; }
    88 postfix_expr(A) ::= primary_expr(B). { A = B; }
    92 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); }
    93 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); }
    94 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); }
    95 //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
    96 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)); }
    97 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); }
    98 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); }
    99 
    96 
   100 %type argument_expr_list { Expression * }
    97 %type argument_expr_list { Expression * }
   101 argument_expr_list(A) ::= assignment_expr(B). { A = B; }
    98 argument_expr_list(A) ::= assignment_expr(B). { A = B; }