commit 64b0e82ab315572742f93f9789c5c6d16e4c4607 from: Benjamin Stürz date: Sun Oct 13 13:00:12 2024 UTC cc1: add parsing of declaration at the start of a function commit - 4b0bcc854725c71590df2786768009a5bf26027e commit + 64b0e82ab315572742f93f9789c5c6d16e4c4607 blob - aee9628bdfde43a9f21d2d3e91ce6d3567462693 blob + e10d1a674f97709eff162ea5de14204ed0528770 --- cc/cc1/cc1.c +++ cc/cc1/cc1.c @@ -177,8 +177,23 @@ struct dtype { enum dtype_type type; }; +enum decl_type { + DL_VAR, + DL_FUNC, +}; + +struct decl { + struct decl *next; + enum sc_class sc; + struct dtype *dt; + char *name; +}; + // PARSER +#define new(T) ((T *)calloc (1, sizeof (T))) +#define pnew(T) (new (T)) + dtype (dt) struct dtype *dt; { @@ -192,6 +207,8 @@ struct dtype *dt; } } +body (); + decl (global) { enum sc_class sc; @@ -250,7 +267,7 @@ decl (global) if (!first || !global) error ("syntax error"); - // TODO: body + body (); expect ('}'); return 1; @@ -276,6 +293,12 @@ decl (global) return 1; } +body (void) +{ + while (decl (0)); + +} + parse (void) { while (peek () != TK_EOF) { blob - 5214b99bdcf8c37d707fd52884a8398dee10d032 blob + 9ca5ba4182db216e139a91acce1b53cc6a63b8f8 --- cc/cc1/test.c +++ cc/cc1/test.c @@ -8,6 +8,8 @@ int z; int g () { + extern x, y, z (); + int k; } main ()