diff options
Diffstat (limited to 'prolog')
-rw-r--r-- | prolog/lexer.py | 1 | ||||
-rw-r--r-- | prolog/parser.py | 44 |
2 files changed, 45 insertions, 0 deletions
diff --git a/prolog/lexer.py b/prolog/lexer.py index 799ebb9..7ca67e1 100644 --- a/prolog/lexer.py +++ b/prolog/lexer.py @@ -53,6 +53,7 @@ operators = { r'//': 'IDIV', r'mod': 'MOD', r'**': 'POW', + r'^': 'POW', r'.': 'PERIOD', r',': 'COMMA', r';': 'SEMI' diff --git a/prolog/parser.py b/prolog/parser.py index 0c539d5..19d2da5 100644 --- a/prolog/parser.py +++ b/prolog/parser.py @@ -151,6 +151,10 @@ def p_term_simple(p): | VARIABLE''' p[0] = Tree('term', [make_token(p, 1)]) +def p_term_clpr(p): + 'term : LBRACE clpr RBRACE' + p[0] = Tree('term', [make_token(p, 1), p[2], make_token(p, 3)]) + def p_args_single(p): 'args : term' p[0] = Tree('args', [p[1]]) @@ -174,6 +178,46 @@ def p_functor(p): 'functor : NAME' p[0] = Tree('functor', [make_token(p, 1)]) +# CLP(R) syntax +def p_clpr_single(p): + 'clpr : clpr_constr' + p[0] = Tree('clpr', [p[1]]) +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]]) + +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)]) + def p_error(t): if t is None: raise SyntaxError('unexpected end of file') |