Commit 4ef72124 authored by Brice Videau's avatar Brice Videau

Added expression associativity.

parent ac3fe37e
......@@ -27,13 +27,28 @@ module CCS
end
end
AssociativityType = enum FFI::Type::INT32, :ccs_associativity_type_t, [
:CCS_ASSOCIATIVITY_NONE, 0,
:CCS_LEFT_TO_RIGHT,
:CCS_RIGHT_TO_LEFT
]
class MemoryPointer
def read_ccs_associativity_type_t
AssociativityType.from_native(read_int32, nil)
end
end
attach_variable :expression_precedence, :ccs_expression_precedence, FFI::ArrayType::new(find_type(:int), ExpressionType.symbol_map.size)
attach_variable :expression_associativity, :ccs_expression_associativity, FFI::ArrayType::new(find_type(:ccs_associativity_type_t), ExpressionType.symbol_map.size)
attach_variable :expression_symbols, :ccs_expression_symbols, FFI::ArrayType::new(find_type(:string), ExpressionType.symbol_map.size)
attach_variable :expression_arity, :ccs_expression_arity, FFI::ArrayType::new(find_type(:int), ExpressionType.symbol_map.size)
ExpressionPrecedence = ExpressionType.symbol_map.collect { |k, v|
[k, expression_precedence[v]]
}.to_h
ExpressionAssociativity = ExpressionType.symbol_map.collect { |k, v|
[k, expression_associativity[v]]
}.to_h
ExpressionSymbols = ExpressionType.symbol_map.collect { |k, v|
p = expression_symbols[v]
[k, p]
......
......@@ -48,6 +48,18 @@ typedef enum ccs_expression_type_e ccs_expression_type_t;
// One for each expression type:
extern const int ccs_expression_precedence[];
enum ccs_associativity_type_e {
CCS_ASSOCIATIVITY_TYPE_NONE = 0,
CCS_LEFT_TO_RIGHT,
CCS_RIGHT_TO_LEFT,
CCS_ASSOCIATIVITY_TYPE_MAX,
CCS_ASSOCIATIVITY_TYPE_FORCE_32BIT = INT_MAX
};
typedef enum ccs_associativity_type_e ccs_associativity_type_t;
extern const ccs_associativity_type_t ccs_expression_associativity[];
extern const char *ccs_expression_symbols[];
extern const int ccs_expression_arity[];
......
......@@ -17,6 +17,19 @@ const int ccs_expression_precedence[] = {
9, 9
};
const ccs_associativity_type_t ccs_expression_associativity[] = {
CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT,
CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT, CCS_LEFT_TO_RIGHT,
CCS_RIGHT_TO_LEFT, CCS_RIGHT_TO_LEFT, CCS_RIGHT_TO_LEFT,
CCS_LEFT_TO_RIGHT,
CCS_ASSOCIATIVITY_TYPE_NONE, CCS_ASSOCIATIVITY_TYPE_NONE
};
const char *ccs_expression_symbols[] = {
"||",
"&&",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment