Skip to content

Instantly share code, notes, and snippets.

@wbars
Created January 18, 2016 05:04
Show Gist options
  • Save wbars/343df935ba8323c06dd4 to your computer and use it in GitHub Desktop.
Save wbars/343df935ba8323c06dd4 to your computer and use it in GitHub Desktop.
factorial parse tree
PROGRAM program_name;
Function fac(n: integer;): Integer;
VAR
n: Integer;
BEGIN
IF n = 1 THEN fac = 1 ELSE fac = n * fac(n - 1);
END;
BEGIN
print(fac(10));
END.
├── Program
├── Identifier(program_name)
└── ProgramBody
├── Function
├── FunctionSignature
├── Identifier(fac)
├── Var
└── VarDeclaration
├── Identifier(n)
├── Separate(COLON)
└── Identifier(integer)
└── Type(INTEGER)
└── ProgramBody
├── Var
└── VarDeclaration
├── Identifier(n)
├── Separate(COLON)
└── Type(INTEGER)
└── CompoundStatement
├── Condition
├── Expression
├── Identifier(n)
├── Operator(EQUALS)
└── Int(1)
└── CompoundStatement
└── Expression
├── Identifier(fac)
├── Operator(EQUALS)
└── Int(1)
└── Expression
├── Identifier(fac)
├── Operator(EQUALS)
└── Expression
└── Term
├── Identifier(n)
├── Operator(MULTIPLY)
└── FunctionCall
├── Identifier(fac)
└── SimpleExpression
├── Identifier(n)
├── Operator(MINUS)
└── Int(1)
└── CompoundStatement
└── Expression
└── FunctionCall
├── Identifier(print)
└── FunctionCall
├── Identifier(fac)
└── Int(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment