-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename lib file * Add parser for one lvt instruction * Add ;\n for all instruction * Add AST * Fix file location * Add header * Add exports * Fix TypeValue * Fix norm + returnValue * Fix * Fix type * Fix export * Merge remote-tracking branch 'origin/step4TypeCheck' into step-3rd-parser-lvt * Fix lvtrun files compil * Fix condition for parser * Fix norm * Fix func call for value * Add operation priority * Fix --------- Co-authored-by: guillaume abel <[email protected]>
- Loading branch information
1 parent
4e4f570
commit 5328948
Showing
12 changed files
with
729 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{- | ||
-- EPITECH PROJECT, 2023 | ||
-- Leviator Run | ||
-- File description: | ||
-- AST | ||
-} | ||
|
||
module AST | ||
( Type | ||
, Value (..) | ||
, Var | ||
, FuncCall | ||
, FuncPrototype | ||
, FuncDeclaration | ||
, Instruction (..) | ||
, VarDeclaration | ||
, VarAssignation | ||
, Condition | ||
, Symbol | ||
) where | ||
|
||
import Data.Int (Int32) | ||
|
||
type Symbol = String | ||
|
||
type Type = String | ||
|
||
data Value = | ||
Var String | ||
| FuncValue FuncCall | ||
| Boolean Bool | ||
| Integer Int32 | ||
| Character Char | ||
| StringView String | ||
| Void | ||
|
||
instance Show Value where | ||
show (Var x) = "V< " ++ show x ++ " >" | ||
show (FuncValue x) = "F< " ++ show x ++ " >" | ||
show (Boolean x) = "B< " ++ show x ++ " >" | ||
show (Integer x) = "I< " ++ show x ++ " >" | ||
show (Character x) = "C< " ++ show x ++ " >" | ||
show (StringView x) = "SV< " ++ show x ++ " >" | ||
show Void = "Void" | ||
|
||
instance Eq Value where | ||
(==) (Var x) (Var y) = x == y | ||
(==) (FuncValue x) (FuncValue y) = x == y | ||
(==) (Boolean x) (Boolean y) = x == y | ||
(==) (Integer x) (Integer y) = x == y | ||
(==) (Character x) (Character y) = x == y | ||
(==) (StringView x) (StringView y) = x == y | ||
(==) Void Void = True | ||
(==) _ _ = False | ||
|
||
-- Function | ||
|
||
type Var = (Symbol, Type) | ||
|
||
type FuncPrototype = (Symbol, [Var], Type) | ||
|
||
type FuncDeclaration = (FuncPrototype, [Instruction]) | ||
|
||
|
||
-- condition | ||
|
||
type Condition = (Value, [Instruction], [Instruction]) | ||
|
||
-- Instruction | ||
|
||
type FuncCall = (Symbol, [Value]) | ||
|
||
type VarDeclaration = (Var, Value) | ||
|
||
type VarAssignation = (Symbol, Value) | ||
|
||
data Instruction = | ||
Function FuncCall | ||
| Return Value | ||
| Declaration VarDeclaration | ||
| Assignation VarAssignation | ||
| Cond Condition | ||
|
||
instance Show Instruction where | ||
show (Function x) = | ||
"Function[< " ++ show x ++ " >]" | ||
show (Return x) = | ||
"Return[< " ++ show x ++ " >]" | ||
show (Declaration x) = | ||
"Declaration[< " ++ show x ++ " >]" | ||
show (Assignation x) = | ||
"Assignation[< " ++ show x ++ " >]" | ||
show (Cond x) = | ||
"Cond[< " ++ show x ++ " >]" | ||
|
||
instance Eq Instruction where | ||
(==) (Function x) (Function y) = x == y | ||
(==) (Return x) (Return y) = x == y | ||
(==) (Declaration x) (Declaration y) = x == y | ||
(==) (Assignation x) (Assignation y) = x == y | ||
(==) (Cond x) (Cond y) = x == y | ||
(==) _ _ = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.