summaryrefslogtreecommitdiff
path: root/crenshaw/main.pas
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-08-11 16:10:03 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-08-11 16:10:03 +0200
commit0300971e3bb7efa727c35ef54203a8ffe00eba9a (patch)
treed7633f8fae3b279209651f25dd00ab310a26b635 /crenshaw/main.pas
parent3f7d123bbcc1611b37e5e3ea5777177ed0ef0aa8 (diff)
downloadcompilertests-0300971e3bb7efa727c35ef54203a8ffe00eba9a.tar.gz
compilertests-0300971e3bb7efa727c35ef54203a8ffe00eba9a.tar.bz2
a first tutorial2 expression output
Diffstat (limited to 'crenshaw/main.pas')
-rw-r--r--crenshaw/main.pas51
1 files changed, 50 insertions, 1 deletions
diff --git a/crenshaw/main.pas b/crenshaw/main.pas
index 3adc53b..a5f42ae 100644
--- a/crenshaw/main.pas
+++ b/crenshaw/main.pas
@@ -63,9 +63,58 @@ end;
procedure EmitLn(s : string);
begin
- WriteLn;
Emit(s);
+ WriteLn;
+end;
+
+
+procedure Term;
+begin
+ EmitLn('mov eax, ' + GetNum);
+end;
+
+procedure Add;
+begin;
+ Match('+');
+ Term;
+ EmitLn('add eax, ebx');
+end;
+
+procedure Subtract;
+begin;
+ Match('-');
+ Term;
+ EmitLn('sub eax, ebx');
+end;
+
+procedure Expression;
+begin
+ Term;
+ EmitLn('mov ebx, eax');
+ case Look of
+ '+': Add;
+ '-': Subtract;
+ else Expected('+/-');
+ end;
+end;
+
+procedure Init;
+begin
+ GetChar;
+end;
+
+procedure Prologue;
+begin
+ EmitLn('[bits 32]');
+end;
+
+procedure Epilogue;
+begin
end;
begin
+ Prologue;
+ Init;
+ Expression;
+ Epilogue;
end.