Parse the variable part to AST
This commit is contained in:
@ -272,4 +272,56 @@ BEGIN
|
||||
|
||||
RETURN result
|
||||
END parse_type_part;
|
||||
PROCEDURE parse_variable_declaration(lexer: PLexer): PAstVariableDeclaration;
|
||||
VAR
|
||||
token: LexerToken;
|
||||
result: PAstVariableDeclaration;
|
||||
BEGIN
|
||||
ALLOCATE(result, TSIZE(AstVariableDeclaration));
|
||||
|
||||
token := lexer_current(lexer);
|
||||
result^.variable_name := token.identifierKind;
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
result^.variable_type := parse_type_expression(lexer);
|
||||
|
||||
token := transpiler_lex(lexer);
|
||||
RETURN result
|
||||
END parse_variable_declaration;
|
||||
PROCEDURE parse_variable_part(lexer: PLexer): PPAstVariableDeclaration;
|
||||
VAR
|
||||
token: LexerToken;
|
||||
result: PPAstVariableDeclaration;
|
||||
current_declaration: PPAstVariableDeclaration;
|
||||
declaration_count: CARDINAL;
|
||||
BEGIN
|
||||
token := lexer_current(lexer);
|
||||
|
||||
ALLOCATE(result, TSIZE(PAstVariableDeclaration));
|
||||
current_declaration := result;
|
||||
declaration_count := 0;
|
||||
|
||||
IF token.kind = lexerKindVar THEN
|
||||
token := transpiler_lex(lexer);
|
||||
|
||||
WHILE token.kind = lexerKindIdentifier DO
|
||||
INC(declaration_count);
|
||||
|
||||
REALLOCATE(result, TSIZE(PAstVariableDeclaration) * (declaration_count + 1));
|
||||
current_declaration := result;
|
||||
INC(current_declaration, TSIZE(PAstVariableDeclaration) * (declaration_count - 1));
|
||||
|
||||
current_declaration^ := parse_variable_declaration(lexer);
|
||||
token := transpiler_lex(lexer)
|
||||
END
|
||||
END;
|
||||
IF declaration_count <> 0 THEN
|
||||
INC(current_declaration, TSIZE(PAstVariableDeclaration))
|
||||
END;
|
||||
current_declaration^ := NIL;
|
||||
|
||||
RETURN result
|
||||
END parse_variable_part;
|
||||
END Parser.
|
||||
|
Reference in New Issue
Block a user