def p_ImportDecl(p): """ImportDecl : KW_IMPORT ImportSpec | KW_IMPORT '(' ImportSpecList ')' """ if len(p) == 3: p[0] = syntree.List([p[2]]) elif len(p) == 5: p[0] = p[3]
def p_ConstDecl(p): """ConstDecl : KW_CONST ConstSpec | KW_CONST '(' ConstSpecList ')' """ if len(p) == 3: p[0] = syntree.List([p[2]]) elif len(p) == 5: p[0] = p[3]
def p_TypeDecl(p): """TypeDecl : KW_TYPE TypeSpec | KW_TYPE '(' TypeSpecList ')' """ if len(p) == 3: p[0] = syntree.List([p[2]]) elif len(p) == 5: p[0] = p[3]
def p_VarDecl(p): """VarDecl : KW_VAR VarSpec | KW_VAR '(' VarSpecList ')' """ if len(p) == 3: p[0] = syntree.List([p[2]]) elif len(p) == 5: p[0] = p[3]
def p_ExpressionList(p): """ExpressionList : Expression | Expression ',' ExpressionList """ if len(p) == 4: p[3].append(p[1]) p[0] = p[3] elif len(p) == 2: p[0] = syntree.List([p[1]])
def p_IdentifierList(p): """IdentifierList : IDENTIFIER | IDENTIFIER ',' IdentifierList """ if len(p) == 2: p[0] = syntree.List([syntree.Identifier(p[1], p.lineno(1))]) elif len(p) == 4: p[3].append(syntree.Identifier(p[1], p.lineno(1))) p[0] = p[3]
def p_ParameterList(p): """ParameterList : ParameterDecl | ParameterList ',' ParameterDecl """ if len(p) == 4: p[1].append(p[3]) p[0] = p[1] elif len(p) == 2: p[0] = syntree.List([p[1]])
def p_ImportSpecList(p): """ImportSpecList : empty | ImportSpec ';' ImportSpecList """ if len(p) == 4: if p[3] is not None: p[3].append(p[1]) p[0] = p[3] else: p[0] = syntree.List([p[1]])
def p_TypeSpecList(p): """TypeSpecList : empty | TypeSpec ';' TypeSpecList """ if len(p) == 4: if p[3] is not None: p[3].append(p[1]) p[0] = p[3] else: p[0] = syntree.List([p[1]])
def p_ConstSpecList(p): """ConstSpecList : empty | ConstSpec ';' ConstSpecList """ if len(p) == 4: if p[3] is not None: p[3].append(p[1]) p[0] = p[3] else: p[0] = syntree.List([p[1]])
def p_StatementList(p): """StatementList : empty | Statement ';' StatementList """ if len(p) == 4: if p[3] is not None: p[3].append(p[1]) p[0] = p[3] else: p[0] = syntree.List([p[1]])
def p_TopLevelDeclList(p): """TopLevelDeclList : empty | TopLevelDecl ';' TopLevelDeclList """ if len(p) == 4: if p[3] is not None: p[3].append(p[1]) p[0] = p[3] else: p[0] = syntree.List([p[1]])
def p_KeyedElementList(p): """KeyedElementList : KeyedElement | KeyedElement ',' KeyedElementList """ if len(p) == 2: p[0] = syntree.List([p[1]]) elif len(p) == 4: p[3].append(p[1]) p[0] = p[3] else: raise Exception("Bad grammar or rules!")