parseAstFile function
- String path
Parses an AST file from YAML format into a concrete AST node structure.
This function serves as the main entry point for AST parsing. It reads a YAML file containing the abstract syntax tree representation (typically generated by the flex-bison parser) and converts it into a tree of Node objects that can be processed by the semantic analyzer and code generator.
The YAML file format contains structured representations of:
- Program statements and declarations
- Expression trees with operator precedence
- Type information and variable declarations
- Function definitions and calls
- Control flow constructs
Parameters:
path
: File system path to the YAML AST file
Returns: The root Node of the parsed AST
Throws:
- FileSystemException if the file cannot be read
- YamlException if the YAML format is invalid
- Exception if the AST structure contains unsupported node types
Example:
final ast = parseAstFile("build/tmp/ast.out");
ast.evaluate(SymbolTable()); // Process the AST
Implementation
Node parseAstFile(String path) {
var yamlString = File(path).readAsStringSync();
YamlMap astDict = loadYaml(yamlString)[0];
return parseNode(astDict);
}