Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created October 26, 2016 03:42
Show Gist options
  • Select an option

  • Save toptensoftware/17f7643551b41032911d0fb433416d1b to your computer and use it in GitHub Desktop.

Select an option

Save toptensoftware/17f7643551b41032911d0fb433416d1b to your computer and use it in GitHub Desktop.
// Variable
if (_tokenizer.Token == Token.Identifier)
{
// Capture the name and skip it
var name = _tokenizer.Identifier;
_tokenizer.NextToken();
// Parens indicate a function call, otherwise just a variable
if (_tokenizer.Token != Token.OpenParens)
{
// Variable
return new NodeVariable(name);
}
else
{
// Function call
// Skip parens
_tokenizer.NextToken();
// Parse arguments
var arguments = new List<Node>();
while (true)
{
// Parse argument and add to list
arguments.Add(ParseAddSubtract());
// Is there another argument?
if (_tokenizer.Token == Token.Comma)
{
_tokenizer.NextToken();
continue;
}
// Get out
break;
}
// Check and skip ')'
if (_tokenizer.Token != Token.CloseParens)
throw new SyntaxException("Missing close parenthesis");
_tokenizer.NextToken();
// Create the function call node
return new NodeFunctionCall(name, arguments.ToArray());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment