mirror of
https://github.com/LucasVbr/croissant.git
synced 2026-05-13 17:12:10 +00:00
feat: Support Unary Operation #1
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
(* bin/main.ml *)
|
(* bin/main.ml *)
|
||||||
|
|
||||||
open Printf
|
open Printf
|
||||||
open Ast
|
open Ast.Print
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
let lexbuf = Lexing.from_channel stdin in
|
let lexbuf = Lexing.from_channel stdin in
|
||||||
|
|||||||
+4
-4
@@ -3,16 +3,16 @@
|
|||||||
(name croissant)
|
(name croissant)
|
||||||
(generate_opam_files true)
|
(generate_opam_files true)
|
||||||
(source (github LucasVbr/croissant))
|
(source (github LucasVbr/croissant))
|
||||||
(authors "LucasVbr")
|
(authors "LucasVbr <contact@lucasvbr.dev>")
|
||||||
(maintainers "LucasVbr")
|
(maintainers "LucasVbr <contact@lucasvbr.dev>")
|
||||||
(license LICENSE)
|
(license MIT)
|
||||||
;(documentation https://url/to/documentation)
|
;(documentation https://url/to/documentation)
|
||||||
|
|
||||||
(package
|
(package
|
||||||
(name croissant)
|
(name croissant)
|
||||||
(synopsis "A short synopsis")
|
(synopsis "A short synopsis")
|
||||||
(description "A longer description")
|
(description "A longer description")
|
||||||
(depends ocaml dune alcotest menhir ocamlformat)
|
(depends ocaml dune menhir ocamlformat (alcotest :with-test))
|
||||||
(tags
|
(tags
|
||||||
("Custom programming language" "French")
|
("Custom programming language" "French")
|
||||||
)
|
)
|
||||||
|
|||||||
+6
-2
@@ -1,6 +1,6 @@
|
|||||||
/* lib/parser.mly */
|
/* lib/parser.mly */
|
||||||
%{
|
%{
|
||||||
open Ast
|
open Ast.Syntax
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token <int> INT
|
%token <int> INT
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
%left "+" "-"
|
%left "+" "-"
|
||||||
%left "*" "/"
|
%left "*" "/"
|
||||||
//%nonassoc UMINUS
|
%nonassoc UMINUS
|
||||||
|
|
||||||
%start main
|
%start main
|
||||||
%type <source_file> main
|
%type <source_file> main
|
||||||
@@ -38,12 +38,16 @@ statement:
|
|||||||
|
|
||||||
expression:
|
expression:
|
||||||
| literal { $1 }
|
| literal { $1 }
|
||||||
|
| unary_expression { $1 }
|
||||||
| binary_expression { $1 }
|
| binary_expression { $1 }
|
||||||
| "(" expression ")" { $2 }
|
| "(" expression ")" { $2 }
|
||||||
|
|
||||||
literal:
|
literal:
|
||||||
| INT { IntegerLiteral($1) }
|
| INT { IntegerLiteral($1) }
|
||||||
|
|
||||||
|
unary_expression:
|
||||||
|
| MINUS expression %prec UMINUS { UnaryExpression(Negate, $2) }
|
||||||
|
|
||||||
binary_expression:
|
binary_expression:
|
||||||
| e1=expression PLUS e2=expression { BinaryExpression(Add, e1, e2) }
|
| e1=expression PLUS e2=expression { BinaryExpression(Add, e1, e2) }
|
||||||
| e1=expression MINUS e2=expression { BinaryExpression(Substract, e1, e2) }
|
| e1=expression MINUS e2=expression { BinaryExpression(Substract, e1, e2) }
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
;test/ast/dune
|
||||||
|
|
||||||
|
(test
|
||||||
|
(name print)
|
||||||
|
(libraries alcotest ast)
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user