bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 5/6] examples: improve some function prototypes


From: Akim Demaille
Subject: [PATCH 5/6] examples: improve some function prototypes
Date: Tue, 9 Feb 2021 07:15:45 +0100

* examples/c/bistromathic/parse.y, examples/c/glr/c++-types.y,
* examples/c/lexcalc/parse.y: Use const where appropriate.
Avoid `yy` prefixes where it does not make sense.
Avoid the `p` prefix for pointers.
---
 examples/c/bistromathic/parse.y |  4 ++--
 examples/c/glr/c++-types.y      | 16 ++++++++--------
 examples/c/lexcalc/parse.y      |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index e10d99ced..e06db523a 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -87,7 +87,7 @@
   yytoken_kind_t
   yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc,
          const user_context *uctx);
-  void yyerror (YYLTYPE *loc, const user_context *uctx,
+  void yyerror (const YYLTYPE *loc, const user_context *uctx,
                 char const *format, ...)
     __attribute__ ((__format__ (__printf__, 3, 4)));
 }
@@ -466,7 +466,7 @@ yyreport_syntax_error (const yypcontext_t *ctx, const 
user_context *uctx)
 
 
 // Called by yyparse on error.
-void yyerror (YYLTYPE *loc, const user_context *uctx, char const *format, ...)
+void yyerror (const YYLTYPE *loc, const user_context *uctx, char const 
*format, ...)
 {
   if (uctx->silent)
     return;
diff --git a/examples/c/glr/c++-types.y b/examples/c/glr/c++-types.y
index a96ef70c7..67cadcaf5 100644
--- a/examples/c/glr/c++-types.y
+++ b/examples/c/glr/c++-types.y
@@ -68,8 +68,8 @@
   static void node_print (FILE *, const Node *);
   static Node *stmtMerge (YYSTYPE x0, YYSTYPE x1);
 
-  static void yyerror (YYLTYPE const * const llocp, const char *msg);
-  static yytoken_kind_t yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
+  static void yyerror (YYLTYPE const * const loc, const char *msg);
+  static yytoken_kind_t yylex (YYSTYPE *lval, YYLTYPE *lloc);
 }
 
 %expect-rr 1
@@ -138,7 +138,7 @@ yyerror (YYLTYPE const * const loc, const char *msg)
 FILE * input = NULL;
 
 yytoken_kind_t
-yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
+yylex (YYSTYPE *lval, YYLTYPE *lloc)
 {
   static int lineNum = 1;
   static int colNum = 0;
@@ -165,8 +165,8 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
         default:
           {
             yytoken_kind_t tok;
-            llocp->first_line = llocp->last_line = lineNum;
-            llocp->first_column = colNum;
+            lloc->first_line = lloc->last_line = lineNum;
+            lloc->first_column = colNum;
             if (isalpha (c))
               {
                 char buffer[256];
@@ -186,12 +186,12 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
                 if (isupper ((unsigned char) buffer[0]))
                   {
                     tok = TYPENAME;
-                    lvalp->TYPENAME = new_term (strcpy (malloc (i), buffer));
+                    lval->TYPENAME = new_term (strcpy (malloc (i), buffer));
                   }
                 else
                   {
                     tok = ID;
-                    lvalp->ID = new_term (strcpy (malloc (i), buffer));
+                    lval->ID = new_term (strcpy (malloc (i), buffer));
                   }
               }
             else
@@ -199,7 +199,7 @@ yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
                 colNum += 1;
                 tok = c;
               }
-            llocp->last_column = colNum;
+            lloc->last_column = colNum;
             return tok;
           }
         }
diff --git a/examples/c/lexcalc/parse.y b/examples/c/lexcalc/parse.y
index 9c137b588..aa72a4106 100644
--- a/examples/c/lexcalc/parse.y
+++ b/examples/c/lexcalc/parse.y
@@ -28,7 +28,7 @@
   yytoken_kind_t yylex (YYSTYPE* yylval, YYLTYPE *yylloc)
   YY_DECL;
 
-  void yyerror (YYLTYPE *loc, const char *msg);
+  void yyerror (const YYLTYPE *loc, const char *msg);
 }
 
 // Emitted on top of the implementation file.
@@ -118,7 +118,7 @@ exp:
 %%
 // Epilogue (C code).
 
-void yyerror (YYLTYPE *loc, const char *msg)
+void yyerror (const YYLTYPE *loc, const char *msg)
 {
   YYLOCATION_PRINT (stderr, loc);
   fprintf (stderr, ": %s\n", msg);
-- 
2.30.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]