This commit is contained in:
Michael Zhang 2024-11-23 13:50:07 -06:00
commit 3d0f5ffee7
8 changed files with 90 additions and 0 deletions

3
.editorconfig Normal file
View file

@ -0,0 +1,3 @@
[*]
indent_style = space
indent_size = 2

1
.envrc Normal file
View file

@ -0,0 +1 @@
export PATH="$HOME/Projects/silver/support/bin:$PATH"

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
ablebash.jar
build.xml

6
Makefile Normal file
View file

@ -0,0 +1,6 @@
SOURCES := $(shell find . -name "*.sv")
all: ablebash.jar
ablebash.jar: $(SOURCES)
silver -I src ablebash ablebash

View file

@ -0,0 +1,4 @@
grammar ablebash;
nonterminal Item;
synthesized attribute n :: Integer occurs on Item_c;

View file

@ -0,0 +1,28 @@
grammar ablebash;
import silver:langutil;
nonterminal Root;
synthesized attribute items :: [Item] occurs on Root;
nonterminal Item_c with ast<Item>;
-------------- 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);
}

39
src/ablebash/Main.sv Normal file
View file

@ -0,0 +1,39 @@
grammar ablebash;
parser parse::Root { ablebash; }
function main IO<Integer> ::= largs::[String] {
local attribute args :: String;
args = implode(" ", largs);
local attribute result :: ParseResult<Root>;
result = parse(args, "<<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<Unit>;
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<Unit>;
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;
};
}

View file

@ -0,0 +1,7 @@
grammar ablebash;
terminal IntLit_t /[0-9]+/;
terminal ItemSep_t /(;|\r?\n)/;
ignore terminal WhiteSpace_t /[ ]+/ ;