Commit a8898ef7 authored by VIGNET Pierre's avatar VIGNET Pierre
Browse files

[lib][antlr] Agnostic update: Fix typos; Try to quickly improve Python bindings

parent 66343619
......@@ -2,8 +2,6 @@
// Filename : chart_compiler.g
// Author(s) : Michel Le Borgne
// Created : 4/2010
// Revision :
// Source :
//
// Copyright 2009 - 2010 : IRISA-IRSET
//
......@@ -36,12 +34,10 @@
// IRISA Campus de Beaulieu
// 35042 RENNES Cedex, FRANCE
//
// Contributor(s): Pierre VIGNET
//
// http:
// mailto:
//
// Contributor(s):
//
// To generate a parser based on this grammar you'll need ANTLRv4, which you can
// get from 'https://www.antlr.org/download.html'.
parser grammar sigexpr_compiler;
......@@ -59,110 +55,110 @@ import string
}
// auxiliary methods
@members{
def set_error_reporter(self, err):
self.error_reporter = err
def set_error_reporter(self, err):
self.error_reporter = err
def displayRecognitionError(self, tokens_names, re):
"""Display RecognitionError in the reporter"""
# location of the error
header = self.getErrorHeader(re)
# message of the error
error_msg = self.getErrorMessage(re, tokens_names)
self.error_reporter.display(
"RecognitionError: sig_exp -> {}; {}; {}".format(header, error_msg, self.message)
)
def displayRecognitionError(self, tokens_names, re):
"""Display RecognitionError in the reporter"""
# location of the error
header = self.getErrorHeader(re)
# message of the error
error_msg = self.getErrorMessage(re, tokens_names)
self.error_reporter.display(
"RecognitionError: sig_exp -> {}; {}; {}".format(header, error_msg, self.message)
)
def displayExceptionMessage(self, e):
"""Display ExceptionMessage in the reporter"""
error_msg = self.getErrorMessage(self, e, tokenNames)
self.error_reporter.display("Exception: sig_exp -> " + error_msg)
def displayExceptionMessage(self, e):
"""Display ExceptionMessage in the reporter"""
error_msg = self.getErrorMessage(self, e, tokenNames)
self.error_reporter.display("Exception: sig_exp -> " + error_msg)
# semantic checks for compilers
def check_ident(self, symbol_table, st_only, free_clock, deep, message, name):
"""Check if name is declared (with state/input type if st_only = True)
# semantic checks for compilers
def check_ident(self, symbol_table, st_only, free_clock, deep, message, name):
"""Check if name is declared (with state/input type if st_only = True)
@return: a SigIdentExpr
"""
name = name.encode("utf-8")
try:
state_type, deepness = symbol_table[name]
# for condition compiler
if st_only and state_type not in ("state", "input"):
self.error_reporter.display(
"Type error: '{}' has not an expected state: '{}'; {}".format(
name, state_type, message
)
)
elif deep >= 0 and deepness >= deep:
self.error_reporter.display(
"Type error: '{}' not declared in a surrounding macro state; {}".format(
name, message
)
)
except KeyError:
if free_clock and not st_only:
self.free_clocks.append(name)
else:
self.error_reporter.display(
"Declaration error: Undeclared event or state: '{}'; {}".format(
name, message
)
@return: a SigIdentExpr
"""
name = name.encode("utf-8")
try:
state_type, deepness = symbol_table[name]
# for condition compiler
if st_only and state_type not in ("state", "input"):
self.error_reporter.display(
"Type error: '{}' has not an expected state: '{}'; {}".format(
name, state_type, message
)
return SigIdentExpr(name)
def check_updown(self, symbol_table, id, mode):
"""
This function introduce new signals: state> or state<
"""
id = id.encode("utf-8")
try:
state_type, _ = symbol_table[id]
except KeyError:
)
elif deep >= 0 and deepness >= deep:
self.error_reporter.display(
"Declaration error: Undeclared state in variation: '{}'".format(id)
"Type error: '{}' not declared in a surrounding macro state; {}".format(
name, message
)
)
state_type = None
if state_type == "state":
# mode = 1: up: ">"
# mode != 1: down: "<"
name = id + (">" if mode == 1 else "<")
self.state_events.append(name)
return SigIdentExpr(name)
except KeyError:
if free_clock and not st_only:
self.free_clocks.append(name)
else:
self.error_reporter.display(
"Type error: Up and Down can only be derived from a state: '{}'".format(id)
"Declaration error: Undeclared event or state: '{}'; {}".format(
name, message
)
)
return SigIdentExpr(name)
def check_change(self, symbol_table, id):
id = id.encode("utf-8")
try:
state_type, _ = symbol_table[id]
except KeyError:
self.error_reporter.display(
"Declaration error: Undeclared signal in variation: '{}'".format(id)
)
state_type = None
def check_updown(self, symbol_table, id, mode):
"""
This function introduce new signals: state> or state<
"""
id = id.encode("utf-8")
try:
state_type, _ = symbol_table[id]
except KeyError:
self.error_reporter.display(
"Declaration error: Undeclared state in variation: '{}'".format(id)
)
state_type = None
if state_type == "state":
refresh_expr = SigIdentExpr(id)
st_expr = SigIdentExpr(id)
return SigWhenExpr(SigConstExpr(True),SigDiffExpr(st_expr, refresh_expr))
else:
self.error_reporter.display(
"Type error: Change can only be derived from a state: '{}'".format(id)
)
if state_type == "state":
# mode = 1: up: ">"
# mode = 1: down: "<"
name = id + (">" if mode == 1 else "<")
self.state_events.append(name)
return SigIdentExpr(name)
else:
self.error_reporter.display(
"Type error: Up and Down can only be derived from a state: '{}'".format(id)
)
def check_change(self, symbol_table, id):
id = id.encode("utf-8")
try:
state_type, _ = symbol_table[id]
except KeyError:
self.error_reporter.display(
"Declaration error: Undeclared signal in variation: '{}'".format(id)
)
state_type = None
if state_type == "state":
refresh_expr = SigIdentExpr(id)
st_expr = SigIdentExpr(id)
return SigWhenExpr(SigConstExpr(True),SigDiffExpr(st_expr, refresh_expr))
else:
self.error_reporter.display(
"Type error: Change can only be derived from a state: '{}'".format(id)
)
def check_sync(self, lexp):
# type checking is done in expressions
return SigConstraintExpr(SigConstraintExpr.SYNCHRO, lexp)
def check_sync(self, lexp):
# type checking is done in expressions
return SigConstraintExpr(SigConstraintExpr.SYNCHRO, lexp)
def check_exclus(self, lexp):
return SigConstraintExpr(SigConstraintExpr.EXCLU, lexp)
def check_exclus(self, lexp):
return SigConstraintExpr(SigConstraintExpr.EXCLU, lexp)
def check_included(self, exp1,exp2):
return SigConstraintExpr(SigConstraintExpr.INCL, [exp1,exp2])
def check_included(self, exp1,exp2):
return SigConstraintExpr(SigConstraintExpr.INCL, [exp1,exp2])
}
// Compiler options and internals
......
......@@ -2,8 +2,6 @@
// Filename : chart_lexer.g
// Author(s) : Michel Le Borgne
// Created : 4/2010
// Revision :
// Source :
//
// Copyright 2009 - 2010 : IRISA-IRSET
//
......@@ -36,12 +34,10 @@
// IRISA Campus de Beaulieu
// 35042 RENNES Cedex, FRANCE
//
// Contributor(s): Pierre VIGNET
//
// http:
// mailto:
//
// Contributor(s):
//
// To generate a parser based on this grammar you'll need ANTLRv4, which you can
// get from 'https://www.antlr.org/download.html'.
lexer grammar sigexpr_lexer;
......
// Collect ident names in a boolean expression
//
// To generate a parser based on this grammar you'll need ANTLRv4, which you can
// get from 'https://www.antlr.org/download.html'.
grammar condexp;
......
// read a textual description of a chart model and build it
// read a textual description of a chart model and build it
//
// To generate a parser based on this grammar you'll need ANTLRv4, which you can
// get from 'https://www.antlr.org/download.html'.
grammar cadlang;
......@@ -46,11 +49,9 @@ def check_ident_dec(self, id, type, line):
@param id : string
"""
line_txt = 'line '+str(line)+':'
try:
place = self.symb_tab[id]
self.error_reporter.display(line_txt+" Node double declaration:"+id)
except KeyError:
if id in self.symb_tab:
self.error_reporter.display(line_txt+" Node double declaration: "+id)
else:
if type == 'S':
node = self.current_macro.add_simple_node(id, 0,0)
elif type == 'P':
......@@ -161,7 +162,7 @@ def build_deg_transition(self, id, gc, note, line):
ori = self.check_ident_deg(id, line)
event = gc[0]
cond = gc[1]
note_txt = self.clean_note(note)
self.clean_note(note)
t = self.current_macro.add_transition(ori, target)
if event:
t.set_event(event)
......
// compiler for pint language import
//
// To generate a parser based on this grammar you'll need ANTLRv4, which you can
// get from 'https://www.antlr.org/download.html'.
grammar pintlang;
......@@ -110,7 +113,7 @@ def check_tr_rhs(self, cond, cname, clevel1, clevel2, line):
try:
lev = self.symb_tab[cname]
if clevel1>lev or clevel2>lev:
self.error_reporter(line_txt, "Incorrect level for:"+cname)
self.error_reporter(line_txt, "Incorrect level for: "+cname)
return
except KeyError:
self.error_reporter.display(line_txt, "Undeclared process: "+cname)
......@@ -128,7 +131,7 @@ def check_tr_rhs(self, cond, cname, clevel1, clevel2, line):
def tt_translate_cond(self, id_list, val_list, line_txt):
if len(id_list) != len(val_list):
self.error_reporter.display(line_txt, "Bad condition specification"+id_list.__str__())
self.error_reporter.display(line_txt, "Bad condition specification " + str(id_list))
return None
cond = id_list[0] + "_"+str(val_list[0])
for i in range(1, len(id_list)):
......
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