summaryrefslogtreecommitdiff
path: root/crenshaw
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2018-08-31 13:10:59 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2018-08-31 13:10:59 +0200
commitc5c75d786de3e6d21ec146df9e043896feb8dfba (patch)
tree5eb472fc0622c8a00226652b5f6b90a545401727 /crenshaw
parent21f6eb821811cd3c93cb6604da236a44d47e0749 (diff)
downloadcompilertests-c5c75d786de3e6d21ec146df9e043896feb8dfba.tar.gz
compilertests-c5c75d786de3e6d21ec146df9e043896feb8dfba.tar.bz2
.
Diffstat (limited to 'crenshaw')
-rw-r--r--crenshaw/README7
-rw-r--r--crenshaw/main.pas43
-rw-r--r--crenshaw/test.prog8
3 files changed, 51 insertions, 7 deletions
diff --git a/crenshaw/README b/crenshaw/README
index dbe62d6..244c0be 100644
--- a/crenshaw/README
+++ b/crenshaw/README
@@ -43,9 +43,16 @@ https://github.com/Rewzilla/asemu.git
http://www.unicorn-engine.org/
http://www.capstone-engine.org/
+https://github.com/lotabout/Let-s-build-a-compiler.git
+
findings
--------
+general: doesn't follow the normal path
+
+I personally don't like the omition of a scanner, as a scanner helps
+to deal with weird issues I encountered, like when parsing conditions.
+
tutor2:
the expression and data stacks should be better explained and
diff --git a/crenshaw/main.pas b/crenshaw/main.pas
index 1db3faf..e79878d 100644
--- a/crenshaw/main.pas
+++ b/crenshaw/main.pas
@@ -4,7 +4,9 @@ const
TAB = ^I;
LF = ^J;
-var Look : char;
+var
+ Look : char;
+ LCount : integer;
procedure Error(s : string);
begin
@@ -107,6 +109,15 @@ begin
WriteLn;
end;
+function NewLabel : string;
+var
+ s : string;
+begin
+ Str(LCount, s);
+ NewLabel := 'L'+s;
+ Inc(LCount);
+end;
+
procedure EmitLabel(s : string);
begin
WriteLn(s+':');
@@ -117,7 +128,7 @@ begin
WriteLn('; '+s);
end;
-procedure Expression; Forward;
+procedure Expression; forward;
type
symbolType = ( variableType = 1, functionType = 2 );
@@ -254,6 +265,7 @@ end;
procedure Init;
begin
nof_symbols := 0;
+ LCount := 0;
GetChar;
SkipWhite;
end;
@@ -319,10 +331,33 @@ begin
end;
end;
+procedure Block; forward;
+
+procedure Condition;
+begin
+ EmitComment('Condition: '+GetName);
+end;
+
+procedure DoIf;
+var
+ L : string;
+begin
+ Match('i');
+ L := NewLabel;
+ Condition;
+ EmitLn('jz '+L);
+ Block;
+ Match('e');
+ EmitLabel(L);
+end;
+
procedure Block;
-begin;
+begin
while not(Look in ['e']) do begin
- Other;
+ case Look of
+ 'i': DoIf;
+ 'o': Other;
+ end;
end;
end;
diff --git a/crenshaw/test.prog b/crenshaw/test.prog
index 2d501ed..1040b29 100644
--- a/crenshaw/test.prog
+++ b/crenshaw/test.prog
@@ -1,5 +1,7 @@
-a = 1
-b = 2
-x = ( 4 + 4 + 12 ) * 3 / 2 - 3 + a - b * func1( )
+i a t
+ o a = 1
+ o b = 2
+ o x = ( 4 + 4 + 12 ) * 3 / 2 - 3 + a - b * func1( )
+e
e