Compare commits
No commits in common. "1a181095c6150c93902b9b1787a192425b77eb9d" and "76e2707156290971929331ca4207697576bd6024" have entirely different histories.
1a181095c6
...
76e2707156
@ -1,6 +0,0 @@
|
|||||||
texte name = "Anthony";
|
|
||||||
si name ne vaut pas "Anthony" alors {
|
|
||||||
afficher "C'est pas moi";
|
|
||||||
} sinon {
|
|
||||||
afficher "C'est moi";
|
|
||||||
}
|
|
8
spf.lark
8
spf.lark
@ -35,7 +35,6 @@ operator: expressionleft SAME_OP expression -> equal
|
|||||||
| NEG_OP expression -> neg
|
| NEG_OP expression -> neg
|
||||||
// string/list -> string/list
|
// string/list -> string/list
|
||||||
| SIZE_OP expression -> sizeof
|
| SIZE_OP expression -> sizeof
|
||||||
| expressionleft "[" expression "]" -> list_get
|
|
||||||
|
|
||||||
?type: BOOL_TYPE
|
?type: BOOL_TYPE
|
||||||
| INT_TYPE
|
| INT_TYPE
|
||||||
@ -46,8 +45,8 @@ declaration: type VARIABLE (EQUAL_SIGN expression)?
|
|||||||
|
|
||||||
assignation: VARIABLE EQUAL_SIGN expression
|
assignation: VARIABLE EQUAL_SIGN expression
|
||||||
|
|
||||||
loop: "tant" "que" expression "faire" "{" instruction_seq "}" -> while_loop
|
loop: "tant" "que" expression "faire" "{" (instruction)* "}" -> while_loop
|
||||||
| "pour" "chaque" type VARIABLE "dans" expression "faire" "{" instruction_seq "}" -> for_loop
|
| "pour" "chaque" type VARIABLE "dans" expression "faire" "{" (instruction)* "}" -> for_loop
|
||||||
|
|
||||||
?literal: ENTIER -> entier
|
?literal: ENTIER -> entier
|
||||||
| booleen
|
| booleen
|
||||||
@ -60,8 +59,7 @@ range: "[" expression? ":" expression? "]"
|
|||||||
controls: test
|
controls: test
|
||||||
| loop
|
| loop
|
||||||
|
|
||||||
test: "si" expression "alors" "{" instruction_seq "}" ("sinon" "{" instruction_seq "}")?
|
test: "si" expression "alors" "{" instruction* "}" ("sinon" "{" instruction* "}")?
|
||||||
instruction_seq: (instruction*)
|
|
||||||
|
|
||||||
?booleen: TRUE_KW -> true
|
?booleen: TRUE_KW -> true
|
||||||
| FALSE_KW -> false
|
| FALSE_KW -> false
|
||||||
|
27
spf.py
27
spf.py
@ -15,19 +15,13 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
self.variables = Variables(trace)
|
self.variables = Variables(trace)
|
||||||
|
|
||||||
def while_loop(self, el):
|
def while_loop(self, el):
|
||||||
while self.visit_children(el.children[0])[0]:
|
print("TODO: while")
|
||||||
self.visit_children(el.children[1])
|
cond = el.children[0]
|
||||||
|
instr = el.children[1:]
|
||||||
|
print(cond.pretty())
|
||||||
|
|
||||||
def for_loop(self, el):
|
def for_loop(self, el):
|
||||||
type = el.children[0].value
|
print("TODO: for")
|
||||||
name = el.children[1].value
|
|
||||||
self.variables.declare(type, name)
|
|
||||||
|
|
||||||
target = self.visit_children(el.children[2])[0]
|
|
||||||
for i in target:
|
|
||||||
self.variables.assign(name, i)
|
|
||||||
self.visit_children(el.children[3])
|
|
||||||
# TODO: delete the variable out of scope
|
|
||||||
|
|
||||||
def afficher(self, el):
|
def afficher(self, el):
|
||||||
ligne = ""
|
ligne = ""
|
||||||
@ -109,10 +103,6 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
|
|
||||||
sizeof = lambda self, el:len(self.visit_children(el)[1])
|
sizeof = lambda self, el:len(self.visit_children(el)[1])
|
||||||
|
|
||||||
def list_get(self, el):
|
|
||||||
(left, right) = self.visit_children(el)
|
|
||||||
return left[right]
|
|
||||||
|
|
||||||
|
|
||||||
def expression(self, el):
|
def expression(self, el):
|
||||||
return self.visit_children(el)[0]
|
return self.visit_children(el)[0]
|
||||||
@ -123,13 +113,6 @@ class SPFInterpreter(lark.visitors.Interpreter):
|
|||||||
def variable(self, el):
|
def variable(self, el):
|
||||||
return self.variables.get(el.children[0].value)
|
return self.variables.get(el.children[0].value)
|
||||||
|
|
||||||
def test(self,el):
|
|
||||||
if self.visit_children(el.children[0])[0]:
|
|
||||||
self.visit_children(el.children[1])
|
|
||||||
elif len(el.children) >= 3:
|
|
||||||
self.visit_children(el.children[2])
|
|
||||||
|
|
||||||
|
|
||||||
# Literals
|
# Literals
|
||||||
string = lambda self, el: el.children[0][1:-1]
|
string = lambda self, el: el.children[0][1:-1]
|
||||||
entier = lambda self, el: int(el.children[0])
|
entier = lambda self, el: int(el.children[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user