mirror of
https://github.com/Wack0/IFPSTools.NET.git
synced 2025-06-18 10:45:36 -04:00

libifpscc: initial commit readme: document ifpscc/libifpscc license: add credits for ifpscc/libifpscc (derived from code also MIT licensed) libifps: make additional fields/types public for libifpscc libifps: fix field documentation for some opcodes libifps: fix loading functions that are not exported libifps: allow saving a nonexistant primitive type if the same primitive type was added already libifps: fix parsing Extended constants libifps: fix ushort/short being mapped to the wrong types in one table csproj: set Prefer32Bit=false for release builds
81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
using AST;
|
|
using static Parsing.ParserCombinator;
|
|
|
|
namespace Parsing {
|
|
public partial class CParsers {
|
|
|
|
/// <summary>
|
|
/// translation-unit
|
|
/// : [external-declaration]+
|
|
/// </summary>
|
|
public static NamedParser<TranslnUnit>
|
|
TranslationUnit { get; } = new NamedParser<TranslnUnit>("translation-unit");
|
|
|
|
/// <summary>
|
|
/// external-declaration
|
|
/// : function-definition | declaration
|
|
/// </summary>
|
|
public static NamedParser<IExternDecln>
|
|
ExternalDeclaration { get; } = new NamedParser<IExternDecln>("external-declaration");
|
|
|
|
/// <summary>
|
|
/// function-definition
|
|
/// : [declaration-specifiers]? declarator [declaration-list]? compound-statement
|
|
///
|
|
/// NOTE: the optional declaration_list is for the **old-style** function prototype like this:
|
|
/// +-------------------------------+
|
|
/// | int foo(param1, param2) |
|
|
/// | int param1; |
|
|
/// | char param2; |
|
|
/// | { |
|
|
/// | .... |
|
|
/// | } |
|
|
/// +-------------------------------+
|
|
///
|
|
/// i'm **not** going to support this style. function prototypes should always be like this:
|
|
/// +------------------------------------------+
|
|
/// | int foo(int param1, char param2) { |
|
|
/// | .... |
|
|
/// | } |
|
|
/// +------------------------------------------+
|
|
///
|
|
/// so the grammar becomes:
|
|
/// function-definition
|
|
/// : [declaration-specifiers]? declarator compound-statement
|
|
/// </summary>
|
|
public static NamedParser<FuncDef>
|
|
FunctionDefinition { get; } = new NamedParser<FuncDef>("function-definition");
|
|
|
|
public static void SetExternalDefinitionRules() {
|
|
|
|
// translation-unit
|
|
// : [external-declaration]+
|
|
TranslationUnit.Is(
|
|
(ExternalDeclaration)
|
|
.OneOrMoreForEntireUnit()
|
|
.Then(TranslnUnit.Create)
|
|
);
|
|
|
|
// external-declaration
|
|
// : function-definition | declaration
|
|
ExternalDeclaration.Is(
|
|
Either<IExternDecln>(
|
|
FunctionDefinition
|
|
).Or(
|
|
Declaration
|
|
)
|
|
);
|
|
|
|
// function-definition
|
|
// : [declaration-specifiers]? declarator compound-statement
|
|
FunctionDefinition.Is(
|
|
DeclarationSpecifiers.Optional()
|
|
.Then(Declarator)
|
|
.Then(CompoundStatement)
|
|
.Then(FuncDef.Create)
|
|
);
|
|
|
|
}
|
|
}
|
|
}
|