]> thyrsus.com Git - mad.git/commitdiff
Oh good, % kluge isn't needed after all.
authorEric S. Raymond <esr@thyrsus,com>
Fri, 13 Feb 2004 08:58:40 +0000 (08:58 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Fri, 13 Feb 2004 08:58:40 +0000 (08:58 +0000)
mad

diff --git a/mad b/mad
index bd314e3e239bf7035bdc8931a4be83c9fc05771e..651eddf1c1635d60b93a7ac5b53f76aab1e41a22 100755 (executable)
--- a/mad
+++ b/mad
@@ -11,7 +11,7 @@ reserved = ('BOOLEAN', 'CONDITIONAL', 'CONTINUE', 'DATA', 'DIMENSION',
 
 tokens = reserved + (
     'EOS', 'COMMA',
-    'NAME','ARRAYNAME','INTNUM', 'DOUBLENUM', 'BOOLNUM', 'STRING', 'FUNCALL',
+    'NAME','INTNUM', 'DOUBLENUM', 'BOOLNUM', 'STRING', 'FUNCALL',
     'LPAREN','RPAREN',
     'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
     'NOT', 'OR', 'AND', 'THEN', 'EQV',
@@ -53,11 +53,6 @@ reserved_map = { }
 for r in reserved:
     reserved_map[r] = r
 
-def t_ARRAYNAME(t):
-    r'%[A-Z][A-Z0-9]*'
-    t.value = t.value.lower()[1:]
-    return t
-
 def t_NAME(t):
     r'[A-Z][A-Z0-9_]*(\.(?!P))?'
     t.type = reserved_map.get(t.value, 'NAME')
@@ -169,10 +164,10 @@ def p_statement_dimension(t):
     'statement : DIMENSION dimension_list'
     t[0] = ('dimension', t[2])
 def p_dimension_list(t):
-    'dimension_list : ARRAYNAME application'
+    'dimension_list : NAME application'
     t[0] = [[t[1], tuple(t[2])]]
 def p_dimension_list_continue(t):
-    'dimension_list : dimension_list COMMA ARRAYNAME application'
+    'dimension_list : dimension_list COMMA NAME application'
     t[0] = t[1] + [[t[3], tuple(t[4])]]
 
 ## END
@@ -267,7 +262,7 @@ def p_outval(t):
               | expression'''
     t[0] = t[1]
 def p_range(t):
-    'range : ARRAYNAME application DOTRANGE ARRAYNAME application'
+    'range : NAME application DOTRANGE NAME application'
     t[0] = ('range', t[1], t[2], t[5])
     if t[1] != t[4]:
         sys.stderr.write("variable names in range don't match!")
@@ -421,7 +416,7 @@ def p_expression_float(t):
     t[0] = ('doublenum', t[1])
 
 def p_expression_subscript(t):
-    'expression : ARRAYNAME application'
+    'expression : NAME application'
     t[0] = ('variable', t[1], tuple(t[2]))
     var = t[1]
     refcount[var] = refcount.get(var, 0) + 1
@@ -982,12 +977,6 @@ if __name__ == '__main__':
         source = source.replace("SET LIST TO", "SET_LIST_TO")
         source = source.replace("PRINT FORMAT", "PRINT_FORMAT")
         source = source.replace("READ FORMAT", "READ_FORMAT")
-        # SLR parsing seems to be a tad too weak for the full grammar of MAD.
-        # It hits lookahead problens in parsing array references and array
-        # ranges -- doesn't know that it should look ahead far enough to
-        # see the leading paren on the subscript.  So, decorate array
-        # references in a way that will make them syntactucally obvious.
-        source = re.sub(r"[A-Z][A-Z0-9]*\s*\(", r"%\g<0>", source)
         # Lex or parse
         if lexercise:
             lex.input(source)