Transpile procedure declaration heading
This commit is contained in:
parent
46d89122e4
commit
24651e7c48
4
Rakefile
4
Rakefile
@ -102,9 +102,11 @@ task :backport do
|
|||||||
target = source
|
target = source
|
||||||
.gsub(/^(var|type|const)/) { |match| match.upcase }
|
.gsub(/^(var|type|const)/) { |match| match.upcase }
|
||||||
.gsub(/^[[:alnum:]]* ?module/) { |match| match.upcase }
|
.gsub(/^[[:alnum:]]* ?module/) { |match| match.upcase }
|
||||||
.gsub(/(procedure|record| pointer to )/) { |match| match.upcase }
|
.gsub(/(record| pointer to )/) { |match| match.upcase }
|
||||||
|
.gsub(/proc(\(| )/, 'PROCEDURE\1')
|
||||||
.gsub(/([[:space:]]*)end;/, '\1END;')
|
.gsub(/([[:space:]]*)end;/, '\1END;')
|
||||||
.gsub(/^from ([[:alnum:]]+) import/, 'FROM \1 IMPORT')
|
.gsub(/^from ([[:alnum:]]+) import/, 'FROM \1 IMPORT')
|
||||||
|
.gsub(/ \^([[:alnum:]])/, ' POINTER TO \1')
|
||||||
|
|
||||||
target_path = Pathname.new('boot/stage1/source') + source_path.basename
|
target_path = Pathname.new('boot/stage1/source') + source_path.basename
|
||||||
File.write target_path, target
|
File.write target_path, target
|
||||||
|
@ -60,7 +60,7 @@ type
|
|||||||
transitionStateDecimalSuffix,
|
transitionStateDecimalSuffix,
|
||||||
transitionStateEnd
|
transitionStateEnd
|
||||||
);
|
);
|
||||||
TransitionAction = procedure(PLexer, PLexerToken);
|
TransitionAction = proc(PLexer, PLexerToken);
|
||||||
Transition = record
|
Transition = record
|
||||||
Action: TransitionAction;
|
Action: TransitionAction;
|
||||||
NextState: TransitionState
|
NextState: TransitionState
|
||||||
@ -311,7 +311,7 @@ BEGIN
|
|||||||
AToken^.Kind := lexerKindWhile
|
AToken^.Kind := lexerKindWhile
|
||||||
ELSIF CompareKeyword('DO', ALexer^.Start, ALexer^.Current) THEN
|
ELSIF CompareKeyword('DO', ALexer^.Start, ALexer^.Current) THEN
|
||||||
AToken^.Kind := lexerKindDo
|
AToken^.Kind := lexerKindDo
|
||||||
ELSIF CompareKeyword('PROCEDURE', ALexer^.Start, ALexer^.Current) THEN
|
ELSIF CompareKeyword('PROCEDURE', ALexer^.Start, ALexer^.Current) OR CompareKeyword('proc', ALexer^.Start, ALexer^.Current) THEN
|
||||||
AToken^.Kind := lexerKindProc
|
AToken^.Kind := lexerKindProc
|
||||||
ELSIF CompareKeyword('BEGIN', ALexer^.Start, ALexer^.Current) THEN
|
ELSIF CompareKeyword('BEGIN', ALexer^.Start, ALexer^.Current) THEN
|
||||||
AToken^.Kind := lexerKindBegin
|
AToken^.Kind := lexerKindBegin
|
||||||
|
@ -7,7 +7,7 @@ from Terminal import Write, WriteLn, WriteString;
|
|||||||
from Lexer import Lexer, LexerToken, LexerCurrent, LexerLex, LexerKind;
|
from Lexer import Lexer, LexerToken, LexerCurrent, LexerLex, LexerKind;
|
||||||
|
|
||||||
type
|
type
|
||||||
PTranspilerContext = pointer to TranspilerContext;
|
PTranspilerContext = ^TranspilerContext;
|
||||||
TranspilerContext = record
|
TranspilerContext = record
|
||||||
Indentation: CARDINAL
|
Indentation: CARDINAL
|
||||||
end;
|
end;
|
||||||
@ -141,6 +141,7 @@ BEGIN
|
|||||||
TranspileConstantPart(AContext, ALexer);
|
TranspileConstantPart(AContext, ALexer);
|
||||||
TranspileTypePart(AContext, ALexer);
|
TranspileTypePart(AContext, ALexer);
|
||||||
TranspileVariablePart(AContext, ALexer);
|
TranspileVariablePart(AContext, ALexer);
|
||||||
|
TranspileProcedurePart(AContext, ALexer);
|
||||||
|
|
||||||
Token := LexerCurrent(ALexer);
|
Token := LexerCurrent(ALexer);
|
||||||
WHILE Token.Kind <> lexerKindEof DO
|
WHILE Token.Kind <> lexerKindEof DO
|
||||||
@ -190,8 +191,11 @@ VAR
|
|||||||
Token: LexerToken;
|
Token: LexerToken;
|
||||||
WrittenBytes: CARDINAL;
|
WrittenBytes: CARDINAL;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
Token := LexerCurrent(ALexer);
|
||||||
WriteString('POINTER TO ');
|
WriteString('POINTER TO ');
|
||||||
Token := TranspilerLex(ALexer);
|
IF Token.Kind = lexerKindPointer THEN
|
||||||
|
Token := TranspilerLex(ALexer)
|
||||||
|
END;
|
||||||
TranspileTypeExpression(AContext, ALexer)
|
TranspileTypeExpression(AContext, ALexer)
|
||||||
END TranspilePointerType;
|
END TranspilePointerType;
|
||||||
|
|
||||||
@ -285,7 +289,7 @@ BEGIN
|
|||||||
TranspileEnumerationType(AContext, ALexer)
|
TranspileEnumerationType(AContext, ALexer)
|
||||||
ELSIF Token.Kind = lexerKindArray THEN
|
ELSIF Token.Kind = lexerKindArray THEN
|
||||||
TranspileArrayType(AContext, ALexer)
|
TranspileArrayType(AContext, ALexer)
|
||||||
ELSIF Token.Kind = lexerKindPointer THEN
|
ELSIF (Token.Kind = lexerKindPointer) OR (Token.Kind = lexerKindHat) THEN
|
||||||
TranspilePointerType(AContext, ALexer)
|
TranspilePointerType(AContext, ALexer)
|
||||||
ELSIF Token.Kind = lexerKindProc THEN
|
ELSIF Token.Kind = lexerKindProc THEN
|
||||||
TranspileProcedureType(AContext, ALexer)
|
TranspileProcedureType(AContext, ALexer)
|
||||||
@ -364,6 +368,60 @@ BEGIN
|
|||||||
END
|
END
|
||||||
END TranspileVariablePart;
|
END TranspileVariablePart;
|
||||||
|
|
||||||
|
PROCEDURE TranspileProcedureDeclaration(AContext: PTranspilerContext; ALexer: PLexer);
|
||||||
|
VAR
|
||||||
|
Token: LexerToken;
|
||||||
|
WrittenBytes: CARDINAL;
|
||||||
|
BEGIN
|
||||||
|
WriteString('PROCEDURE ');
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WrittenBytes := WriteNBytes(StdOut, ADDRESS(ALexer^.Current - ALexer^.Start), ALexer^.Start);
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
Write('(');
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WHILE Token.Kind <> lexerKindRightParen DO
|
||||||
|
WrittenBytes := WriteNBytes(StdOut, ADDRESS(ALexer^.Current - ALexer^.Start), ALexer^.Start);
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WriteString(': ');
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WrittenBytes := WriteNBytes(StdOut, ADDRESS(ALexer^.Current - ALexer^.Start), ALexer^.Start);
|
||||||
|
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
IF Token.Kind = lexerKindSemicolon THEN
|
||||||
|
WriteString('; ');
|
||||||
|
Token := TranspilerLex(ALexer)
|
||||||
|
END
|
||||||
|
END;
|
||||||
|
WriteString(')');
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
|
||||||
|
(* Check for the return type and write it. *)
|
||||||
|
IF Token.Kind = lexerKindColon THEN
|
||||||
|
WriteString(': ');
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WrittenBytes := WriteNBytes(StdOut, ADDRESS(ALexer^.Current - ALexer^.Start), ALexer^.Start);
|
||||||
|
Token := TranspilerLex(ALexer)
|
||||||
|
END;
|
||||||
|
Token := TranspilerLex(ALexer);
|
||||||
|
WriteSemicolon()
|
||||||
|
END TranspileProcedureDeclaration;
|
||||||
|
|
||||||
|
PROCEDURE TranspileProcedurePart(AContext: PTranspilerContext; ALexer: PLexer);
|
||||||
|
VAR
|
||||||
|
Token: LexerToken;
|
||||||
|
BEGIN
|
||||||
|
Token := LexerCurrent(ALexer);
|
||||||
|
|
||||||
|
IF Token.Kind = lexerKindProc THEN
|
||||||
|
TranspileProcedureDeclaration(AContext, ALexer)
|
||||||
|
END
|
||||||
|
END TranspileProcedurePart;
|
||||||
|
|
||||||
PROCEDURE Transpile(ALexer: PLexer);
|
PROCEDURE Transpile(ALexer: PLexer);
|
||||||
VAR
|
VAR
|
||||||
Token: LexerToken;
|
Token: LexerToken;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user