Refactoring operators to include priority
This commit is contained in:
65
spf.lark
65
spf.lark
@@ -6,36 +6,41 @@ instruction: declaration ";"
|
||||
| ADD_KW expression "dans" VARIABLE ";" -> append
|
||||
| controls
|
||||
|
||||
expression: expressionleft // TODO: priorité des operator certainement fausse
|
||||
| operator
|
||||
// rule finishing by u are "UnambigiousED"
|
||||
expression: logical
|
||||
|
||||
expressionleft: literal
|
||||
| list
|
||||
| range
|
||||
| VARIABLE -> variable
|
||||
| "(" expression ")"
|
||||
logical: comparison logicalu?
|
||||
logicalu: AND_OP logical
|
||||
| OR_OP logical
|
||||
|
||||
//any -> bool
|
||||
operator: expressionleft SAME_OP expression -> equal
|
||||
| expressionleft DIFF_OP expression -> unequal
|
||||
//bool -> bool
|
||||
| expressionleft AND_OP expression -> and_op
|
||||
| expressionleft OR_OP expression -> or_op
|
||||
| NOT_OP expression -> not_op
|
||||
//int -> bool
|
||||
| expressionleft LT_OP expression -> lt
|
||||
| expressionleft LE_OP expression -> le
|
||||
| expressionleft GT_OP expression -> gt
|
||||
| expressionleft GE_OP expression -> ge
|
||||
//int -> int
|
||||
| expressionleft PLUS_OP expression -> plus
|
||||
| expressionleft MINUS_OP expression -> minus
|
||||
| expressionleft TIMES_OP expression -> time
|
||||
| expressionleft DIVIDE_OP expression -> divide
|
||||
| NEG_OP expression -> neg
|
||||
// string/list -> string/list
|
||||
| SIZE_OP expression -> sizeof
|
||||
| expressionleft "[" expression "]" -> list_get
|
||||
comparison: sumterm comparisonu?
|
||||
comparisonu: SAME_OP comparison
|
||||
| DIFF_OP comparison
|
||||
| LT_OP comparison
|
||||
| LE_OP comparison
|
||||
| GT_OP comparison
|
||||
| GE_OP comparison
|
||||
|
||||
sumterm: multterm sumtermu?
|
||||
sumtermu: PLUS_OP sumterm
|
||||
| MINUS_OP sumterm
|
||||
|
||||
multterm: priority multtermu?
|
||||
multtermu: TIMES_OP multterm
|
||||
| DIVIDE_OP multterm
|
||||
|
||||
priority: finalterm
|
||||
| finalterm "[" expression "]" -> list_get
|
||||
| SIZE_OP finalterm
|
||||
| NEG_OP finalterm
|
||||
| NOT_OP finalterm
|
||||
|
||||
|
||||
finalterm: "(" expression ")"
|
||||
| literal
|
||||
| list
|
||||
| range
|
||||
| VARIABLE -> variable
|
||||
|
||||
?type: BOOL_TYPE
|
||||
| INT_TYPE
|
||||
@@ -64,7 +69,7 @@ test: "si" expression "alors" "{" instruction_seq "}" ("sinon" "{" instruction_s
|
||||
instruction_seq: (instruction*)
|
||||
|
||||
?booleen: TRUE_KW -> true
|
||||
| FALSE_KW -> false
|
||||
| FALSE_KW -> false
|
||||
|
||||
TERMINAL: ";"
|
||||
|
||||
@@ -101,6 +106,8 @@ GE_OP: ">="
|
||||
|
||||
CONC_OP: "+"
|
||||
SIZE_OP: "taille"
|
||||
LBRAC: "["
|
||||
RBRAC: "]"
|
||||
|
||||
ADD_KW: "ajouter"
|
||||
SHOW_KW: "afficher"
|
||||
|
||||
Reference in New Issue
Block a user