Commit 84aa440d authored by eckhart's avatar eckhart

- slight cleanups

parent 0fe428f6
......@@ -1040,7 +1040,6 @@ def dsl_error_msg(parser: Parser, error_str: str) -> str:
return " ".join(msg)
########################################################################
#
# Token and Regular Expression parser classes (i.e. leaf classes)
......@@ -2081,7 +2080,7 @@ class Compiler:
"""
Class Compiler is the abstract base class for compilers. Compiler
objects are callable and take the root node of the abstract
syntax tree (AST) as agrument and return the compiled code in a
syntax tree (AST) as argument and return the compiled code in a
format chosen by the compiler itself.
Subclasses implementing a compiler must define `on_XXX()`-methods
......@@ -2170,7 +2169,7 @@ class Compiler:
Calls the compilation method for the given node and returns the
result of the compilation.
The method's name is dreived from either the node's parser
The method's name is derived from either the node's parser
name or, if the parser is anonymous, the node's parser's class
name by adding the prefix 'on_'.
......@@ -2230,7 +2229,7 @@ def compile_source(source: str,
1. The result as returned by the compiler or ``None`` in case
of failure,
2. A list of error or warning messages
3. The root-node of the abstract syntax treelow
3. The root-node of the abstract syntax tree
"""
source_text = load_if_file(source)
log_file_name = logfile_basename(source, compiler)
......
......@@ -4,4 +4,5 @@ General TODO-List
- Position Handling: `Node._pos` and `Node._len` should be set by
parser guard to allow for early dropping of nodes. (Should speed
up tree-traversal later)
\ No newline at end of file
- Position handling should provide for position shifts during preprocessing
OUTDATED
CommonMark
==========
......
import functools
import sys
sys.path.extend(['../../', '../', './'])
from DHParser import *
arithmetik_ebnf = """
expr = expr ("+"|"-") term | term
term = term ("*"|"/") factor | factor
factor = /[0-9]+/~ | "(" expr ")"
"""
ASTTable = {
"+": remove_expendables,
"*": replace_by_single_child,
"factor": [reduce_single_child, remove_brackets]
}
parser = grammar_provider(arithmetik_ebnf)()
transformer = functools.partial(traverse, processing_table=ASTTable.copy())
syntax_tree = parser("5 + 3 * 4")
assert not syntax_tree.error_flag, str(syntax_tree.collect_errors())
transformer(syntax_tree)
print(">>>>> Ausdruck ohne Klammern:\n")
print(syntax_tree.as_sxpr(compact = True))
syntax_tree = parser("(5 + 3) * 4")
assert not syntax_tree.error_flag, str(syntax_tree.collect_errors())
transformer(syntax_tree)
print("\n\n>>>>> Ausdruck mit Klammern:\n")
print(syntax_tree.as_sxpr(compact = True))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment