Ejemplo n.º 1
0
		/// <summary>
		/// Parses a top level expression
		/// </summary>
		/// <returns>An expression syntax tree</returns>
		private ExpressionSyntaxTree ParseTopLevelExpression()
		{
			ExpressionSyntaxTree expression = this.ParseExpression();

			if (expression != null)
			{
				//Make an anonymous prototype
				PrototypeSyntaxTree prototype = new PrototypeSyntaxTree("", new List<string>());
				return new FunctionSyntaxTree(prototype, expression);
			}

			return null;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Parses a function definition
		/// </summary>
		/// <returns>A function syntax tree</returns>
		private FunctionSyntaxTree ParseDefinition()
		{
			this.NextToken(); //Consume the def
			PrototypeSyntaxTree prototype = this.ParsePrototype();

			if (prototype == null)
			{
				return null;
			}

			//Parse the body
			ExpressionSyntaxTree bodyExpression = this.ParseExpression();

			if (bodyExpression != null)
			{
				return new FunctionSyntaxTree(prototype, bodyExpression);
			}

			return null;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Parses an extern 
		/// </summary>
		/// <returns>A external function syntax tree</returns>
		private ExternalFunctionSyntaxTree ParseExtern()
		{
			this.NextToken(); //Consume the extern

			PrototypeSyntaxTree protoType = this.ParsePrototype();

			CharacterToken charToken = this.currentToken as CharacterToken;

			if ((charToken != null && charToken.Value != ':') || charToken == null)
			{
				throw new ParserException("Expected ':' after extern");
			}

			//Consume the :
			this.NextToken();

			charToken = this.currentToken as CharacterToken;

			if ((charToken != null && charToken.Value != ':') || charToken == null)
			{
				throw new ParserException("Expected ':' after extern");
			}

			//Consume the :
			this.NextToken();

			if (this.currentToken.Type != TokenType.Identifier)
			{
				throw new ParserException("Expected indentifier.");
			}

			string funcRef = ((IdentifierToken)this.currentToken).Value;

			//Consume the identifier
			this.NextToken();

			return new ExternalFunctionSyntaxTree(protoType, funcRef);
		}
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new external function syntax tree
 /// </summary>
 /// <param name="name">The prototype</param>
 /// <param name="funcReference">The name of the external function</param>
 public ExternalFunctionSyntaxTree(PrototypeSyntaxTree prototype, string funcReference)
 {
     this.prototype     = prototype;
     this.funcReference = funcReference;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new function syntax tree
 /// </summary>
 /// <param name="name">The prototype</param>
 /// <param name="arguments">The body</param>
 public FunctionSyntaxTree(PrototypeSyntaxTree prototype, ExpressionSyntaxTree body)
 {
     this.prototype = prototype;
     this.body      = body;
 }
Ejemplo n.º 6
0
		/// <summary>
		/// Creates a new external function syntax tree
		/// </summary>
		/// <param name="name">The prototype</param>
		/// <param name="funcReference">The name of the external function</param>
		public ExternalFunctionSyntaxTree(PrototypeSyntaxTree prototype, string funcReference)
		{
			this.prototype = prototype;
			this.funcReference = funcReference;
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Creates a new function syntax tree
		/// </summary>
		/// <param name="name">The prototype</param>
		/// <param name="arguments">The body</param>
		public FunctionSyntaxTree(PrototypeSyntaxTree prototype, ExpressionSyntaxTree body)
		{
			this.prototype = prototype;
			this.body = body;
		}