From c702c9b852486e81cd1877921c15b79d950d580e Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 24 Jul 2023 18:42:27 -0700 Subject: [PATCH] add support for C conditional operator its used by setbc's pseudocode and by the bfp_* functions --- src/openpower/decoder/pseudo/lexer.py | 2 ++ src/openpower/decoder/pseudo/parser.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/openpower/decoder/pseudo/lexer.py b/src/openpower/decoder/pseudo/lexer.py index 339a1980..b454b2ac 100644 --- a/src/openpower/decoder/pseudo/lexer.py +++ b/src/openpower/decoder/pseudo/lexer.py @@ -363,6 +363,7 @@ class PowerLexer: 'WS', 'NEWLINE', 'COMMA', + 'QMARK', 'PERIOD', 'SEMICOLON', 'INDENT', @@ -424,6 +425,7 @@ class PowerLexer: t_BITOR = r'\|' t_BITAND = r'\&' t_BITXOR = r'\^' + t_QMARK = r'\?' # Ply nicely documented how to do this. diff --git a/src/openpower/decoder/pseudo/parser.py b/src/openpower/decoder/pseudo/parser.py index a8ab32cb..a409d86a 100644 --- a/src/openpower/decoder/pseudo/parser.py +++ b/src/openpower/decoder/pseudo/parser.py @@ -820,8 +820,12 @@ class PowerParser: # as I don't support 'and', 'or', and 'not' this works down to 'comparison' def p_test(self, p): - "test : comparison" - p[0] = p[1] + """test : comparison + | comparison QMARK test COLON test""" + if len(p) == 2: + p[0] = p[1] + else: + p[0] = ast.IfExp(test=p[1], body=p[3], orelse=p[5]) # arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] # | '**' test) -- 2.30.2