diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2018-08-11 14:40:38 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2018-08-11 14:40:38 +0200 |
commit | 3f7d123bbcc1611b37e5e3ea5777177ed0ef0aa8 (patch) | |
tree | 6dde94bfc0b27d7652bbeff8f1ec06fa40c3a240 /crenshaw | |
parent | 02cb3b2447e24b95a8b6203b28e0d78ebb0a3d87 (diff) | |
download | compilertests-3f7d123bbcc1611b37e5e3ea5777177ed0ef0aa8.tar.gz compilertests-3f7d123bbcc1611b37e5e3ea5777177ed0ef0aa8.tar.bz2 |
first step crenshaw
Diffstat (limited to 'crenshaw')
-rw-r--r-- | crenshaw/main.pas | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/crenshaw/main.pas b/crenshaw/main.pas new file mode 100644 index 0000000..3adc53b --- /dev/null +++ b/crenshaw/main.pas @@ -0,0 +1,71 @@ +program Main; + +const TAB = ^I; + +var Look : char; + +procedure Error(s : string); +begin + WriteLn; + WriteLn(^G, 'Error: ', s, '.'); +end; + +procedure GetChar; +begin + Read(Look); +end; + +procedure Abort(s : string); +begin + Error(s); + Halt; +end; + +procedure Expected(s : string); +begin + Abort(s + ' expected'); +end; + +procedure Match(c : char); +begin + if c = Look then GetChar + else Expected('''' + c + ''''); +end; + +function IsAlpha(c : char) : boolean; +begin + IsAlpha := upcase(c) in ['A'..'Z']; +end; + +function IsDigit(c : char) : boolean; +begin + IsDigit := c in ['0'..'9']; +end; + +function GetName : char; +begin + if not IsAlpha(Look) then Expected('Name'); + GetName := UpCase(Look); + GetChar; +end; + +function GetNum : char; +begin + if not IsDigit(Look) then Expected('Integer'); + GetNum := Look; + GetChar; +end; + +procedure Emit(s : string); +begin + Write(TAB, s); +end; + +procedure EmitLn(s : string); +begin + WriteLn; + Emit(s); +end; + +begin +end. |