Skip to content

alpha coyote grammar

Stefan Koch edited this page Feb 23, 2015 · 1 revision
CoyoteNode {
	Number {
		[0-9][] number
	}

	Identifier {
		[_A-Za-z][] identifier
	}

	Type { 		
		Int {
		 	"int"
		}

		Void {
			"void"
		}
	}

	Operator {
		Add {"+"}

		Mul {"*"}

		Equals {"=="}
	}

	Declaration {
		VariableDeclaration {
			Type type, Identifier name
		}

		FunctionDeclaration {
			Type returnType, Identifier name, "(", VariableDeclaration[] parameters : ",", ")"  
		}
	}

	Statement {
		FunctionStatement {
			FunctionDeclaration fdecl, BlockStatement body  
		}

		IfStatement {
			"if", "(", Expression cond, ")", Statement stmt
		}

		BlockStatement {
			"{", Statement[] statements, "}"
		}

		DeclarartionStatement {
			Declaration decl, ";"
		}
		
		ExpressionStatement {
			Expression expr, ";"
		}

		ReturnStatement {
			"return", Expression expr, ";"
		}
	}

	Expression {
		PrimaryExpression {
			IdentifierExpression {
				Identifier name
			}
			
			CallExpression {
				Identifier name, "(", Expression[] parameters : ",", ")"
			}

			IntegerLiteral {
				Number val
			}
		}
		BinaryExpression {
			Expression lhs, Operator op, PrimaryExpression rhs
		}
	}
}

Clone this wiki locally