diff options
Diffstat (limited to 'prolog')
-rw-r--r-- | prolog/lexer.py | 1 | ||||
-rw-r--r-- | prolog/parser.py | 38 |
2 files changed, 7 insertions, 32 deletions
diff --git a/prolog/lexer.py b/prolog/lexer.py index f905a2b..f2b19dc 100644 --- a/prolog/lexer.py +++ b/prolog/lexer.py @@ -27,6 +27,7 @@ import ply.lex as lex # tokens; treat operators as names if followed by ( operators = { r':-': 'FROM', + r'-->': 'FROMDCG', r'->': 'IMPLIES', r'\+': 'NOT', r'not': 'NOT', diff --git a/prolog/parser.py b/prolog/parser.py index 4a3f4b5..8fe96da 100644 --- a/prolog/parser.py +++ b/prolog/parser.py @@ -21,7 +21,7 @@ from .util import Token # PARSER precedence = ( - ('nonassoc', 'FROM'), + ('nonassoc', 'FROM', 'FROMDCG'), ('right', 'IMPLIES'), ('right', 'NOT'), ('nonassoc', 'EQU', 'NEQU', 'EQ', 'NEQ', 'UNIV', 'IS', 'EQA', 'NEQA', 'LT', 'LE', 'GT', 'GE', 'LTL', 'LEL', 'GTL', 'GEL', 'IN', 'INS', 'THROUGH', 'EQFD', 'NEQFD', 'LTFD', 'LEFD', 'GTFD', 'GEFD'), @@ -51,7 +51,8 @@ def p_clause_head(p): 'clause : head PERIOD' p[0] = Tree('clause', [p[1], make_token(p, 2)]) def p_clause_rule(p): - 'clause : head FROM or PERIOD' + '''clause : head FROM or PERIOD + | head FROMDCG or PERIOD''' p[0] = Tree('clause', [p[1], make_token(p, 2), p[3], make_token(p, 4)]) def p_head(p): @@ -198,37 +199,10 @@ def p_clpr_more(p): '''clpr : clpr_constr COMMA clpr | clpr_constr SEMI clpr''' p[0] = Tree('clpr', [p[1], make_token(p, 2), p[3]]) - +# XXX temporary until the new parser is in place, this also covers { } notation for DCGs def p_clpr_constr(p): - '''clpr_constr : clpr_expr LT clpr_expr - | clpr_expr GT clpr_expr - | clpr_expr LE clpr_expr - | clpr_expr GE clpr_expr - | clpr_expr NEQA clpr_expr - | clpr_expr EQA clpr_expr - | clpr_expr EQU clpr_expr''' - p[0] = Tree('clpr_constr', [p[1], make_token(p, 2), p[3]]) - -def p_clpr_expr_value(p): - '''clpr_expr : VARIABLE - | UINTEGER - | UREAL''' - p[0] = Tree('clpr_expr', [make_token(p, 1)]) -def p_clpr_expr_unary(p): - '''clpr_expr : MINUS clpr_expr %prec UMINUS - | PLUS clpr_expr %prec UPLUS''' - p[0] = Tree('clpr_expr', [make_token(p, 1), p[2]]) -def p_clpr_expr_binary(p): - '''clpr_expr : clpr_expr PLUS clpr_expr - | clpr_expr MINUS clpr_expr - | clpr_expr STAR clpr_expr - | clpr_expr DIV clpr_expr - | clpr_expr POW clpr_expr - | clpr_expr NAME clpr_expr''' # XXX a hack to allow (X)*(X) without spaces - p[0] = Tree('clpr_expr', [p[1], make_token(p, 2), p[3]]) -def p_clpr_expr_parens(p): - 'clpr_expr : LPAREN clpr_expr RPAREN' - p[0] = Tree('clpr_expr', [make_token(p, 1), p[2], make_token(p, 3)]) + 'clpr_constr : term' + p[0] = p[1] def p_error(t): if t is None: |