diff --git a/simc-codes/char-input-test.simc b/simc-codes/char-input-test.simc new file mode 100644 index 0000000..6a01a39 --- /dev/null +++ b/simc-codes/char-input-test.simc @@ -0,0 +1,4 @@ +MAIN + var c = input("Enter a character: ","c") + print(c) +END_MAIN diff --git a/simc/compiler.py b/simc/compiler.py index 386d654..58d0984 100644 --- a/simc/compiler.py +++ b/simc/compiler.py @@ -118,8 +118,8 @@ def compile(opcodes, c_filename, table): _, dtype, _ = table.get_by_id(table.get_by_symbol(val[0])) # Helper Dictionaries - get_data_type = {"i": "int", "s": "char*", "f": "float", "d": "double"} - get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf"} + get_data_type = {"i": "int", "s": "char*", "f": "float", "d": "double", "c": "char"} + get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf", "c": "c"} # If it is of string type then change it to char [] if dtype == "string": @@ -153,8 +153,8 @@ def compile(opcodes, c_filename, table): _, dtype, _ = table.get_by_id(table.get_by_symbol(val[0])) # Helper Dictionaries - get_data_type = {"i": "int", "s": "char*", "f": "float", "d": "double"} - get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf"} + get_data_type = {"i": "int", "s": "char*", "f": "float", "d": "double", "c": "char"} + get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf", "c": "c"} # If it is of string type then change it to char [] if dtype == "string": @@ -212,8 +212,8 @@ def compile(opcodes, c_filename, table): # val contains - ---, split that into a list val = opcode.val.split("---") # Helper Dictionaries - get_data_type = {"i": "int", "s": "char *", "f": "float", "d": "double"} - get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf"} + get_data_type = {"i": "int", "s": "char *", "f": "float", "d": "double", "c": "char"} + get_placeholder = {"i": "d", "s": "s", "f": "f", "d": "lf", "c": "c"} # Check if the statement is of type input or not if len(val) == 3: code += "\t" + val[0] + " " + val[1] + " " + val[2] + ";\n" diff --git a/simc/parser/simc_parser.py b/simc/parser/simc_parser.py index 9cd4889..92aca23 100644 --- a/simc/parser/simc_parser.py +++ b/simc/parser/simc_parser.py @@ -193,7 +193,7 @@ def expression( else: p_msg = "" dtype = "s" - dtype_to_prec = {"i": 3, "f": 4, "d": 5, "s": 1} + dtype_to_prec = {"i": 3, "f": 4, "d": 5, "s": 1, "c": 2} op_value = str(p_msg) + "---" + str(dtype) op_type = dtype_to_prec[dtype] # Return the expression, type of expression, and current index in source codes @@ -676,4 +676,4 @@ def parse(tokens, table): error("No matching MAIN for END_MAIN", tokens[i-1].line_num + 1) # Return opcodes - return op_codes \ No newline at end of file + return op_codes