From 6a5a9a384842870f9a54ffeb3a828e57eafdec08 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 27 Jul 2013 17:06:37 +0300 Subject: Can do logical and. --- mparser.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mparser.py') diff --git a/mparser.py b/mparser.py index 0b5ed30..5a28ccc 100644 --- a/mparser.py +++ b/mparser.py @@ -27,6 +27,9 @@ reserved = {'true' : 'TRUE', 'if' : 'IF', 'endif' : 'ENDIF', 'else' : 'ELSE', + 'and' : 'AND', + 'or' : 'OR', + 'not' : 'NOT', } tokens = ['LPAREN', @@ -62,6 +65,16 @@ t_COLON = ':' t_ignore = ' \t' +precedence = ( +('left', 'COMMA'), +('left', 'ASSIGN'), +('nonassoc', 'EQUALS', 'NEQUALS'), +('left', 'OR'), +('left', 'AND'), +('nonassoc', 'COLON') +('left', 'DOT'), +) + def t_ATOM(t): '[a-zA-Z][_0-9a-zA-Z]*' t.type = reserved.get(t.value, 'ATOM') @@ -175,6 +188,14 @@ def p_statement_if(t): 'statement : IF statement EOL codeblock elseblock ENDIF' t[0] = nodes.IfStatement(t[2], t[4], t[5], t.lineno(1)) +def p_statement_parentheses(t): + 'statement : LPAREN statement RPAREN' + t[0] = t[2] + +def p_statement_and(t): + 'statement : statement AND statement' + t[0] = nodes.AndStatement(t[1], t[3]) + def p_empty_else(t): 'elseblock : ' return None -- cgit v1.1