commit 3d0f5ffee70a7229ed335571dcdb332e797356a1 Author: Michael Zhang Date: Sat Nov 23 13:50:07 2024 -0600 initial diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..76a93c0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*] +indent_style = space +indent_size = 2 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..e596947 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +export PATH="$HOME/Projects/silver/support/bin:$PATH" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..72fffab --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ablebash.jar +build.xml \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5799231 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +SOURCES := $(shell find . -name "*.sv") + +all: ablebash.jar + +ablebash.jar: $(SOURCES) + silver -I src ablebash ablebash diff --git a/src/ablebash/AbstractSyntax.sv b/src/ablebash/AbstractSyntax.sv new file mode 100644 index 0000000..5cf6c0c --- /dev/null +++ b/src/ablebash/AbstractSyntax.sv @@ -0,0 +1,4 @@ +grammar ablebash; + +nonterminal Item; + synthesized attribute n :: Integer occurs on Item_c; \ No newline at end of file diff --git a/src/ablebash/ConcreteSyntax.sv b/src/ablebash/ConcreteSyntax.sv new file mode 100644 index 0000000..08cb06a --- /dev/null +++ b/src/ablebash/ConcreteSyntax.sv @@ -0,0 +1,28 @@ +grammar ablebash; + +import silver:langutil; + +nonterminal Root; + synthesized attribute items :: [Item] occurs on Root; + +nonterminal Item_c with ast; + +-------------- Root -------------- + +concrete production root_cons r::Root ::= i::Item_c s::ItemSep_t j::Root { + r.items = i.ast :: j.items; +} + +concrete production root_one r::Root ::= i::Item_c { + r.items = i.ast :: []; +} + +concrete production root_nil r::Root ::= { + r.items = []; +} + +-------------- Item -------------- + +concrete production item_c i::Item_c ::= n::IntLit_t { + i.n = toInteger(n.lexeme); +} diff --git a/src/ablebash/Main.sv b/src/ablebash/Main.sv new file mode 100644 index 0000000..12c22d2 --- /dev/null +++ b/src/ablebash/Main.sv @@ -0,0 +1,39 @@ +grammar ablebash; + +parser parse::Root { ablebash; } + +function main IO ::= largs::[String] { + local attribute args :: String; + args = implode(" ", largs); + + local attribute result :: ParseResult; + result = parse(args, "<>"); + + -- local attribute r_cst :: Root_c ; + -- r_cst = result.parseTree ; + + -- local attribute r_ast :: Root ; + -- r_ast = r_cst.ast_Root ; + + local attribute print_success :: IO; + print_success = + print( "Command line expression: " ++ args ++ + -- "\n\n" ++ + -- "CST pretty print: " ++ r_cst.pp ++ + -- "\n\n" ++ + -- "AST pretty print: " ++ r_ast.pp ++ + -- "\n\n" ++ + -- "AST better pretty print: " ++ r_ast.bpp ++ + -- "\n\n" ++ + -- "Value: " ++ toString(r_ast.value) ++ + "\n\n"); + + local attribute print_failure :: IO; + print_failure = + print("Encountered a parse error:\n" ++ result.parseErrors ++ "\n"); + + return do { + new(if result.parseSuccess then print_success else print_failure); + return 0; + }; +} diff --git a/src/ablebash/Terminals.sv b/src/ablebash/Terminals.sv new file mode 100644 index 0000000..1da8ed0 --- /dev/null +++ b/src/ablebash/Terminals.sv @@ -0,0 +1,7 @@ +grammar ablebash; + +terminal IntLit_t /[0-9]+/; + +terminal ItemSep_t /(;|\r?\n)/; + +ignore terminal WhiteSpace_t /[ ]+/ ; \ No newline at end of file