You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by pm...@apache.org on 2015/08/31 19:46:04 UTC

incubator-corinthia git commit: Flat: Use consistent variable names for Rules

Repository: incubator-corinthia
Updated Branches:
  refs/heads/master b35496cf7 -> 2a245432d


Flat: Use consistent variable names for Rules

Rules used to be called Definitions, and a lot of variabels in Grammar.c
reflected that. Use 'rule' instead of 'def' when referring to Rule
objects, for consistency.


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/2a245432
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/2a245432
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/2a245432

Branch: refs/heads/master
Commit: 2a245432de4f8efb2dd2c10f4170b310bda140ed
Parents: b35496c
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Tue Sep 1 00:07:04 2015 +0700
Committer: Peter Kelly <pe...@uxproductivity.com>
Committed: Tue Sep 1 00:07:04 2015 +0700

----------------------------------------------------------------------
 experiments/flat/src/Grammar.c | 54 ++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/2a245432/experiments/flat/src/Grammar.c
----------------------------------------------------------------------
diff --git a/experiments/flat/src/Grammar.c b/experiments/flat/src/Grammar.c
index 5cba326..89eb638 100644
--- a/experiments/flat/src/Grammar.c
+++ b/experiments/flat/src/Grammar.c
@@ -31,54 +31,54 @@ struct Rule {
 };
 
 struct Grammar {
-    Rule **nextDef;
-    Rule *defList;
+    Rule **nextRule;
+    Rule *ruleList;
 };
 
 Rule *RuleNew(const char *name, Expression *expr)
 {
-    Rule *def = (Rule *)calloc(1,sizeof(Rule));
-    def->name = strdup(name);
-    def->expr = expr;
-    return def;
+    Rule *rule = (Rule *)calloc(1,sizeof(Rule));
+    rule->name = strdup(name);
+    rule->expr = expr;
+    return rule;
 }
 
-void RuleFree(Rule *def)
+void RuleFree(Rule *rule)
 {
-    free(def->name);
-    ExpressionFree(def->expr);
-    free(def);
+    free(rule->name);
+    ExpressionFree(rule->expr);
+    free(rule);
 }
 
 Grammar *GrammarNew(void)
 {
     Grammar *gram = (Grammar *)calloc(1,sizeof(Grammar));
-    gram->nextDef = &gram->defList;
+    gram->nextRule = &gram->ruleList;
     return gram;
 }
 
 void GrammarFree(Grammar *gram)
 {
     Rule *next;
-    for (Rule *def = gram->defList; def != NULL; def = next) {
-        next = def->next;
-        RuleFree(def);
+    for (Rule *rule = gram->ruleList; rule != NULL; rule = next) {
+        next = rule->next;
+        RuleFree(rule);
     }
     free(gram);
 }
 
 void GrammarDefine(Grammar *gram, const char *name, Expression *expr)
 {
-    Rule *def = RuleNew(name,expr);
-    *gram->nextDef = def;
-    gram->nextDef = &def->next;
+    Rule *rule = RuleNew(name,expr);
+    *gram->nextRule = rule;
+    gram->nextRule = &rule->next;
 }
 
 Expression *GrammarLookup(Grammar *gram, const char *name)
 {
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
-        if (!strcmp(def->name,name))
-            return def->expr;
+    for (Rule *rule = gram->ruleList; rule != NULL; rule = rule->next) {
+        if (!strcmp(rule->name,name))
+            return rule->expr;
     }
     return NULL;
 }
@@ -102,15 +102,15 @@ static void GrammarResolveRecursive(Grammar *gram, Expression *expr, const char
 
 void GrammarResolve(Grammar *gram)
 {
-    for (Rule *def = gram->defList; def != NULL; def = def->next)
-        GrammarResolveRecursive(gram,def->expr,def->name);
+    for (Rule *rule = gram->ruleList; rule != NULL; rule = rule->next)
+        GrammarResolveRecursive(gram,rule->expr,rule->name);
 }
 
 void GrammarPrint(Grammar *gram, int exprAsTree)
 {
     int maxNameLen = 0;
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
-        int nameLen = strlen(def->name);
+    for (Rule *rule = gram->ruleList; rule != NULL; rule = rule->next) {
+        int nameLen = strlen(rule->name);
         if (maxNameLen < nameLen)
             maxNameLen = nameLen;
     }
@@ -119,7 +119,7 @@ void GrammarPrint(Grammar *gram, int exprAsTree)
     memset(prefix,' ',maxNameLen+1);
     prefix[maxNameLen+1] = '\0';
 
-    for (Rule *def = gram->defList; def != NULL; def = def->next) {
+    for (Rule *def = gram->ruleList; def != NULL; def = def->next) {
         int nameLen = strlen(def->name);
         printf("%s",def->name);
         if (exprAsTree) {
@@ -145,8 +145,8 @@ void GrammarPrint(Grammar *gram, int exprAsTree)
 
 const char *GrammarFirstRuleName(Grammar *gram)
 {
-    if (gram->defList == NULL)
+    if (gram->ruleList == NULL)
         return NULL;
     else
-        return gram->defList->name;
+        return gram->ruleList->name;
 }