Browse Source

update makefile and add an example

AbderFaiz 5 months ago
parent
commit
6b464dfa7b
2 changed files with 16 additions and 3 deletions
  1. 3 3
      Makefile
  2. 13 0
      examples/reverse

+ 3 - 3
Makefile

@@ -3,6 +3,8 @@ FLAGS = -Wall
 EXAMPLE = examples/factorial
 
 all: test.out
+	./$< $(EXAMPLE)
+	$(CC) out.c
 
 Token.o : src/Token.cpp src/Token.hpp
 	$(CC) -c $(FLAGS) $< 
@@ -21,12 +23,10 @@ Parser.o : src/Parser.cpp src/Parser.hpp Lexer.o Token.o Symbol.o Emitter.o
 
 test.out: src/main.cpp Token.o Lexer.o Parser.o Symbol.o Emitter.o
 	$(CC) $(FLAGS) $^ -o $@
-	./$@ $(EXAMPLE)
-	$(CC) out.c
 
 exec: test.out
 	./a.out
 	
 
 clean:
-	rm -f test.out *.o
+	rm -f *.o *.out *.c

+ 13 - 0
examples/reverse

@@ -0,0 +1,13 @@
+PRINT "Enter a number to reverse:"
+INPUT num
+PRINT ""
+
+LET reversed = 0
+WHILE num > 0 REPEAT
+    LET digit = num MOD 10
+    LET reversed = reversed * 10 + digit
+    LET num = num \ 10
+ENDWHILE
+
+PRINT "The reversed number is:"
+PRINT reversed