ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
538 stars 39 forks source link

Implement the parse of parameters in K&R style functions #71

Closed ltcmelo closed 2 years ago

ltcmelo commented 2 years ago

Implement the parse of parameters in K&R style functions

This article illustrates the syntax of a function in K&R C.

  1. Add the syntax — follow the guidance from this wiki page.

    • new node syntax: ExtKR_ParameterDeclarationSyntax (similar to ParameterDeclarationSyntax but with a semicolon token).
    • new list: typedef SyntaxNodePlainList<ExtKR_ParameterDeclarationSyntax*> ExtKR_ParameterDeclarationListSyntax;.
    • new field for the K&R parameters in FunctionDefinitionSyntax.
  2. Parse the syntax

    • at Parser::parseDeclarationOrFunctionDefinition_AtFollowOfSpecifiers at label default, after the parse of an initializer syntax.
    • pre: Backtracker BT(this); (mind the non-K&R parameter functions Parser::parseParameterDeclarationList and parseParameterDeclaration).
    • post: BT.backtrack(); or BT.discard();
  3. Test the syntax

    • TestParser::case0280' toTestParser::case0299'.
ltcmelo commented 2 years ago

This was implemented in https://github.com/ltcmelo/psychec/pull/84