Skip to content

Commit

Permalink
Merge pull request #411 from yashshah14093/in-370
Browse files Browse the repository at this point in the history
PR for issue #370
  • Loading branch information
frankhart2018 authored Dec 15, 2020
2 parents 82519ed + c608f5f commit cbc9738
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions simc-codes/char-input-test.simc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MAIN
var c = input("Enter a character: ","c")
print(c)
END_MAIN
12 changes: 6 additions & 6 deletions simc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <identifier>[]
if dtype == "string":
Expand Down Expand Up @@ -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 <identifier>[]
if dtype == "string":
Expand Down Expand Up @@ -212,8 +212,8 @@ def compile(opcodes, c_filename, table):
# val contains - <identifier>---<expression>, 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"
Expand Down
4 changes: 2 additions & 2 deletions simc/parser/simc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
return op_codes

0 comments on commit cbc9738

Please sign in to comment.