Permalink
Browse files

初步

  • Loading branch information...
1 parent eef43d2 commit 4cda7a3746eef84892cc53fc9de06662a2d4a574 @jiyinyiyong jiyinyiyong committed Mar 30, 2012
Showing with 43 additions and 7 deletions.
  1. +2 −0 .gitignore
  2. +26 −3 clear.coffee
  3. +8 −1 source.cln
  4. +7 −3 target.c
View
@@ -0,0 +1,2 @@
+
+*.out
View
@@ -30,7 +30,7 @@ converter = (source) ->
if image?
f_head = image[1]
f_argv = image[2]
- target_code = f_head + '(' + f_argv + ');'
+ target_code = f_head + ' (' + f_argv + ');'
code.push target_code
return true
false
@@ -50,7 +50,7 @@ converter = (source) ->
if image?
func_name = image[1]
func_argv = image[2].trim()
- define_sentence = func_name + '(' + func_argv + '){'
+ define_sentence = func_name + ' (' + func_argv + '){'
exp = define_sentence.replace /:/g, ' '
code.push exp
return true
@@ -61,13 +61,36 @@ converter = (source) ->
if image?
front = image[1]
back = image[2]
- exp = front + ' ' + back + ';'
+ exp = "#{front} #{back};"
+ code.push exp
+ return true
+ false
+
+ detect_assign = (item) ->
+ image = item.match /^(\s+[a-zA-Z_]+)\s*=\s*(.*)$/
+ if image?
+ front = image[1]
+ back = image[2]
+ exp = "#{front} = #{back};"
+ code.push exp
+ return true
+ false
+
+ detect_mix_define = (item) ->
+ image = item.match /^(\s+[a-zA-Z]+):\s*([a-zA-Z_]+)\s*=\s*(.*)$/
+ if image?
+ front = image[1]
+ middle = image[2]
+ back = image[3]
+ exp = "#{front} #{middle} = #{back};"
code.push exp
return true
false
for item, index in source
item = do item.trimRight
+ continue if detect_mix_define item
+ continue if detect_assign item
continue if detect_include item
continue if detect_function item
continue if detect_return item
View
@@ -2,6 +2,13 @@
#include stdio.h
int:main :: void:
- char: dd, go
+
+ char: firstLetter = 'a'
+ int: hour = 11, minute = 59
+
+ int: total, total_minute
+ total = total_minute = hour * 60 + minute
+
+ printf "current time is %d:%d", hour, minute
printf "hello world"
=> 0
View
@@ -1,6 +1,10 @@
#include <stdio.h>
-int main(void ){
- char dd, go;
- printf("hello world");
+int main (void ){
+ char firstLetter = 'a';
+ int hour = 11, minute = 59;
+ int total, total_minute;
+ total = total_minute = hour * 60 + minute;
+ printf ("current time is %d:%d", hour, minute);
+ printf ("hello world");
return 0;
}

0 comments on commit 4cda7a3

Please sign in to comment.