@@ -3,24 +3,28 @@ uid: Kaleidoscope-ParseTreeVisitor
33---
44
55# Kaleidoscope Parse Tree Visitors
6- The Ubiquity.NET.Llvm Kaleidoscope tutorials all use ANTLR4 to parse the Kaleidoscope language When ANTLR processes the
7- language grammar description to generate the lexer and parser it also generates a base "visitor" class for applying
8- the [ Visitor pattern] ( https://en.wikipedia.org/wiki/Visitor_pattern ) to the parse tree. This is the primary mechanism
9- for generating the [ AST] ( xref:Kaleidoscope-AST ) for these examples. The AST transformation classes derive from the ANTLR
10- generated base visitor class.
6+ The Ubiquity.NET.Llvm Kaleidoscope tutorials all use ANTLR4 to parse the Kaleidoscope
7+ language When ANTLR processes the grammar description to generate the lexer and parser it
8+ also generates a base "visitor" class for applying the [ Visitor pattern] ( https://en.wikipedia.org/wiki/Visitor_pattern )
9+ to the parse tree. This is the primary mechanism for generating the [ AST] ( xref:Kaleidoscope-AST )
10+ for these examples. The AST transformation classes derive from the ANTLR generated base
11+ visitor class.
1112
12- There are only a few top level rules in the grammar to consider (although each has many sub rules).
13+ There are only a few top level rules in the grammar to consider (although each has many
14+ sub-rules).
1315
1416[ !code-antlr[ repl] ( Kaleidoscope.g4?start=181&end=187 )]
1517
16- The parse tree consist of a tree of nodes generated for each rule in the grammar. The rule classes are generated at
17- build time when the antlr grammar file is parsed. The C# target for ANTLR4 will generate the rule classes with the
18- partial keyword, allowing the application code to add application specific support to the rule classes, and thus to
19- the parse tree. For Kaleidoscope, this is used to provide simpler access to the information parsed from the Kaleidoscope
20- language input simplifying generation of the AST. For simplicity and clarity of understanding each of the extended partial
21- classes are placed into their own source file.
18+ The parse tree consist of a tree of nodes generated for each rule in the grammar. The rule
19+ classes are generated at build time when the ANTLR grammar file is parsed. The C# target for
20+ ANTLR4 will generate the rule classes with the partial keyword, allowing the application
21+ code to add application specific support to the rule classes, and thus to the parse tree.
22+ For Kaleidoscope, this is used to provide simpler access to the information parsed from the
23+ Kaleidoscope language input simplifying generation of the AST. For simplicity and clarity of
24+ understanding each of the extended partial classes are placed into their own source file.
2225
23- Generally speaking, the use of ANTLR and the ParseTree is a hidden internal implementation detail of the Ubiquity.NET.Llvm
24- Kaleidoscope tutorials. The actual code generation deals only with the AST so the parsing could be done with some
25- other technology. (Though with all the functionality that ANTLR4 provides it would take a strong argument to justify
26- something else)
26+ Generally speaking, the use of ANTLR and the ParseTree is a hidden internal implementation
27+ detail of the Ubiquity.NET.Llvm Kaleidoscope tutorials. The actual code generation deals
28+ only with the AST so the parsing could be done with some other technology. (Though with all
29+ the functionality that ANTLR4 provides it would take a strong argument to justify something
30+ else)
0 commit comments