diff --git a/src/gboml/ast/base.py b/src/gboml/ast/base.py index 6e5c4f2a075eb0bf94689c4f59a6619576a3e667..f42dc797426557d4d703c7c0df97508d12a36876 100644 --- a/src/gboml/ast/base.py +++ b/src/gboml/ast/base.py @@ -19,4 +19,4 @@ class NamedGBOMLObject(GBOMLObject): name: str -AnyGBOMLObject = typing.TypeVar('AnyGBOMLObject', bound=GBOMLObject) \ No newline at end of file +AnyGBOMLObject = typing.TypeVar('AnyGBOMLObject', bound=GBOMLObject) diff --git a/src/gboml/parsing.py b/src/gboml/parsing.py index a6c8ff0dbc01495109158c3f05259f57d50f7899..5241af531b8f0f564fc809fb2d55bcea02ccbb04 100644 --- a/src/gboml/parsing.py +++ b/src/gboml/parsing.py @@ -11,7 +11,9 @@ from gboml.tools.tree_modifier import modify, visit def _op_transform(op): return lambda *x, meta: ExpressionOp(op, list(x), meta=meta) def _bool_op_transform(op): return lambda *x, meta: BoolExpressionOp(op, list(x), meta=meta) -def gen_meta(lark_token: Token) -> Meta: return Meta(line=lark_token.line, column=lark_token.column, filename=None) +def gen_meta(lark_token: Token) -> Meta: + print(lark_token.line, lark_token.column) + return Meta(line=lark_token.line, column=lark_token.column, filename=None) def _vargs(f, data, children, _meta): @@ -242,4 +244,4 @@ class GBOMLParser: elif typ == DefinitionType.expression: return ExpressionDefinition(name, val, tags, meta=meta) else: - return ConstantDefinition(name, val, tags, meta=meta) \ No newline at end of file + return ConstantDefinition(name, val, tags, meta=meta) diff --git a/src/gboml/scope.py b/src/gboml/scope.py index 6a02d23dc5d5ee1c2ac556d361e583df53de502e..411de83f38c879ba2989cd5c1c5fadab2f9257ac 100644 --- a/src/gboml/scope.py +++ b/src/gboml/scope.py @@ -56,6 +56,7 @@ class NamedAstScope(Scope, Generic[T]): def __post_init__(self): self.name = self.ast.name + self.ast.scope = self super(NamedAstScope, self).__post_init__() diff --git a/src/main.py b/src/main.py old mode 100644 new mode 100755 index 83bfcd4dd06d4fe264ab51fc0aaaa7235c789b61..fd7c11da5e3ceae806570da5da5d250473129f30 --- a/src/main.py +++ b/src/main.py @@ -1,54 +1,72 @@ -from gboml.parsing import parse, parse_file +#!/usr/bin/env python3 -tree = parse("""#TIMEHORIZON - T = 8760; +from gboml.parsing import GBOMLParser +from gboml.semantic import semantic_check +from gboml.scope import RootScope + +tree = GBOMLParser().parse("""#TIMEHORIZON + T = 1; #GLOBAL - a = 2; - b = 2.2; - c = 2e2; - d = -1; - e = 2e-2; -#NODE nodeI = import nodeA from "hello.gboml"; -#NODE nodeI2 = import nodeA from "hello.gboml" with - a = 2; - b external; - c internal; -#NODE node1 - #PARAMETERS - a = 2; - b = import "lol.csv"; - #NODE A - #VARIABLES - external: x; - external: y; - #HYPEREDGE E - #PARAMETERS - a = 2; - #CONSTRAINTS - A.x == A.y; - #VARIABLES - internal: a; - external: b; - internal continuous: c[T]; - internal integer: d[T+2]; - internal binary: e[T-2]; - #CONSTRAINTS - 2+f(2,2,{2})*(2-2/2%2**2) == -2.2*0; - 2 >= 0; - 0 <= 2; - a == b; - named: a == b for i in [0:2] where ((i % 2) == 0) and i > 0 or (i < 0 or i != 0 and not i == i and i <= 0 and i >= 0); - SOS1 {a, b}; - SOS2 {a, b}; - sum(a*2 for a in [0:2]) == 2; - #OBJECTIVES - min named: a; - max: b[i] for i in [0:2*4] where i % 2 == 1; -#HYPEREDGE he1 = import lal from "x" with - a = 2; - b = 2; + b = 4; + +// Working example where x = -4 + +#NODE H +#VARIABLES +internal : x; +internal : y; +#CONSTRAINTS +x<=-4; +#OBJECTIVES +max : x + global.b; """) + # c = 2e2; + # d = -1; + # e = 2e-2; +# #NODE nodeI = import nodeA from "hello.gboml"; +# #NODE nodeI2 = import nodeA from "hello.gboml" with + # a = 2; + # b external; + # c internal; +# #NODE node1 + # #PARAMETERS + # a = 2; + # b = import "lol.csv"; + # #NODE A + # #VARIABLES + # external: x; + # external: y; + # #HYPEREDGE E + # #PARAMETERS + # a = 2; + # #CONSTRAINTS + # A.x == A.y; + # #VARIABLES + # internal: a; + # external: b; + # internal continuous: c[T]; + # internal integer: d[T+2]; + # internal binary: e[T-2]; + # #CONSTRAINTS + # 2+f(2,2,{2})*(2-2/2%2**2) == -2.2*0; + # 2 >= 0; + # 0 <= 2; + # a == b; + # named: a == b for i in [0:2] where ((i % 2) == 0) and i > 0 or (i < 0 or i != 0 and not i == i and i <= 0 and i >= 0); + # SOS1 {a, b}; + # SOS2 {a, b}; + # sum(a*2 for a in [0:2]) == 2; + # #OBJECTIVES + # min named: a; + # max: b[i] for i in [0:2*4] where i % 2 == 1; +# #HYPEREDGE he1 = import lal from "x" with + # a = 2; + # b = 2; +# """) print(tree) -print(tree.meta) +# print(tree.meta) +# print(tree.global_defs[0].meta) +rootScope = RootScope(tree) +semantic_check(rootScope) #parse_file("test/test1.txt")