summaryrefslogtreecommitdiff
path: root/src/reduce.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2017-07-26 11:47:49 -0400
committerAdrian Thurston <thurston@colm.net>2017-07-26 15:03:23 -0400
commit1395ab646772f3c37e3fbad207d9f12a9d3f3140 (patch)
tree8e610b0670535fd772683683f68d9046f83f6f1a /src/reduce.cc
parent2fcb7bac46eb4b9e1ed7f133dea62370867a0d0e (diff)
downloadcolm-1395ab646772f3c37e3fbad207d9f12a9d3f3140.tar.gz
read-reduce: unescape token data to get proper pass throuh
Diffstat (limited to 'src/reduce.cc')
-rw-r--r--src/reduce.cc27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/reduce.cc b/src/reduce.cc
index 953dc652..4b6fa230 100644
--- a/src/reduce.cc
+++ b/src/reduce.cc
@@ -660,6 +660,31 @@ void Compiler::writeCommit()
" read_reduce_node *child;\n"
"};\n"
"\n"
+ "void unescape( colm_data *tokdata )\n"
+ "{\n"
+ " unsigned char *src = (unsigned char*)tokdata->data, *dest = (unsigned char*)tokdata->data;\n"
+ " while ( *src != 0 ) {\n"
+ " if ( *src == '\\\\' ) {\n"
+ " unsigned int i;\n"
+ " char buf[3];\n"
+ "\n"
+ " src += 1;\n"
+ " buf[0] = *src++;\n"
+ " buf[1] = *src++;\n"
+ " buf[2] = 0;\n"
+ "\n"
+ " sscanf( buf, \"%x\", &i );\n"
+ " *dest++ = (unsigned char)i;\n"
+ "\n"
+ " tokdata->length -= 2;\n"
+ " }\n"
+ " else {\n"
+ " *dest++ = *src++;\n"
+ " }\n"
+ " }\n"
+ " *dest = 0;\n"
+ "}\n"
+ "\n"
"void " << reduction->name << "::read_reduce_forward( program_t *prg )\n"
"{\n"
" std::ifstream in( \"postfix.txt\" );\n"
@@ -681,6 +706,7 @@ void Compiler::writeCommit()
" node->loc.byte = byte;\n"
" node->data.data = strdup( text.c_str() );\n"
" node->data.length = text.size();\n"
+ " unescape( &node->data );\n"
"\n"
" node->next = stack;\n"
" node->child = 0;\n"
@@ -688,7 +714,6 @@ void Compiler::writeCommit()
" }\n"
" else if ( type == \"r\" ) {\n"
" in >> tok >> _id >> prod_num >> children;\n"
- " std::cout << \"reducing: \" << tok << std::endl;\n"
" read_reduce_node *node = new read_reduce_node;\n"
" memset( &node->loc, 0, sizeof(colm_location) );\n"
" memset( &node->data, 0, sizeof(colm_data) );\n"