├── lab-material ├── mips-material │ ├── codegen-examples │ │ ├── expr-mips │ │ │ ├── source2 │ │ │ ├── source1 │ │ │ ├── source3 │ │ │ ├── source4 │ │ │ ├── source2.tokens │ │ │ ├── t │ │ │ ├── source1.tokens │ │ │ ├── source3.tokens │ │ │ ├── source4.tokens │ │ │ ├── lexer │ │ │ ├── target2.s │ │ │ ├── multi-labels-ex.s │ │ │ ├── target3.s │ │ │ ├── target1.s │ │ │ └── workflow.log │ │ ├── expr-tac │ │ │ ├── code2 │ │ │ ├── code1 │ │ │ ├── code2.tokens │ │ │ ├── code1.tokens │ │ │ ├── lexer │ │ │ ├── workflow.log │ │ │ └── sdd.lisp │ │ ├── expr-zac │ │ │ ├── code2 │ │ │ ├── code1 │ │ │ ├── code2.tokens │ │ │ ├── code1.tokens │ │ │ ├── lexer │ │ │ ├── workflow.log │ │ │ └── sdd.lisp │ │ ├── expr-mips-float │ │ │ ├── source2 │ │ │ ├── source1 │ │ │ ├── source2n │ │ │ ├── source3 │ │ │ ├── source4 │ │ │ ├── source2.tokens │ │ │ ├── source2n.tokens │ │ │ ├── source3.tokens │ │ │ ├── source1.tokens │ │ │ ├── source3n │ │ │ ├── source4.tokens │ │ │ ├── source1n │ │ │ ├── source3n.tokens │ │ │ ├── source1n.tokens │ │ │ ├── lexer │ │ │ ├── multi-labels-ex.s │ │ │ ├── target2.s │ │ │ ├── target_source2.s │ │ │ ├── target_source2n.s │ │ │ ├── indirect-addr-by-local-var.s │ │ │ ├── target3.s │ │ │ ├── target_source3.s │ │ │ ├── target1.s │ │ │ ├── target_source3n.s │ │ │ ├── target_source1n.s │ │ │ └── target_source1.s │ │ ├── ex3 │ │ │ ├── source.supervision │ │ │ ├── source.supervision.tokens │ │ │ ├── lexer │ │ │ └── workflow.log │ │ └── ex2 │ │ │ ├── source.ccg.tokens │ │ │ ├── source.ccg │ │ │ ├── lexer │ │ │ └── workflow.log │ ├── MIPSfunctions.pdf │ ├── procedure-call.gif │ ├── SPIM_instruction-set.pdf │ ├── spim-procedure-calls.pdf │ ├── MIPSCallingConventionsSummary.pdf │ ├── spim-procedure-calls-basic.md │ └── README.md ├── old_material │ ├── antLR-material │ │ ├── README.md │ │ ├── balanced-parentheses │ │ │ ├── data1 │ │ │ ├── data2 │ │ │ ├── data3 │ │ │ ├── data4 │ │ │ ├── bp.tokens │ │ │ ├── bpLexer.tokens │ │ │ ├── bpLexer.class │ │ │ ├── bpListener.class │ │ │ ├── bpParser.class │ │ │ ├── bpBaseListener.class │ │ │ ├── bpParser$DataContext.class │ │ │ ├── bpParser$ProgContext.class │ │ │ ├── bpParser$StartContext.class │ │ │ ├── bpParser$StuffContext.class │ │ │ ├── bp.workflow │ │ │ ├── EvalVisitor.java │ │ │ ├── bp.g4 │ │ │ ├── bp.interp │ │ │ ├── bpListener.java │ │ │ ├── bpLexer.interp │ │ │ ├── bpBaseListener.java │ │ │ └── bpLexer.java │ │ ├── language-L │ │ │ ├── data2 │ │ │ ├── data3 │ │ │ ├── data1 │ │ │ ├── data4 │ │ │ ├── lLexer.class │ │ │ ├── lParser.class │ │ │ ├── L-language.pdf │ │ │ ├── lListener.class │ │ │ ├── lBaseListener.class │ │ │ ├── lParser$EContext.class │ │ │ ├── lParser$FContext.class │ │ │ ├── lParser$SContext.class │ │ │ ├── lParser$TContext.class │ │ │ ├── lParser$DefContext.class │ │ │ ├── lParser$StartContext.class │ │ │ ├── l.tokens │ │ │ ├── lLexer.tokens │ │ │ ├── l.workflow │ │ │ ├── l.g4 │ │ │ ├── l.interp │ │ │ ├── lListener.java │ │ │ ├── lLexer.interp │ │ │ ├── lBaseListener.java │ │ │ └── lLexer.java │ │ ├── language-L-bad-trees │ │ │ ├── data2 │ │ │ ├── data3 │ │ │ ├── data1 │ │ │ ├── .l.g4.swp │ │ │ ├── lLexer.class │ │ │ ├── lParser.class │ │ │ ├── L-language.pdf │ │ │ ├── lListener.class │ │ │ ├── lBaseListener.class │ │ │ ├── lParser$FContext.class │ │ │ ├── lParser$SContext.class │ │ │ ├── lParser$TContext.class │ │ │ ├── lParser$DefContext.class │ │ │ ├── lParser$StartContext.class │ │ │ ├── l.tokens │ │ │ ├── lLexer.tokens │ │ │ ├── l.workflow │ │ │ ├── l.g4 │ │ │ ├── l.interp │ │ │ ├── lListener.java │ │ │ ├── lLexer.interp │ │ │ ├── lBaseListener.java │ │ │ └── lLexer.java │ │ └── antlr-parse-trees.pdf │ ├── gnu-lightning │ │ └── GNU-lightning.pdf │ └── lalr-material │ │ ├── README.md │ │ └── symbol-table.lisp ├── riscv-material │ └── riscv-spec.pdf ├── sly-material │ ├── README.md │ └── cb-sly-example │ │ ├── hello-world-bad.src.log │ │ ├── pftl.src.log │ │ ├── acid-test.src.log │ │ ├── acid-test2.src.log │ │ ├── hello-world.src.log │ │ ├── README.md │ │ ├── deco.py │ │ ├── acid-test.src │ │ ├── hello-world-bad.src │ │ ├── hello-world.src │ │ ├── hello-world.tc │ │ ├── hello-world.tc.lisp │ │ ├── acid-test2.tc │ │ ├── acid-test2.tc.lisp │ │ ├── acid-test2.src │ │ ├── acid-test.tc │ │ └── acid-test.tc.lisp └── README.md ├── project-material ├── project_1_for_students │ ├── lexer_tests │ │ ├── test3.txt │ │ ├── test2.txt │ │ ├── test1.txt │ │ ├── test4.txt │ │ ├── test3.txt.toks │ │ ├── test5.txt │ │ ├── test4.txt.toks │ │ ├── test2.txt.toks │ │ ├── test1.txt.toks │ │ └── test5.txt.toks │ ├── parser.py │ ├── parser_tests │ │ ├── test1.vox.ast.pkl │ │ ├── test2.vox.ast.pkl │ │ ├── test3.vox.ast.pkl │ │ ├── test4.vox.ast.pkl │ │ ├── test5.vox.ast.pkl │ │ ├── test5.vox │ │ ├── test5.vox.ast │ │ ├── test4.vox │ │ ├── test1.vox │ │ ├── test2.vox │ │ ├── test3.vox │ │ ├── test3.vox.ast │ │ ├── test4.vox.ast │ │ ├── test2.vox.ast │ │ └── test1.vox.ast │ ├── project1_submission_details.pdf │ ├── lexer.py │ ├── misc.py │ └── tester.py ├── old_projects │ ├── vspecs-2019.pdf │ ├── project1 │ │ └── README.md │ └── project2 │ │ └── README.md ├── project1_minitestcases │ ├── vec.v │ ├── hw.v │ ├── bad_decl.v │ ├── vec_badcomp.v │ ├── hw_bad.v │ ├── comp_stmt.v │ └── comp_stmt_bad.v ├── vox_grammar.txt ├── project1_solutions │ ├── lexer.py │ └── misc.py └── README.md ├── cb-lectures-notes ├── README.md ├── 2-Lexical-analysis-scanning.pdf ├── 3-Syntactic-analysis-parsing.pdf ├── 1-Introduction-and-walk-through.pdf ├── 4-2-Runtime-Paramater-Passing.pdf ├── 4-Semantic-analysis-code-runtime.pdf └── 5-Compiling-Functional-Languages.pdf ├── examples └── README.md └── README.md /lab-material/mips-material/codegen-examples/expr-mips/source2: -------------------------------------------------------------------------------- 1 | b := -f/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/code2: -------------------------------------------------------------------------------- 1 | b := -f/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/code2: -------------------------------------------------------------------------------- 1 | b := -f/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source2: -------------------------------------------------------------------------------- 1 | b := -f/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source1: -------------------------------------------------------------------------------- 1 | a := b+c*d-(- e+f)/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/code1: -------------------------------------------------------------------------------- 1 | a := b+c*d-(- e+f)/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/code1: -------------------------------------------------------------------------------- 1 | a := b+c*d-(- e+f)/5; 2 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test3.txt: -------------------------------------------------------------------------------- 1 | .43534543.435345345 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/README.md: -------------------------------------------------------------------------------- 1 | Some example code for antlr v4 2 | 3 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/data1: -------------------------------------------------------------------------------- 1 | ((A))(_hah)(((125))) 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/data2: -------------------------------------------------------------------------------- 1 | (A)(125)(_MINE)(+) 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/data3: -------------------------------------------------------------------------------- 1 | (_hah)(((5)))((A)) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source1: -------------------------------------------------------------------------------- 1 | a := b+c*d-(- e+f)/5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source3: -------------------------------------------------------------------------------- 1 | a := b+c*78.45-(- e+f)/12.5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source4: -------------------------------------------------------------------------------- 1 | a :== b+c*78.45-(- e+f)/12.5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source2n: -------------------------------------------------------------------------------- 1 | f := 12.0; 2 | b := -f/5; 3 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source3: -------------------------------------------------------------------------------- 1 | a := b+c*78.45-(- e+f)/12.5; 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source4: -------------------------------------------------------------------------------- 1 | a :== b+c*78.45-(- e+f)/12.5; 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/data4: -------------------------------------------------------------------------------- 1 | (_hah)(((125)))((A12))((((+)))) 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/data2: -------------------------------------------------------------------------------- 1 | x=0 2 | y=1 3 | x => y => 0 => 1 4 | $ 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source2.tokens: -------------------------------------------------------------------------------- 1 | (b |:| |=| |-| f |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/code2.tokens: -------------------------------------------------------------------------------- 1 | ( b |:| |=| |-| f |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/code2.tokens: -------------------------------------------------------------------------------- 1 | ( b |:| |=| |-| f |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/data3: -------------------------------------------------------------------------------- 1 | x = 0 2 | y = 1 3 | z = 1 4 | ~~x => y 5 | $ 6 | -------------------------------------------------------------------------------- /cb-lectures-notes/README.md: -------------------------------------------------------------------------------- 1 | These are my personal slides. For nonprofit use only. 2 | 3 | -cem bozsahin 4 | 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source2.tokens: -------------------------------------------------------------------------------- 1 | (b |:| |=| |-| f |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/data2: -------------------------------------------------------------------------------- 1 | x=0 2 | y=1 3 | x => y => 0 => 1 4 | $ 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/data1: -------------------------------------------------------------------------------- 1 | x = 0 => 1 2 | y = x => 1 3 | ~ y => x => 1 4 | $ 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/data4: -------------------------------------------------------------------------------- 1 | x = 0 => 1 2 | y = x => 1 3 | y => ~ x => 1 4 | $ 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/data3: -------------------------------------------------------------------------------- 1 | x = 0 2 | y = 1 3 | z = 1 4 | ~~x => y 5 | $ 6 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/data1: -------------------------------------------------------------------------------- 1 | x = 0 => 1 2 | y = x => 1 3 | ~ y => x => 1 4 | $ 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/t: -------------------------------------------------------------------------------- 1 | (a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex3/source.supervision: -------------------------------------------------------------------------------- 1 | john saw the man : saw man john; 2 | mary walked : walk !mary; 3 | -------------------------------------------------------------------------------- /lab-material/riscv-material/riscv-spec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/riscv-material/riscv-spec.pdf -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test2.txt: -------------------------------------------------------------------------------- 1 | .435435 = == funwhile whileee fun(){}n"fun" "[" []];;; "var else" if nil 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/MIPSfunctions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/mips-material/MIPSfunctions.pdf -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source2n.tokens: -------------------------------------------------------------------------------- 1 | (f |:| |=| 12.0 |;| 2 | b |:| |=| |-| f |/| 5 |;| ) 3 | -------------------------------------------------------------------------------- /lab-material/mips-material/procedure-call.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/mips-material/procedure-call.gif -------------------------------------------------------------------------------- /project-material/old_projects/vspecs-2019.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/old_projects/vspecs-2019.pdf -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test1.txt: -------------------------------------------------------------------------------- 1 | whileee while he!+-*/34234.234=="fun"fun funnn ifelse if else ===>=>>=<=<== "test 2 | -------------------------------------------------------------------------------- /cb-lectures-notes/2-Lexical-analysis-scanning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/2-Lexical-analysis-scanning.pdf -------------------------------------------------------------------------------- /cb-lectures-notes/3-Syntactic-analysis-parsing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/3-Syntactic-analysis-parsing.pdf -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source1.tokens: -------------------------------------------------------------------------------- 1 | ( a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source3.tokens: -------------------------------------------------------------------------------- 1 | (a |:| |=| b |+| c |*| 78.45 |-| |(| |-| e |+| f |)| |/| 12.5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/code1.tokens: -------------------------------------------------------------------------------- 1 | ( a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/code1.tokens: -------------------------------------------------------------------------------- 1 | ( a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser.py: -------------------------------------------------------------------------------- 1 | import sly 2 | import lexer 3 | 4 | class Parser(sly.Parser): 5 | tokens = lexer.Lexer.tokens 6 | -------------------------------------------------------------------------------- /cb-lectures-notes/1-Introduction-and-walk-through.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/1-Introduction-and-walk-through.pdf -------------------------------------------------------------------------------- /cb-lectures-notes/4-2-Runtime-Paramater-Passing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/4-2-Runtime-Paramater-Passing.pdf -------------------------------------------------------------------------------- /lab-material/mips-material/SPIM_instruction-set.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/mips-material/SPIM_instruction-set.pdf -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex3/source.supervision.tokens: -------------------------------------------------------------------------------- 1 | (john saw the man |:| saw man john |;| 2 | mary walked |:| walk !mary |;| ) 3 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source3.tokens: -------------------------------------------------------------------------------- 1 | (a |:| |=| b |+| c |*| 78.45 |-| |(| |-| e |+| f |)| |/| 12.5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/source4.tokens: -------------------------------------------------------------------------------- 1 | (a |:| |=| |=| b |+| c |*| 78.45 |-| |(| |-| e |+| f |)| |/| 12.5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/spim-procedure-calls.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/mips-material/spim-procedure-calls.pdf -------------------------------------------------------------------------------- /project-material/project1_minitestcases/vec.v: -------------------------------------------------------------------------------- 1 | var fibo5 = [1,1,2,3,5]; 2 | 3 | // just bad syntax for comparison 4 | // 5 | if fibo[3 == 5 print "oops"; 6 | -------------------------------------------------------------------------------- /cb-lectures-notes/4-Semantic-analysis-code-runtime.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/4-Semantic-analysis-code-runtime.pdf -------------------------------------------------------------------------------- /cb-lectures-notes/5-Compiling-Functional-Languages.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/cb-lectures-notes/5-Compiling-Functional-Languages.pdf -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source1.tokens: -------------------------------------------------------------------------------- 1 | ( a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source3n: -------------------------------------------------------------------------------- 1 | b := 10.0; 2 | c := 12.0; 3 | e := 14.0; 4 | f := 16.2; 5 | a := b+c*78.45-(- e+f)/12.5; 6 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source4.tokens: -------------------------------------------------------------------------------- 1 | (a |:| |=| |=| b |+| c |*| 78.45 |-| |(| |-| e |+| f |)| |/| 12.5 |;| ) 2 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source1n: -------------------------------------------------------------------------------- 1 | b := 5.0; 2 | c := 2.0; 3 | d := 10.0; 4 | e := 10.0; 5 | f := 20.0; 6 | a := b+c*d-(- e+f)/5; 7 | -------------------------------------------------------------------------------- /lab-material/old_material/gnu-lightning/GNU-lightning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/gnu-lightning/GNU-lightning.pdf -------------------------------------------------------------------------------- /lab-material/sly-material/README.md: -------------------------------------------------------------------------------- 1 | These are local examples of use of sly.py 2 | 3 | There are more examples here. 4 | -------------------------------------------------------------------------------- /project-material/project1_minitestcases/hw.v: -------------------------------------------------------------------------------- 1 | // this should parse OK 2 | // 3 | var a = true; 4 | 5 | if #a print "hello world" ; else print "no one hears me"; 6 | -------------------------------------------------------------------------------- /lab-material/mips-material/MIPSCallingConventionsSummary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/mips-material/MIPSCallingConventionsSummary.pdf -------------------------------------------------------------------------------- /project-material/project1_minitestcases/bad_decl.v: -------------------------------------------------------------------------------- 1 | var a = 3; // the first 3 decl should be ok. 2 | var b = true; 3 | var c; 4 | var d // bad 5 | 6 | a = false; 7 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/antlr-parse-trees.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/antlr-parse-trees.pdf -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lLexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lLexer.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bp.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | WS=3 4 | OP=4 5 | NUM=5 6 | ID=6 7 | KEYWD=7 8 | NEWLINE=8 9 | '('=1 10 | ')'=2 11 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/L-language.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/L-language.pdf -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lListener.class -------------------------------------------------------------------------------- /project-material/project1_minitestcases/vec_badcomp.v: -------------------------------------------------------------------------------- 1 | var fibo5 = [1,1,2,3,5]; 2 | 3 | // cexpr takes makes arithmetic comparison, not logical. 4 | if # fibo[3] == 5 print "oops"; 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | WS=3 4 | OP=4 5 | NUM=5 6 | ID=6 7 | KEYWD=7 8 | NEWLINE=8 9 | '('=1 10 | ')'=2 11 | -------------------------------------------------------------------------------- /project-material/project1_minitestcases/hw_bad.v: -------------------------------------------------------------------------------- 1 | var a = true; 2 | 3 | // here, print is a simple stmt but does not terminate 4 | if #a print "hello world" else print "no one hears me"; 5 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test1.vox.ast.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/parser_tests/test1.vox.ast.pkl -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test2.vox.ast.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/parser_tests/test2.vox.ast.pkl -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test3.vox.ast.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/parser_tests/test3.vox.ast.pkl -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test4.vox.ast.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/parser_tests/test4.vox.ast.pkl -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test5.vox.ast.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/parser_tests/test5.vox.ast.pkl -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/.l.g4.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/.l.g4.swp -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lBaseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lBaseListener.class -------------------------------------------------------------------------------- /project-material/project_1_for_students/project1_submission_details.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/project-material/project_1_for_students/project1_submission_details.pdf -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpLexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpLexer.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lLexer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lLexer.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$EContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$EContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$FContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$FContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$SContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$SContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$TContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$TContext.class -------------------------------------------------------------------------------- /project-material/project1_minitestcases/comp_stmt.v: -------------------------------------------------------------------------------- 1 | var a; 2 | var b; 3 | if true 4 | while false 5 | { a = 3; 6 | b = false; 7 | } // this should parse OK 8 | else b = true; 9 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test4.txt: -------------------------------------------------------------------------------- 1 | test.nofieldsinvox //whoa a comment else if if else 2 | while fun //another one 1231242 3 | //.123123 4 | 1231.312312 .12313. //"test" 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpListener.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpParser.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/L-language.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/L-language.pdf -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lListener.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$DefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$DefContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lParser$StartContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L/lParser$StartContext.class -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test3.txt.toks: -------------------------------------------------------------------------------- 1 | Tokens: 2 | Token(type='ERROR', value='.', lineno=1, index=0, end=1) 3 | Token(type='NUMBER', value=43534543.435345344, lineno=1, index=1, end=19) -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpBaseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpBaseListener.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lBaseListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lBaseListener.class -------------------------------------------------------------------------------- /project-material/project1_minitestcases/comp_stmt_bad.v: -------------------------------------------------------------------------------- 1 | var a; 2 | var b; 3 | if true 4 | while false 5 | { a = 3; 6 | b = false; 7 | }; // compounds don't terminate by ; 8 | else b = true; 9 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser$FContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser$FContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser$SContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser$SContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser$TContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser$TContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpParser$DataContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpParser$DataContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpParser$ProgContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpParser$ProgContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser$DefContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser$DefContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lParser$StartContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/language-L-bad-trees/lParser$StartContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpParser$StartContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpParser$StartContext.class -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpParser$StuffContext.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bozsahin/ceng444/HEAD/lab-material/old_material/antLR-material/balanced-parentheses/bpParser$StuffContext.class -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test5.txt: -------------------------------------------------------------------------------- 1 | eand or orand andor ==or else iffun fun ""else"" test.123.21332 test 123notvarname truefalse true // false "false" 2 | false "true" "falsee" falsee falsetrue truee 3 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex2/source.ccg.tokens: -------------------------------------------------------------------------------- 1 | ( 2 | 3 | 4 | 5 | john n |:=| s |/| |(| s |\\| np |)| |:| |\\| p |.| p !john |;| 6 | likes v |:=| |(| s |\\| np |)| |/| np |:| |\\| x |\\| y |.| !likes x y |;| ) 7 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source3n.tokens: -------------------------------------------------------------------------------- 1 | (b |:| |=| 10.0 |;| 2 | c |:| |=| 12.0 |;| 3 | e |:| |=| 14.0 |;| 4 | f |:| |=| 16.2 |;| 5 | a |:| |=| b |+| c |*| 78.45 |-| |(| |-| e |+| f |)| |/| 12.5 |;| ) 6 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/l.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | T__5=6 7 | T__6=7 8 | T__7=8 9 | WS=9 10 | NEWLINE=10 11 | PL=11 12 | '$'=1 13 | '='=2 14 | '=>'=3 15 | '('=4 16 | ')'=5 17 | '~'=6 18 | '0'=7 19 | '1'=8 20 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/source1n.tokens: -------------------------------------------------------------------------------- 1 | (b |:| |=| 5.0 |;| 2 | c |:| |=| 2.0 |;| 3 | d |:| |=| 10.0 |;| 4 | e |:| |=| 10.0 |;| 5 | f |:| |=| 20.0 |;| 6 | a |:| |=| b |+| c |*| d |-| |(| |-| e |+| f |)| |/| 5 |;| ) 7 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $1: input $2: tokens wrapped in () 3 | # -cem bozsahin 4 | sed -e 's/\([A-Za-z][A-Za-z]*\)/ \1 /g' -e 's/\([\:\=\+\/\*()]\)/ |\1| /g' -e 's/-/ |-| /g' -e 's/;/ |;| /g' -e '1,1s/^/(/' -e '$s/$/)/' $1 > $2 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $1: input $2: tokens wrapped in () 3 | # -cem bozsahin 4 | sed -e 's/\([A-Za-z][A-Za-z]*\)/ \1 /g' -e 's/\([\:\=\+\/\*()]\)/ |\1| /g' -e 's/-/ |-| /g' -e 's/;/ |;| /g' -e '1,1s/^/(/' -e '$s/$/)/' $1 > $2 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $1: input $2: tokens wrapped in () 3 | # -cem bozsahin 4 | sed -e 's/\([A-Za-z][A-Za-z]*\)/ \1 /g' -e 's/\([\:\=\+\/\*()]\)/ |\1| /g' -e 's/-/ |-| /g' -e 's/;/ |;| /g' -e '1,1s/^/(/' -e '$s/$/)/' $1 > $2 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | T__5=6 7 | T__6=7 8 | T__7=8 9 | WS=9 10 | NEWLINE=10 11 | PL=11 12 | '$'=1 13 | '='=2 14 | '=>'=3 15 | '('=4 16 | ')'=5 17 | '~'=6 18 | '0'=7 19 | '1'=8 20 | -------------------------------------------------------------------------------- /lab-material/old_material/lalr-material/README.md: -------------------------------------------------------------------------------- 1 | Some code for help with LALR parser. 2 | 3 | Also note the repo called yalalr, which includes and interface to the parser 4 | and some scripts to download and install it. There are also worked out 5 | examples in it. 6 | 7 | -cemB 8 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test5.vox: -------------------------------------------------------------------------------- 1 | var important_advice = "Start writing your parser early!!! :)"; 2 | fun fibonacci(n){ 3 | if n <= 1 return 1; 4 | else return fibonacci(n-1)+fibonacci(n-2); 5 | } 6 | print important_advice; 7 | print fibonacci(10); 8 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # $1: input $2: tokens wrapped in () 3 | # -cem bozsahin 4 | sed -e 's/\([A-Za-z][A-Za-z]*\)/ \1 /g' -e 's/\([\:\=\+\/\*()]\)/ |\1| /g' -e 's/-/ |-| /g' -e 's/;/ |;| /g' -e '1,1s/^/(/' -e '$s/$/)/' $1 > $2 5 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/l.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | T__5=6 7 | T__6=7 8 | T__7=8 9 | WS=9 10 | NEWLINE=10 11 | PL=11 12 | '$'=1 13 | '='=2 14 | '=>'=3 15 | '('=4 16 | ')'=5 17 | '~'=6 18 | '0'=7 19 | '1'=8 20 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | T__5=6 7 | T__6=7 8 | T__7=8 9 | WS=9 10 | NEWLINE=10 11 | PL=11 12 | '$'=1 13 | '='=2 14 | '=>'=3 15 | '('=4 16 | ')'=5 17 | '~'=6 18 | '0'=7 19 | '1'=8 20 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/l.workflow: -------------------------------------------------------------------------------- 1 | // this is what i did to get it up and running -cemB 2 | antlr4 l.g4 3 | javac l*.java 4 | grun l start -gui data1 // LL-ness test 5 | grun l start -gui data2 // associativity check 6 | grun l start -gui data3 // precedence check 7 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex2/source.ccg: -------------------------------------------------------------------------------- 1 | %this will tokenize differently depending on your lexer. 2 | % ex2.lexer knows about ccglab's comment operator. 3 | % but ex-expr.lexer is more generic lispwrapper 4 | 5 | john n := s/(s\np):\p.p !john; 6 | likes v := (s\np)/np : \x\y.!likes x y; 7 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/l.workflow: -------------------------------------------------------------------------------- 1 | // this is what i did to get it up and running -cemB 2 | antlr4 l.g4 3 | javac l*.java 4 | grun l start -gui data1 // LL-ness test 5 | grun l start -gui data2 // associativity check 6 | grun l start -gui data3 // precedence check 7 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world-bad.src.log: -------------------------------------------------------------------------------- 1 | file: hello-world-bad.src 2 | bad entry in line 14 3 | bad entry in line 18 4 | bad entry in line 22 5 | bad entry in line 30 6 | bad entry in line 31 7 | bad entry in line 32 8 | bad entry in line 41 9 | bad entry in line 42 10 | 11 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/target2.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | t368: .word 0 4 | F: .word 0 5 | t369: .word 0 6 | B: .word 0 7 | 8 | .text 9 | 10 | main: 11 | lw $t1,F 12 | sub $t0,$zero,$t1 13 | sw $t0,t368 14 | lw $t0,t368 15 | li $t1,5 16 | div $t0,$t0,$t1 17 | sw $t0,t369 18 | lw $t0,t369 19 | sw $t0,B 20 | -------------------------------------------------------------------------------- /project-material/old_projects/project1/README.md: -------------------------------------------------------------------------------- 1 | This directory includes project 1 tasks. The language specs are in the upper directory. 2 | 3 | Task: Design an LL parser and lexical analyzer in antLR v4 for the language V. It should output an AST and Symbol table if 4 | the input is well-formed, errors if it is not. 5 | 6 | Deadline: November 30, 2019, midnight. 7 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bp.workflow: -------------------------------------------------------------------------------- 1 | // this is what i did to get it up and running -cemB 2 | antlr4 bp.g4 3 | javac bp*.java 4 | grun bp prog -gui data2 5 | grun bp prog -tokens data2 // shows the tokens. nice for debugging (if token is not what you think, look at internal match) 6 | grun bp prog -tree data2 // shows the parse tree, and in Lisp format! how convenient 7 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test5.vox.ast: -------------------------------------------------------------------------------- 1 | TOP_LVL VAR_DECLS: 2 | var important_advice = "Start writing your parser early!!! :)"; 3 | TOP_LVL FUN_DECLS: 4 | fun fibonacci(n){ 5 | VAR_DECLS: 6 | 7 | STMTS: 8 | if (Lc<= n 1.0) return 1.0; else return (A+ fibonacci((A- n 1.0)) fibonacci((A- n 2.0))); endif 9 | } 10 | TOP_LVL STMTS: 11 | print important_advice; 12 | print fibonacci(10.0); -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | In this folder you will see examples of code generation from previous offerings of the course. 2 | 3 | There are also examples in yalalr repo. 4 | 5 | Ahmet Gulden's repo 6 | 7 | Berk Ozbalci's repo 8 | 9 | Thanks everyone for sharing. 10 | 11 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test4.vox: -------------------------------------------------------------------------------- 1 | //a program full of semantic errors (that we don't check in this assignment) 2 | var a; 3 | 4 | var b = [3, 5]; 5 | 6 | var c = [true, false, b]; 7 | fun a(){} 8 | fun b(a,b){ 9 | var c = a((#a)); 10 | while(#a[b+3]){} 11 | if true if true if true {var c; a = 3; b= 5;} else a = 5; else a =6; 12 | return b; 13 | } 14 | a = "hello"; 15 | a = a[a[a[a+2]]]+3; 16 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/EvalVisitor.java: -------------------------------------------------------------------------------- 1 | public static class EvalVisitor extends LExprBaseVisitor { public Integer visitMult(LExprParser.MultContext ctx) { 2 | return visit(ctx.e(0)) * visit(ctx.e(1)); } 3 | public Integer visitAdd(LExprParser.AddContext ctx) { return visit(ctx.e(0)) + visit(ctx.e(1)); 4 | } 5 | public Integer visitInt(LExprParser.IntContext ctx) { return Integer.valueOf(ctx.INT().getText()); 6 | } } 7 | 8 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/multi-labels-ex.s: -------------------------------------------------------------------------------- 1 | # this example compiles OK by MIPS assembler; multiple labels on same instruction is allowed 2 | # -cem bozsahin 3 | .data 4 | t368: .word 0 5 | t369: .word 0 6 | F: .word 0 7 | B: .word 0 8 | .text 9 | lw $t1,F 10 | l1: 11 | l2: 12 | sub $t0,$zero,$t1 13 | sw $t0,t368 14 | lw $t0,t368 15 | l3: 16 | l4: 17 | l5: 18 | li $t1,5 19 | div $t0,$t0,$t1 20 | sw $t0,t369 21 | lw $t0,t369 22 | sw $t0,B 23 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/multi-labels-ex.s: -------------------------------------------------------------------------------- 1 | # this example compiles OK by MIPS assembler; multiple labels on same instruction is allowed 2 | # -cem bozsahin 3 | .data 4 | t368: .word 0 5 | t369: .word 0 6 | F: .word 0 7 | B: .word 0 8 | .text 9 | lw $t1,F 10 | l1: 11 | l2: 12 | sub $t0,$zero,$t1 13 | sw $t0,t368 14 | lw $t0,t368 15 | l3: 16 | l4: 17 | l5: 18 | li $t1,5 19 | div $t0,$t0,$t1 20 | sw $t0,t369 21 | lw $t0,t369 22 | sw $t0,B 23 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test1.vox: -------------------------------------------------------------------------------- 1 | var a; 2 | var b; 3 | var y; 4 | var b; 5 | fun f(a, b, d){ 6 | var c; 7 | var d; 8 | e = #d; 9 | if x == 3 { 10 | var d; 11 | var e = f(); 12 | var f = d; 13 | var c; 14 | f(); 15 | #345; 16 | & 17 | 456; 18 | e = y+3; 19 | } 20 | } 21 | a = --a+3*5-4+f; 22 | e = 345; 23 | while(a == 3){ 24 | x = 5; 25 | if true{ 26 | var x; 27 | var z; 28 | var x; 29 | for(;a == 3;y = x+1) 30 | }} 31 | } -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test2.vox: -------------------------------------------------------------------------------- 1 | var a; 2 | var b; 3 | var z = 100; 4 | fun f(f,f,f){ 5 | var f; 6 | var x = 0; 7 | var z = 0; 8 | fun g(){} //erroneous 9 | for(x=0;x < 10;x = x+1){ 10 | var z; //scopes are cool! 11 | y = y+1; 12 | while y > 0 { 13 | var q = [2,4,6,true,false,#f(),undeclared]; 14 | y = y-1; 15 | z = z+x; 16 | if #true {} //wont parse 17 | if true q = y-1; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lab-material/README.md: -------------------------------------------------------------------------------- 1 | sly, antLR, LALR, MIPS, SPIM, Lisp material go here. 2 | 3 | sly is python's lex and yacc. 4 | 5 | antLR is easier from its complete jar file. Build can be tricky (it was for me). 6 | 7 | We don't need developer tools like maven for antLR. 8 | 9 | Keep an eye on potential incompatibility between antLR's compile-time java libraries 10 | and your run-time java libraries. (I didn't) 11 | 12 | Just get your Java RE and JDK in sync; it should be OK. 13 | 14 | -cemB 15 | 16 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test3.vox: -------------------------------------------------------------------------------- 1 | var a; 2 | var b = [[2,3,4],true]; //parse error, now the rest will be treated as stmts 3 | var c; // parse error again 4 | while(a == 3){ 5 | var b; //scopes to declare more variables 6 | var c; 7 | var b; 8 | print #b; 9 | print b; 10 | var x; //wont parse 11 | return c; //semantically incorrect but we don't check it for this assignment 12 | x = 3 or 5; //wont parse 13 | x = #y or #l and #x() or 3*-6+5-3----3+8*4/2+7 < 5*f(a(4+5,7,88,x),4); 14 | } 15 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/pftl.src.log: -------------------------------------------------------------------------------- 1 | file: pftl.src 2 | The grammar file compiled OK. 3 | Grammarians: 4 | Please do NOT use at 5 | the end of elements. It is used for model training. 6 | Use plain grammar entries instead. 7 | Modelers: 8 | Please DO NOT change that information manually. 9 | When you add new entries to an already-indexed grammar, 10 | put ALL OF THEM at the END of the grammar file. 11 | In model updates, make new entries WITHOUT extra information. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lab-material/mips-material/spim-procedure-calls-basic.md: -------------------------------------------------------------------------------- 1 | Here is a more basic link for explaining the preparations that need to be done 2 | at assembly level before, during, and after a procedure call, in SPIM. 3 | 4 | One example here (basics) is copied here because git does not support ftp links. sorry CS201. 5 | 6 | The example is a hand translation of a function call to SPIM, not to be confused with 7 | compiler generated code, which should give the same behavior but probably not the same code. 8 | 9 | 10 | -cem bozsahin 11 | 12 | 13 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test.src.log: -------------------------------------------------------------------------------- 1 | file: acid-test.src 2 | The grammar file compiled OK. 3 | Grammarians: 4 | Please do NOT use at 5 | the end of elements. It is used for model training. 6 | Use plain grammar entries instead. 7 | Modelers: 8 | Please DO NOT change that information manually. 9 | When you add new entries to an already-indexed grammar, 10 | put ALL OF THEM at the END of the grammar file. 11 | In model updates, make new entries WITHOUT extra information. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test2.src.log: -------------------------------------------------------------------------------- 1 | file: acid-test2.src 2 | The grammar file compiled OK. 3 | Grammarians: 4 | Please do NOT use at 5 | the end of elements. It is used for model training. 6 | Use plain grammar entries instead. 7 | Modelers: 8 | Please DO NOT change that information manually. 9 | When you add new entries to an already-indexed grammar, 10 | put ALL OF THEM at the END of the grammar file. 11 | In model updates, make new entries WITHOUT extra information. 12 | 13 | 14 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world.src.log: -------------------------------------------------------------------------------- 1 | file: hello-world.src 2 | The grammar file compiled OK. 3 | Grammarians: 4 | Please do NOT use at 5 | the end of elements. It is used for model training. 6 | Use plain grammar entries instead. 7 | Modelers: 8 | Please DO NOT change that information manually. 9 | When you add new entries to an already-indexed grammar, 10 | put ALL OF THEM at the END of the grammar file. 11 | In model updates, make new entries WITHOUT extra information. 12 | 13 | 14 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test3.vox.ast: -------------------------------------------------------------------------------- 1 | TOP_LVL VAR_DECLS: 2 | var a; 3 | TOP_LVL FUN_DECLS: 4 | 5 | TOP_LVL STMTS: 6 | ERROR_STMT; 7 | ERROR_STMT; 8 | while (Lc== a 3.0) { 9 | VAR_DECLS: 10 | var b; 11 | var c; 12 | var b; 13 | STMTS: 14 | print #b; 15 | print b; 16 | ERROR_STMT; 17 | return c; 18 | ERROR_STMT; 19 | x = (Lor (Lor #y (Land #l #x())) (Lc< (A+ (A+ (A- (A- (A+ (A* 3.0 Au-6.0) 5.0) 3.0) Au-Au-Au-3.0) (A/ (A* 8.0 4.0) 2.0)) 7.0) (A* 5.0 f(a((A+ 4.0 5.0), 7.0, 88.0, x), 4.0)))); 20 | } -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target2.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | t632: .float 0.0 4 | F: .float 0.0 5 | t633: .float 0.0 6 | B: .float 0.0 7 | zzeerroo: .float 0.0 8 | 9 | .text 10 | 11 | main: 12 | l.s $f2,F 13 | #loading dummy zero float to $f0 14 | l.s $f0,zzeerroo 15 | sub.s $f0,$f0,$f2 16 | s.s $f0,t632 17 | l.s $f0,t632 18 | #converting to float 19 | li $t0,5 20 | mtc1 $t0,$f6 21 | cvt.s.w $f2,$f6 22 | #conversion done 23 | div.s $f0,$f0,$f2 24 | s.s $f0,t633 25 | l.s $f0,t633 26 | s.s $f0,B 27 | #MIPs termination protocol: 28 | li $v0,10 29 | syscall 30 | .end main 31 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source2.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | t381: .float 0.0 6 | F: .float 0.0 7 | t382: .float 0.0 8 | B: .float 0.0 9 | zzeerroo: .float 0.0 10 | 11 | .text 12 | 13 | main: 14 | l.s $f2,F 15 | #loading dummy zero float to $f0 16 | l.s $f0,zzeerroo 17 | sub.s $f0,$f0,$f2 18 | s.s $f0,t381 19 | l.s $f0,t381 20 | #converting to float 21 | li $t0,5 22 | mtc1 $t0,$f6 23 | cvt.s.w $f2,$f6 24 | #conversion done 25 | div.s $f0,$f0,$f2 26 | s.s $f0,t382 27 | l.s $f0,t382 28 | s.s $f0,B 29 | #MIPs termination protocol: 30 | li $v0,10 31 | syscall 32 | .end main -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex3/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # adapted from tokens script, for supervision files 3 | # -Cem Bozsahin 2017, Ankara 4 | sed -e 's/\%.*$//g' -e 's/:/ |:| /g' -e 's/=/ |=| /g' -e 's/\./ |\.| /g' -e ' s/\\/ |\\\\| /g' -e 's/\// |\/| /g' -e 's/\;/ |;| /g' -e 's/\,/ |\,| /g' -e 's/-->/ |-->| /g' -e 's/(/ |(| /g' -e 's/)/ |)| /g' -e 's/\^/ |\^| /g' -e 's/\*/ |*| /g' -e 's/\+/ |+| /g' -e 's/\[/ |\[| /g' -e 's/\]/ |\]| /g' -e 's/\&i/ (LAM x x) /g' $1|sed -e 's/ |:|[ ]*|=| / |:=| /g'|sed -e 's/"\(.*\) |\([,\.]\)| \(.*\)"/"\1\2\3"/g' -e 's/"\(.*\) |\([,\.]\)| \(.*\)"/"\1\2\3"/g'|sed -e '1,1s/^/(/' -e '$s/$/)/' > $2 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex2/lexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # leave tokenization to Lisp reader but take care of special symbols 3 | # -cem bozsahin 4 | sed -e 's/\%.*$//g' -e 's/:/ |:| /g' -e 's/=/ |=| /g' -e 's/\./ |\.| /g' -e ' s/\\/ |\\\\| /g' -e 's/\// |\/| /g' -e 's/\;/ |;| /g' -e 's/\,/ |\,| /g' -e 's/-->/ |-->| /g' -e 's/(/ |(| /g' -e 's/)/ |)| /g' -e 's/\^/ |\^| /g' -e 's/\*/ |*| /g' -e 's/\+/ |+| /g' -e 's/\[/ |\[| /g' -e 's/\]/ |\]| /g' -e 's/\&i/ (LAM x x) /g' $1|sed -e 's/ |:|[ ]*|=| / |:=| /g'|sed -e 's/"\(.*\) |\([,\.]\)| \(.*\)"/"\1\2\3"/g' -e 's/"\(.*\) |\([,\.]\)| \(.*\)"/"\1\2\3"/g'|sed -e '1,1s/^/(/' -e '$s/$/)/' > $2 5 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source2n.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | F: .float 0.0 6 | t383: .float 0.0 7 | t384: .float 0.0 8 | B: .float 0.0 9 | zzeerroo: .float 0.0 10 | 11 | .text 12 | 13 | main: 14 | li.s $f0,12.0 15 | s.s $f0,F 16 | l.s $f2,F 17 | #loading dummy zero float to $f0 18 | l.s $f0,zzeerroo 19 | sub.s $f0,$f0,$f2 20 | s.s $f0,t383 21 | l.s $f0,t383 22 | #converting to float 23 | li $t0,5 24 | mtc1 $t0,$f6 25 | cvt.s.w $f2,$f6 26 | #conversion done 27 | div.s $f0,$f0,$f2 28 | s.s $f0,t384 29 | l.s $f0,t384 30 | s.s $f0,B 31 | #MIPs termination protocol: 32 | li $v0,10 33 | syscall 34 | .end main -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test4.txt.toks: -------------------------------------------------------------------------------- 1 | Tokens: 2 | Token(type='ID', value='test', lineno=1, index=0, end=4) 3 | Token(type='ERROR', value='.', lineno=1, index=4, end=5) 4 | Token(type='ID', value='nofieldsinvox', lineno=1, index=5, end=18) 5 | Token(type='WHILE', value='while', lineno=2, index=52, end=57) 6 | Token(type='FUN', value='fun', lineno=2, index=58, end=61) 7 | Token(type='NUMBER', value=1231.312312, lineno=4, index=94, end=105) 8 | Token(type='ERROR', value='.', lineno=4, index=106, end=107) 9 | Token(type='NUMBER', value=12313.0, lineno=4, index=107, end=112) 10 | Token(type='ERROR', value='.', lineno=4, index=112, end=113) -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test4.vox.ast: -------------------------------------------------------------------------------- 1 | TOP_LVL VAR_DECLS: 2 | var a; 3 | var b = [3.0, 5.0]; 4 | var c = [True, False, b]; 5 | TOP_LVL FUN_DECLS: 6 | fun a(){ 7 | VAR_DECLS: 8 | 9 | STMTS: 10 | 11 | } 12 | fun b(a, b){ 13 | VAR_DECLS: 14 | var c = a(#a); 15 | STMTS: 16 | while #a[(A+ b 3.0)] { 17 | VAR_DECLS: 18 | 19 | STMTS: 20 | 21 | } 22 | if True if True if True { 23 | VAR_DECLS: 24 | var c; 25 | STMTS: 26 | a = 3.0; 27 | b = 5.0; 28 | } else a = 5.0; endif else a = 6.0; endif endif 29 | return b; 30 | } 31 | TOP_LVL STMTS: 32 | a = "hello"; 33 | a = (A+ a[a[a[(A+ a 2.0)]]] 3.0); -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/target3.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | B: .word 0 4 | C: .word 0 5 | t370: .word 0 6 | t371: .word 0 7 | t372: .word 0 8 | E: .word 0 9 | F: .word 0 10 | t373: .word 0 11 | t374: .word 0 12 | t375: .word 0 13 | A: .word 0 14 | 15 | .text 16 | 17 | main: 18 | lw $t0,C 19 | li $t1,78.45 20 | mul $t0,$t0,$t1 21 | sw $t0,t370 22 | lw $t0,B 23 | lw $t1,t370 24 | add $t0,$t0,$t1 25 | sw $t0,t371 26 | lw $t1,E 27 | sub $t0,$zero,$t1 28 | sw $t0,t372 29 | lw $t0,t372 30 | lw $t1,F 31 | add $t0,$t0,$t1 32 | sw $t0,t373 33 | lw $t0,t373 34 | li $t1,12.5 35 | div $t0,$t0,$t1 36 | sw $t0,t374 37 | lw $t0,t371 38 | lw $t1,t374 39 | sub $t0,$t0,$t1 40 | sw $t0,t375 41 | lw $t0,t375 42 | sw $t0,A 43 | -------------------------------------------------------------------------------- /lab-material/mips-material/README.md: -------------------------------------------------------------------------------- 1 | Here I will put spim-related material I found freely available and useful, mostly for implementing procedure calls but also 2 | some nice spim examples and the manual. 3 | 4 | SPIM is a MIPS architecture simulator which runs on all platforms (starting with QtSpim) 5 | 6 | Here is the website for SPIM as of 2017 : 7 | QtSpim 8 | 9 | This is a good tutorial for understanding MIPS program structure 10 | 11 | And this is a comprehensive manual for MIPS using Qtspim. 12 | 13 | -cem bozsahin 14 | 15 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/target1.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | B: .word 0 4 | C: .word 0 5 | D: .word 0 6 | t362: .word 0 7 | t363: .word 0 8 | t364: .word 0 9 | E: .word 0 10 | F: .word 0 11 | t365: .word 0 12 | t366: .word 0 13 | t367: .word 0 14 | A: .word 0 15 | 16 | .text 17 | 18 | main: 19 | lw $t0,C 20 | lw $t1,D 21 | mul $t0,$t0,$t1 22 | sw $t0,t362 23 | lw $t0,B 24 | lw $t1,t362 25 | add $t0,$t0,$t1 26 | sw $t0,t363 27 | lw $t1,E 28 | sub $t0,$zero,$t1 29 | sw $t0,t364 30 | lw $t0,t364 31 | lw $t1,F 32 | add $t0,$t0,$t1 33 | sw $t0,t365 34 | lw $t0,t365 35 | li $t1,5 36 | div $t0,$t0,$t1 37 | sw $t0,t366 38 | lw $t0,t363 39 | lw $t1,t366 40 | sub $t0,$t0,$t1 41 | sw $t0,t367 42 | lw $t0,t367 43 | sw $t0,A 44 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bp.g4: -------------------------------------------------------------------------------- 1 | // A mini test grammar for balanced parentheses 2 | // -cem bozsahin 3 | 4 | grammar bp; 5 | 6 | prog: start+; // slightly cheating: a sequence of bps by iteration 7 | // exercise: remove '+' and write recursively 8 | 9 | start: '(' start ')' 10 | | data 11 | | NEWLINE 12 | ; 13 | 14 | data : NUM 15 | | OP 16 | | KEYWD 17 | | ID 18 | ; 19 | 20 | WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines 21 | OP : [+-/*] ; 22 | NUM: [0-9]+ ; 23 | ID : [A-Za-z]([A-Za-z]|NUM)* ; 24 | KEYWD: '_'ID ; // use of pattern within pattern 25 | NEWLINE:'\r'? '\n' ; // returns newline to parser 26 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test2.vox.ast: -------------------------------------------------------------------------------- 1 | TOP_LVL VAR_DECLS: 2 | var a; 3 | var b; 4 | var z = 100.0; 5 | TOP_LVL FUN_DECLS: 6 | fun f(f, f, f){ 7 | VAR_DECLS: 8 | var f; 9 | var x = 0.0; 10 | var z = 0.0; 11 | STMTS: 12 | ERROR_STMT; 13 | for (x = 0.0;(Lc< x 10.0);x = (A+ x 1.0)) { 14 | VAR_DECLS: 15 | var z; 16 | STMTS: 17 | y = (A+ y 1.0); 18 | while (Lc> y 0.0) { 19 | VAR_DECLS: 20 | var q = [2.0, 4.0, 6.0, True, False, #f(), undeclared]; 21 | STMTS: 22 | y = (A- y 1.0); 23 | z = (A+ z x); 24 | ERROR_STMT; 25 | if True q = (A- y 1.0); endif 26 | } 27 | } 28 | } 29 | TOP_LVL STMTS: 30 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/l.g4: -------------------------------------------------------------------------------- 1 | // This example shows that it's a bad idea not to issue 2 | // a warning when the grammar is not LL. 3 | // (antlr3 used to give a warning.) 4 | // It produces a wrong tree for some examples, like data1 here, 5 | // but you can miss that because there is no warning it's not LL! 6 | // -cem bozsahin 7 | 8 | grammar l; 9 | 10 | start: s '$'; 11 | 12 | s : def s 13 | | f 14 | ; 15 | 16 | def : PL '=' f; 17 | 18 | f : t '=>' f 19 | | t 20 | ; 21 | 22 | t : PL 23 | | '(' f ')' 24 | | '~' f 25 | | '0' 26 | | '1' 27 | ; 28 | 29 | 30 | WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines 31 | NEWLINE:'\r'? '\n' ; // returns newline to parser 32 | PL : [A-Za-z] ; // proposition letters 33 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/indirect-addr-by-local-var.s: -------------------------------------------------------------------------------- 1 | # this code is meant for syntax checking only 2 | # no MIPS manual addresses the problem! 3 | # -cem bozsahin 4 | 5 | .data 6 | 7 | local: .word 4 # to check if spim allows x(y) kind of access 8 | t632: .float 0.0 9 | F: .float 0.0 10 | t633: .float 0.0 11 | B: .float 0.0 12 | zzeerroo: .float 0.0 13 | 14 | .text 15 | 16 | main: 17 | l.s $f2,local($sp) # intended use: access 4 bytes off the stack top 18 | l.s $f2,F 19 | #loading dummy zero float to $f0 20 | l.s $f0,zzeerroo 21 | sub.s $f0,$f0,$f2 22 | s.s $f0,t632 23 | l.s $f0,t632 24 | #converting to float 25 | li $t0,5 26 | mtc1 $t0,$f6 27 | cvt.s.w $f2,$f6 28 | #conversion done 29 | div.s $f0,$f0,$f2 30 | s.s $f0,t633 31 | l.s $f0,t633 32 | s.s $f0,B 33 | #MIPs termination protocol: 34 | li $v0,10 35 | syscall 36 | .end main 37 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/README.md: -------------------------------------------------------------------------------- 1 | YOU NEED: 2 | 3 | - python3.8 or above 4 | - pip3.8 or above 5 | - You need to pip-install sly.py first. 6 | 7 | To use this code, do (rlwrap) python main.py 8 | 9 | And follow the instructions there. 10 | 11 | In the folder there are source files for a natural language grammar. 12 | 13 | This grammar is parsed into IC code in the form of a python dict for source's AST. 14 | 15 | Once parsed, the current IC code can generate target code in the form of Common Lisp expressions. 16 | 17 | In main.py code you can see a fairly involved sly lexer and parser. 18 | 19 | Sly is here: sly repo. 20 | 21 | The .tc files are processable by CCGlab. 22 | 23 | So, the TC is interpreted by Lisp. 24 | 25 | enjoy. 26 | -cemB 27 | 28 | -------------------------------------------------------------------------------- /project-material/old_projects/project2/README.md: -------------------------------------------------------------------------------- 1 | # Due : December 30, 2019, midnight 2 | 3 | Project 2: Write an LALR-based code generator for V, and execute your sample code. 4 | 5 |

You can generate MIPS, RISC-V or LLVM code. I cover MIPS in class because it is the tried and true one. 6 | 7 |

Test your sample V code with a native machine if you have one, or use on of the great simulators such 8 | as QtSpim for MIPS or Spike for RISC-V. 9 | 10 |

These emulators are in fact better, because they allow you to debug your code generator by showing 11 | the ``machine state'' all the time, and during register updates. 12 | 13 |

For this phase, you may assume that all input is well-formed syntactically and semantically, that is, it is executable 14 | with a meaningful response. 15 | 16 |

Zip your source, inputs and demo of output to send to me in one file. 17 | -------------------------------------------------------------------------------- /project-material/project_1_for_students/parser_tests/test1.vox.ast: -------------------------------------------------------------------------------- 1 | TOP_LVL VAR_DECLS: 2 | var a; 3 | var b; 4 | var y; 5 | var b; 6 | TOP_LVL FUN_DECLS: 7 | fun f(a, b, d){ 8 | VAR_DECLS: 9 | var c; 10 | var d; 11 | STMTS: 12 | e = #d; 13 | if (Lc== x 3.0) { 14 | VAR_DECLS: 15 | var d; 16 | var e = f(); 17 | var f = d; 18 | var c; 19 | STMTS: 20 | ERROR_STMT; 21 | ERROR_STMT; 22 | ERROR_STMT; 23 | e = (A+ y 3.0); 24 | } endif 25 | } 26 | TOP_LVL STMTS: 27 | a = (A+ (A- (A+ Au-Au-a (A* 3.0 5.0)) 4.0) f); 28 | e = 345.0; 29 | while (Lc== a 3.0) { 30 | VAR_DECLS: 31 | 32 | STMTS: 33 | x = 5.0; 34 | if True { 35 | VAR_DECLS: 36 | var x; 37 | var z; 38 | var x; 39 | STMTS: 40 | for (;(Lc== a 3.0);y = (A+ x 1.0)) ERROR_STMT; 41 | } endif 42 | } -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer.py: -------------------------------------------------------------------------------- 1 | import sly 2 | 3 | class Lexer(sly.Lexer): 4 | tokens = { NUMBER, ID, WHILE, IF, ELSE, PRINT, 5 | PLUS, MINUS, TIMES, DIVIDE, ASSIGN, 6 | EQ, LT, LE, GT, GE, NE, AND, 7 | FALSE, TRUE, FUN, FOR, OR, 8 | RETURN, VAR, STRING, NOT} 9 | 10 | #LE := <= 11 | #EQ := == 12 | #LT := < 13 | #GT := > 14 | #GE := >= 15 | #NE := != 16 | 17 | #Sanitize your tokens for the literals in the language (not token literals)! 18 | #each token t for NUMBER should have type(t.value) == float 19 | #each token t for STRING should have type(t.value) == str (remove the quotes!) 20 | #each token t for TRUE/FALSE should have type(t.value) == bool 21 | 22 | literals = { '(', ')', '{', '}', '[', ']', ';' , ',', '#'} 23 | 24 | #Do not modify the sets Lexer.literals and Lexer.tokens! -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target3.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | B: .float 0.0 4 | C: .float 0.0 5 | t634: .float 0.0 6 | t635: .float 0.0 7 | t636: .float 0.0 8 | E: .float 0.0 9 | F: .float 0.0 10 | t637: .float 0.0 11 | t638: .float 0.0 12 | t639: .float 0.0 13 | A: .float 0.0 14 | zzeerroo: .float 0.0 15 | 16 | .text 17 | 18 | main: 19 | l.s $f0,C 20 | li.s $f2,78.45 21 | mul.s $f0,$f0,$f2 22 | s.s $f0,t634 23 | l.s $f0,B 24 | l.s $f2,t634 25 | add.s $f0,$f0,$f2 26 | s.s $f0,t635 27 | l.s $f2,E 28 | #loading dummy zero float to $f0 29 | l.s $f0,zzeerroo 30 | sub.s $f0,$f0,$f2 31 | s.s $f0,t636 32 | l.s $f0,t636 33 | l.s $f2,F 34 | add.s $f0,$f0,$f2 35 | s.s $f0,t637 36 | l.s $f0,t637 37 | li.s $f2,12.5 38 | div.s $f0,$f0,$f2 39 | s.s $f0,t638 40 | l.s $f0,t635 41 | l.s $f2,t638 42 | sub.s $f0,$f0,$f2 43 | s.s $f0,t639 44 | l.s $f0,t639 45 | s.s $f0,A 46 | #MIPs termination protocol: 47 | li $v0,10 48 | syscall 49 | .end main 50 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/l.g4: -------------------------------------------------------------------------------- 1 | // A simple LL(2) language 2 | // antlr4 wont complain or warn you about k=2. 3 | // antlr3 would complain about this grammar, because it is not LL(1). 4 | // And, that is the right thing to do. 5 | // antlr4 gave up on table-driven LL, whether language is LL or not. 6 | // Think of it this way: If you intended your grammar to be LL, and made 7 | // a mistake, how can you find out unless you spot a wrong parse tree? 8 | // -cem bozsahin 9 | 10 | grammar l; 11 | 12 | start: s '$'; 13 | 14 | s : def s 15 | | e 16 | ; 17 | 18 | def : PL '=' e; 19 | 20 | e : f '=>' e 21 | | t 22 | ; 23 | 24 | t : f 25 | ; 26 | 27 | f : PL 28 | | '(' e ')' 29 | | '~' f 30 | | '0' 31 | | '1' 32 | ; 33 | 34 | 35 | WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines 36 | NEWLINE:'\r'? '\n' ; // returns newline to parser 37 | PL : [A-Za-z] ; // proposition letters 38 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source3.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | B: .float 0.0 6 | C: .float 0.0 7 | t385: .float 0.0 8 | t386: .float 0.0 9 | t387: .float 0.0 10 | E: .float 0.0 11 | F: .float 0.0 12 | t388: .float 0.0 13 | t389: .float 0.0 14 | t390: .float 0.0 15 | A: .float 0.0 16 | zzeerroo: .float 0.0 17 | 18 | .text 19 | 20 | main: 21 | l.s $f0,C 22 | li.s $f2,78.45 23 | mul.s $f0,$f0,$f2 24 | s.s $f0,t385 25 | l.s $f0,B 26 | l.s $f2,t385 27 | add.s $f0,$f0,$f2 28 | s.s $f0,t386 29 | l.s $f2,E 30 | #loading dummy zero float to $f0 31 | l.s $f0,zzeerroo 32 | sub.s $f0,$f0,$f2 33 | s.s $f0,t387 34 | l.s $f0,t387 35 | l.s $f2,F 36 | add.s $f0,$f0,$f2 37 | s.s $f0,t388 38 | l.s $f0,t388 39 | li.s $f2,12.5 40 | div.s $f0,$f0,$f2 41 | s.s $f0,t389 42 | l.s $f0,t386 43 | l.s $f2,t389 44 | sub.s $f0,$f0,$f2 45 | s.s $f0,t390 46 | l.s $f0,t390 47 | s.s $f0,A 48 | #MIPs termination protocol: 49 | li $v0,10 50 | syscall 51 | .end main -------------------------------------------------------------------------------- /project-material/project_1_for_students/misc.py: -------------------------------------------------------------------------------- 1 | from ast_tools import * 2 | from typing import List 3 | from parser import Parser 4 | from lexer import Lexer 5 | 6 | def process(source): 7 | '''parse the source text here. you may return the AST specified in ast_tools.py or something else.''' 8 | pass 9 | 10 | def generate_ast(intermediate) -> Program: 11 | '''return the AST using the output of process() here.''' 12 | pass 13 | 14 | def undeclared_vars(intermediate) -> List[Identifier]: 15 | '''return all of the undeclared uses of the variables in the order they appear in the source code here, using the return value of process()''' 16 | pass 17 | 18 | def multiple_var_declarations(intermediate) -> List[Identifier]: 19 | '''return all of the subsequent declarations of a previously declared variable if the re-declaration cannot be explained by shadowing, 20 | in the order they appear in the source code, using the return value of process()''' 21 | pass 22 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bp.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '(' 4 | ')' 5 | null 6 | null 7 | null 8 | null 9 | null 10 | null 11 | 12 | token symbolic names: 13 | null 14 | null 15 | null 16 | WS 17 | OP 18 | NUM 19 | ID 20 | KEYWD 21 | NEWLINE 22 | 23 | rule names: 24 | prog 25 | start 26 | data 27 | 28 | 29 | atn: 30 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 10, 24, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 3, 2, 6, 2, 10, 10, 2, 13, 2, 14, 2, 11, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 20, 10, 3, 3, 4, 3, 4, 3, 4, 2, 2, 5, 2, 4, 6, 2, 3, 3, 2, 6, 9, 2, 23, 2, 9, 3, 2, 2, 2, 4, 19, 3, 2, 2, 2, 6, 21, 3, 2, 2, 2, 8, 10, 5, 4, 3, 2, 9, 8, 3, 2, 2, 2, 10, 11, 3, 2, 2, 2, 11, 9, 3, 2, 2, 2, 11, 12, 3, 2, 2, 2, 12, 3, 3, 2, 2, 2, 13, 14, 7, 3, 2, 2, 14, 15, 5, 4, 3, 2, 15, 16, 7, 4, 2, 2, 16, 20, 3, 2, 2, 2, 17, 20, 5, 6, 4, 2, 18, 20, 7, 10, 2, 2, 19, 13, 3, 2, 2, 2, 19, 17, 3, 2, 2, 2, 19, 18, 3, 2, 2, 2, 20, 5, 3, 2, 2, 2, 21, 22, 9, 2, 2, 2, 22, 7, 3, 2, 2, 2, 4, 11, 19] -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target1.s: -------------------------------------------------------------------------------- 1 | .data 2 | 3 | B: .float 0.0 4 | C: .float 0.0 5 | D: .float 0.0 6 | t626: .float 0.0 7 | t627: .float 0.0 8 | t628: .float 0.0 9 | E: .float 0.0 10 | F: .float 0.0 11 | t629: .float 0.0 12 | t630: .float 0.0 13 | t631: .float 0.0 14 | A: .float 0.0 15 | zzeerroo: .float 0.0 16 | 17 | .text 18 | 19 | main: 20 | l.s $f0,C 21 | l.s $f2,D 22 | mul.s $f0,$f0,$f2 23 | s.s $f0,t626 24 | l.s $f0,B 25 | l.s $f2,t626 26 | add.s $f0,$f0,$f2 27 | s.s $f0,t627 28 | l.s $f2,E 29 | #loading dummy zero float to $f0 30 | l.s $f0,zzeerroo 31 | sub.s $f0,$f0,$f2 32 | s.s $f0,t628 33 | l.s $f0,t628 34 | l.s $f2,F 35 | add.s $f0,$f0,$f2 36 | s.s $f0,t629 37 | l.s $f0,t629 38 | #converting to float 39 | li $t0,5 40 | mtc1 $t0,$f6 41 | cvt.s.w $f2,$f6 42 | #conversion done 43 | div.s $f0,$f0,$f2 44 | s.s $f0,t630 45 | l.s $f0,t627 46 | l.s $f2,t630 47 | sub.s $f0,$f0,$f2 48 | s.s $f0,t631 49 | l.s $f0,t631 50 | s.s $f0,A 51 | #MIPs termination protocol: 52 | li $v0,10 53 | syscall 54 | .end main 55 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source3n.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | B: .float 0.0 6 | C: .float 0.0 7 | E: .float 0.0 8 | F: .float 0.0 9 | t391: .float 0.0 10 | t392: .float 0.0 11 | t393: .float 0.0 12 | t394: .float 0.0 13 | t395: .float 0.0 14 | t396: .float 0.0 15 | A: .float 0.0 16 | zzeerroo: .float 0.0 17 | 18 | .text 19 | 20 | main: 21 | li.s $f0,10.0 22 | s.s $f0,B 23 | li.s $f0,12.0 24 | s.s $f0,C 25 | li.s $f0,14.0 26 | s.s $f0,E 27 | li.s $f0,16.2 28 | s.s $f0,F 29 | l.s $f0,C 30 | li.s $f2,78.45 31 | mul.s $f0,$f0,$f2 32 | s.s $f0,t391 33 | l.s $f0,B 34 | l.s $f2,t391 35 | add.s $f0,$f0,$f2 36 | s.s $f0,t392 37 | l.s $f2,E 38 | #loading dummy zero float to $f0 39 | l.s $f0,zzeerroo 40 | sub.s $f0,$f0,$f2 41 | s.s $f0,t393 42 | l.s $f0,t393 43 | l.s $f2,F 44 | add.s $f0,$f0,$f2 45 | s.s $f0,t394 46 | l.s $f0,t394 47 | li.s $f2,12.5 48 | div.s $f0,$f0,$f2 49 | s.s $f0,t395 50 | l.s $f0,t392 51 | l.s $f2,t395 52 | sub.s $f0,$f0,$f2 53 | s.s $f0,t396 54 | l.s $f0,t396 55 | s.s $f0,A 56 | #MIPs termination protocol: 57 | li $v0,10 58 | syscall 59 | .end main -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source1n.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | B: .float 0.0 6 | C: .float 0.0 7 | D: .float 0.0 8 | E: .float 0.0 9 | F: .float 0.0 10 | t375: .float 0.0 11 | t376: .float 0.0 12 | t377: .float 0.0 13 | t378: .float 0.0 14 | t379: .float 0.0 15 | t380: .float 0.0 16 | A: .float 0.0 17 | zzeerroo: .float 0.0 18 | 19 | .text 20 | 21 | main: 22 | li.s $f0,5.0 23 | s.s $f0,B 24 | li.s $f0,2.0 25 | s.s $f0,C 26 | li.s $f0,10.0 27 | s.s $f0,D 28 | li.s $f0,10.0 29 | s.s $f0,E 30 | li.s $f0,20.0 31 | s.s $f0,F 32 | l.s $f0,C 33 | l.s $f2,D 34 | mul.s $f0,$f0,$f2 35 | s.s $f0,t375 36 | l.s $f0,B 37 | l.s $f2,t375 38 | add.s $f0,$f0,$f2 39 | s.s $f0,t376 40 | l.s $f2,E 41 | #loading dummy zero float to $f0 42 | l.s $f0,zzeerroo 43 | sub.s $f0,$f0,$f2 44 | s.s $f0,t377 45 | l.s $f0,t377 46 | l.s $f2,F 47 | add.s $f0,$f0,$f2 48 | s.s $f0,t378 49 | l.s $f0,t378 50 | #converting to float 51 | li $t0,5 52 | mtc1 $t0,$f6 53 | cvt.s.w $f2,$f6 54 | #conversion done 55 | div.s $f0,$f0,$f2 56 | s.s $f0,t379 57 | l.s $f0,t376 58 | l.s $f2,t379 59 | sub.s $f0,$f0,$f2 60 | s.s $f0,t380 61 | l.s $f0,t380 62 | s.s $f0,A 63 | #MIPs termination protocol: 64 | li $v0,10 65 | syscall 66 | .end main -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpListener.java: -------------------------------------------------------------------------------- 1 | // Generated from bp.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.tree.ParseTreeListener; 3 | 4 | /** 5 | * This interface defines a complete listener for a parse tree produced by 6 | * {@link bpParser}. 7 | */ 8 | public interface bpListener extends ParseTreeListener { 9 | /** 10 | * Enter a parse tree produced by {@link bpParser#prog}. 11 | * @param ctx the parse tree 12 | */ 13 | void enterProg(bpParser.ProgContext ctx); 14 | /** 15 | * Exit a parse tree produced by {@link bpParser#prog}. 16 | * @param ctx the parse tree 17 | */ 18 | void exitProg(bpParser.ProgContext ctx); 19 | /** 20 | * Enter a parse tree produced by {@link bpParser#start}. 21 | * @param ctx the parse tree 22 | */ 23 | void enterStart(bpParser.StartContext ctx); 24 | /** 25 | * Exit a parse tree produced by {@link bpParser#start}. 26 | * @param ctx the parse tree 27 | */ 28 | void exitStart(bpParser.StartContext ctx); 29 | /** 30 | * Enter a parse tree produced by {@link bpParser#data}. 31 | * @param ctx the parse tree 32 | */ 33 | void enterData(bpParser.DataContext ctx); 34 | /** 35 | * Exit a parse tree produced by {@link bpParser#data}. 36 | * @param ctx the parse tree 37 | */ 38 | void exitData(bpParser.DataContext ctx); 39 | } -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test2.txt.toks: -------------------------------------------------------------------------------- 1 | Tokens: 2 | Token(type='ERROR', value='.', lineno=1, index=0, end=1) 3 | Token(type='NUMBER', value=435435.0, lineno=1, index=1, end=7) 4 | Token(type='ASSIGN', value='=', lineno=1, index=8, end=9) 5 | Token(type='EQ', value='==', lineno=1, index=10, end=12) 6 | Token(type='ID', value='funwhile', lineno=1, index=13, end=21) 7 | Token(type='ID', value='whileee', lineno=1, index=22, end=29) 8 | Token(type='FUN', value='fun', lineno=1, index=30, end=33) 9 | Token(type='(', value='(', lineno=1, index=33, end=34) 10 | Token(type=')', value=')', lineno=1, index=34, end=35) 11 | Token(type='{', value='{', lineno=1, index=35, end=36) 12 | Token(type='}', value='}', lineno=1, index=36, end=37) 13 | Token(type='ID', value='n', lineno=1, index=37, end=38) 14 | Token(type='STRING', value='fun', lineno=1, index=38, end=43) 15 | Token(type='STRING', value='[', lineno=1, index=44, end=47) 16 | Token(type='[', value='[', lineno=1, index=48, end=49) 17 | Token(type=']', value=']', lineno=1, index=49, end=50) 18 | Token(type=']', value=']', lineno=1, index=50, end=51) 19 | Token(type=';', value=';', lineno=1, index=51, end=52) 20 | Token(type=';', value=';', lineno=1, index=52, end=53) 21 | Token(type=';', value=';', lineno=1, index=53, end=54) 22 | Token(type='STRING', value='var else', lineno=1, index=55, end=65) 23 | Token(type='IF', value='if', lineno=1, index=66, end=68) 24 | Token(type='ID', value='nil', lineno=1, index=69, end=72) -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/workflow.log: -------------------------------------------------------------------------------- 1 | Script started on Fri Dec 13 21:56:43 2019 2 | 3 | The default interactive shell is now zsh. 4 | To update your account to use zsh, please run `chsh -s /bin/zsh`. 5 | For more details, please visit https://support.apple.com/kb/HT208050. 6 | [?1034hexpr-zac> yalalr 7 | This is SBCL 1.5.1, an implementation of ANSI Common Lisp. 8 | More information about SBCL is available at . 9 | 10 | SBCL is free software, provided as is, with absolutely no warranty. 11 | It is mostly in the public domain; some portions are provided under 12 | BSD-style licenses. See the CREDITS and COPYING files in the 13 | distribution for more information. 14 | STYLE-WARNING: Defining (*TOPCAT*) as a constant, even though the name follows 15 | the usual naming convention (names like *FOO*) for special variables 16 |  WARNING: redefining COMMON-LISP-USER::PARSE in DEFUN 17 | 18 | =================================================== 19 | Welcome to yalalr, version 2.0 20 | an interface to LALR parser of Mark Johnson 21 | --------------------------------------------------- 22 | Ready. 23 | =================================================== 24 | lexer ok 25 | SDD ok 26 | Grammar loaded. LALR tables set. 27 | > (ic-gen "code1") 28 | (LVAL A / RVAL B / RVAL C / RVAL D / MULT / ADD / RVAL E / NEG / RVAL F / ADD / 29 | RVAL 5 / DIV / SUB / MOVE) 30 | > (ic-gen "code2") 31 | (LVAL B / RVAL F / NEG / RVAL 5 / DIV / MOVE) 32 | expr-zac> exit 33 | 34 | Script done on Fri Dec 13 21:57:20 2019 35 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/l.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '$' 4 | '=' 5 | '=>' 6 | '(' 7 | ')' 8 | '~' 9 | '0' 10 | '1' 11 | null 12 | null 13 | null 14 | 15 | token symbolic names: 16 | null 17 | null 18 | null 19 | null 20 | null 21 | null 22 | null 23 | null 24 | null 25 | WS 26 | NEWLINE 27 | PL 28 | 29 | rule names: 30 | start 31 | s 32 | def 33 | f 34 | t 35 | 36 | 37 | atn: 38 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 13, 44, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 20, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 31, 10, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 42, 10, 6, 3, 6, 2, 2, 7, 2, 4, 6, 8, 10, 2, 2, 2, 44, 2, 12, 3, 2, 2, 2, 4, 19, 3, 2, 2, 2, 6, 21, 3, 2, 2, 2, 8, 30, 3, 2, 2, 2, 10, 41, 3, 2, 2, 2, 12, 13, 5, 4, 3, 2, 13, 14, 7, 3, 2, 2, 14, 3, 3, 2, 2, 2, 15, 16, 5, 6, 4, 2, 16, 17, 5, 4, 3, 2, 17, 20, 3, 2, 2, 2, 18, 20, 5, 8, 5, 2, 19, 15, 3, 2, 2, 2, 19, 18, 3, 2, 2, 2, 20, 5, 3, 2, 2, 2, 21, 22, 7, 13, 2, 2, 22, 23, 7, 4, 2, 2, 23, 24, 5, 8, 5, 2, 24, 7, 3, 2, 2, 2, 25, 26, 5, 10, 6, 2, 26, 27, 7, 5, 2, 2, 27, 28, 5, 8, 5, 2, 28, 31, 3, 2, 2, 2, 29, 31, 5, 10, 6, 2, 30, 25, 3, 2, 2, 2, 30, 29, 3, 2, 2, 2, 31, 9, 3, 2, 2, 2, 32, 42, 7, 13, 2, 2, 33, 34, 7, 6, 2, 2, 34, 35, 5, 8, 5, 2, 35, 36, 7, 7, 2, 2, 36, 42, 3, 2, 2, 2, 37, 38, 7, 8, 2, 2, 38, 42, 5, 8, 5, 2, 39, 42, 7, 9, 2, 2, 40, 42, 7, 10, 2, 2, 41, 32, 3, 2, 2, 2, 41, 33, 3, 2, 2, 2, 41, 37, 3, 2, 2, 2, 41, 39, 3, 2, 2, 2, 41, 40, 3, 2, 2, 2, 42, 11, 3, 2, 2, 2, 5, 19, 30, 41] -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test1.txt.toks: -------------------------------------------------------------------------------- 1 | Tokens: 2 | Token(type='ID', value='whileee', lineno=1, index=0, end=7) 3 | Token(type='WHILE', value='while', lineno=1, index=8, end=13) 4 | Token(type='ID', value='he', lineno=1, index=14, end=16) 5 | Token(type='NOT', value='!', lineno=1, index=16, end=17) 6 | Token(type='PLUS', value='+', lineno=1, index=17, end=18) 7 | Token(type='MINUS', value='-', lineno=1, index=18, end=19) 8 | Token(type='TIMES', value='*', lineno=1, index=19, end=20) 9 | Token(type='DIVIDE', value='/', lineno=1, index=20, end=21) 10 | Token(type='NUMBER', value=34234.234, lineno=1, index=21, end=30) 11 | Token(type='EQ', value='==', lineno=1, index=30, end=32) 12 | Token(type='STRING', value='fun', lineno=1, index=32, end=37) 13 | Token(type='FUN', value='fun', lineno=1, index=37, end=40) 14 | Token(type='ID', value='funnn', lineno=1, index=41, end=46) 15 | Token(type='ID', value='ifelse', lineno=1, index=47, end=53) 16 | Token(type='IF', value='if', lineno=1, index=54, end=56) 17 | Token(type='ELSE', value='else', lineno=1, index=57, end=61) 18 | Token(type='EQ', value='==', lineno=1, index=62, end=64) 19 | Token(type='ASSIGN', value='=', lineno=1, index=64, end=65) 20 | Token(type='GE', value='>=', lineno=1, index=65, end=67) 21 | Token(type='GT', value='>', lineno=1, index=67, end=68) 22 | Token(type='GE', value='>=', lineno=1, index=68, end=70) 23 | Token(type='LE', value='<=', lineno=1, index=70, end=72) 24 | Token(type='LE', value='<=', lineno=1, index=72, end=74) 25 | Token(type='ASSIGN', value='=', lineno=1, index=74, end=75) 26 | Token(type='ERROR', value='"', lineno=1, index=76, end=77) 27 | Token(type='ID', value='test', lineno=1, index=77, end=81) -------------------------------------------------------------------------------- /project-material/vox_grammar.txt: -------------------------------------------------------------------------------- 1 | program -> varDecl* funDecl* free-statement* EOF 2 | 3 | varDecl -> "var" ID ( "=" init )? ";" 4 | funDecl -> "fun" function 5 | 6 | free-statement 7 | -> simpleStmt ";" 8 | | compoundStmt 9 | 10 | init -> expr 11 | | "[" expr ("," expr)* "]" 12 | 13 | simpleStmt -> asgnStmt 14 | | printStmnt 15 | | returnStmt 16 | 17 | compoundStmt-> ifStmt | whileStmt | forStmt 18 | 19 | statement -> free-statement 20 | | block 21 | 22 | asgnStmt -> ID ( "[" aexpr "]" )? "=" expr 23 | printStmt -> "print" expr 24 | returnStmt -> "return" expr 25 | 26 | ifStmt -> "if" lexpr statement ("else" statement )? 27 | whileStmt -> "while" lexpr statement 28 | forStmt -> "for" "(" asgnStmt? ";" lexpr? ";" asgnStmt? ")" statement 29 | 30 | block -> "{" varDecl* statement* "}" 31 | 32 | expr -> lexpr 33 | | aexpr 34 | | sexpr 35 | 36 | lexpr -> lexpr "or" lterm | lterm 37 | lterm -> lterm "and" lfact | lfact 38 | lfact -> cexpr | "#" call | "(" lexpr ")" | "#" ID ( "[" aexpr "]" )? 39 | | "!" lfact 40 | | "true" 41 | | "false" 42 | 43 | aexpr -> aexpr ("-"|"+") term | term 44 | term -> term ("/"|"*") fact | fact 45 | fact -> "-" fact | call | NUMBER | "(" aexpr ")" | ID ( "[" aexpr "]" )? 46 | 47 | cexpr -> aexpr ("!=" | "==" | ">" | ">=" | "<" | "<=") aexpr 48 | 49 | sexpr -> STRING 50 | 51 | arguments -> expr ( "," expr )* 52 | function -> ID "(" parameters? ")" block 53 | parameters -> ID ( "," ID )* 54 | call -> ID "(" arguments? ")" 55 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/l.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '$' 4 | '=' 5 | '=>' 6 | '(' 7 | ')' 8 | '~' 9 | '0' 10 | '1' 11 | null 12 | null 13 | null 14 | 15 | token symbolic names: 16 | null 17 | null 18 | null 19 | null 20 | null 21 | null 22 | null 23 | null 24 | null 25 | WS 26 | NEWLINE 27 | PL 28 | 29 | rule names: 30 | start 31 | s 32 | def 33 | e 34 | t 35 | f 36 | 37 | 38 | atn: 39 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 13, 48, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 22, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 33, 10, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 46, 10, 7, 3, 7, 2, 2, 8, 2, 4, 6, 8, 10, 12, 2, 2, 2, 47, 2, 14, 3, 2, 2, 2, 4, 21, 3, 2, 2, 2, 6, 23, 3, 2, 2, 2, 8, 32, 3, 2, 2, 2, 10, 34, 3, 2, 2, 2, 12, 45, 3, 2, 2, 2, 14, 15, 5, 4, 3, 2, 15, 16, 7, 3, 2, 2, 16, 3, 3, 2, 2, 2, 17, 18, 5, 6, 4, 2, 18, 19, 5, 4, 3, 2, 19, 22, 3, 2, 2, 2, 20, 22, 5, 8, 5, 2, 21, 17, 3, 2, 2, 2, 21, 20, 3, 2, 2, 2, 22, 5, 3, 2, 2, 2, 23, 24, 7, 13, 2, 2, 24, 25, 7, 4, 2, 2, 25, 26, 5, 8, 5, 2, 26, 7, 3, 2, 2, 2, 27, 28, 5, 12, 7, 2, 28, 29, 7, 5, 2, 2, 29, 30, 5, 8, 5, 2, 30, 33, 3, 2, 2, 2, 31, 33, 5, 10, 6, 2, 32, 27, 3, 2, 2, 2, 32, 31, 3, 2, 2, 2, 33, 9, 3, 2, 2, 2, 34, 35, 5, 12, 7, 2, 35, 11, 3, 2, 2, 2, 36, 46, 7, 13, 2, 2, 37, 38, 7, 6, 2, 2, 38, 39, 5, 8, 5, 2, 39, 40, 7, 7, 2, 2, 40, 46, 3, 2, 2, 2, 41, 42, 7, 8, 2, 2, 42, 46, 5, 12, 7, 2, 43, 46, 7, 9, 2, 2, 44, 46, 7, 10, 2, 2, 45, 36, 3, 2, 2, 2, 45, 37, 3, 2, 2, 2, 45, 41, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 45, 44, 3, 2, 2, 2, 46, 13, 3, 2, 2, 2, 5, 21, 32, 45] -------------------------------------------------------------------------------- /project-material/project_1_for_students/lexer_tests/test5.txt.toks: -------------------------------------------------------------------------------- 1 | Tokens: 2 | Token(type='ID', value='eand', lineno=1, index=0, end=4) 3 | Token(type='OR', value='or', lineno=1, index=5, end=7) 4 | Token(type='ID', value='orand', lineno=1, index=8, end=13) 5 | Token(type='ID', value='andor', lineno=1, index=14, end=19) 6 | Token(type='EQ', value='==', lineno=1, index=20, end=22) 7 | Token(type='OR', value='or', lineno=1, index=22, end=24) 8 | Token(type='ELSE', value='else', lineno=1, index=25, end=29) 9 | Token(type='ID', value='iffun', lineno=1, index=30, end=35) 10 | Token(type='FUN', value='fun', lineno=1, index=36, end=39) 11 | Token(type='STRING', value='', lineno=1, index=40, end=42) 12 | Token(type='ELSE', value='else', lineno=1, index=42, end=46) 13 | Token(type='STRING', value='', lineno=1, index=46, end=48) 14 | Token(type='ID', value='test', lineno=1, index=49, end=53) 15 | Token(type='ERROR', value='.', lineno=1, index=53, end=54) 16 | Token(type='NUMBER', value=123.21332, lineno=1, index=54, end=63) 17 | Token(type='ID', value='test', lineno=1, index=64, end=68) 18 | Token(type='NUMBER', value=123.0, lineno=1, index=69, end=72) 19 | Token(type='ID', value='notvarname', lineno=1, index=72, end=82) 20 | Token(type='ID', value='truefalse', lineno=1, index=83, end=92) 21 | Token(type='TRUE', value=True, lineno=1, index=93, end=97) 22 | Token(type='FALSE', value=False, lineno=2, index=115, end=120) 23 | Token(type='STRING', value='true', lineno=2, index=121, end=127) 24 | Token(type='STRING', value='falsee', lineno=2, index=128, end=136) 25 | Token(type='ID', value='falsee', lineno=2, index=137, end=143) 26 | Token(type='ID', value='falsetrue', lineno=2, index=144, end=153) 27 | Token(type='ID', value='truee', lineno=2, index=154, end=159) -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/workflow.log: -------------------------------------------------------------------------------- 1 | Script started on Fri Dec 13 22:00:28 2019 2 | 3 | The default interactive shell is now zsh. 4 | To update your account to use zsh, please run `chsh -s /bin/zsh`. 5 | For more details, please visit https://support.apple.com/kb/HT208050. 6 | [?1034hexpr-tac> yalalr 7 | This is SBCL 1.5.1, an implementation of ANSI Common Lisp. 8 | More information about SBCL is available at . 9 | 10 | SBCL is free software, provided as is, with absolutely no warranty. 11 | It is mostly in the public domain; some portions are provided under 12 | BSD-style licenses. See the CREDITS and COPYING files in the 13 | distribution for more information. 14 | STYLE-WARNING: Defining (*TOPCAT*) as a constant, even though the name follows 15 | the usual naming convention (names like *FOO*) for special variables 16 |  WARNING: redefining COMMON-LISP-USER::PARSE in DEFUN 17 | 18 | =================================================== 19 | Welcome to yalalr, version 2.0 20 | an interface to LALR parser of Mark Johnson 21 | --------------------------------------------------- 22 | Ready. 23 | =================================================== 24 | lexer ok 25 | SDD ok 26 | Grammar loaded. LALR tables set. 27 | > (ic-gen "code1") 28 | 29 | (3AC MULT #:|t-369| C D) 30 | (3AC ADD #:|t-370| B #:|t-369|) 31 | (2AC UMINUS #:|t-371| E) 32 | (3AC ADD #:|t-372| #:|t-371| F) 33 | (3AC DIV #:|t-373| #:|t-372| 5) 34 | (3AC SUB #:|t-374| #:|t-370| #:|t-373|) 35 | (2COPY A #:|t-374|) 36 | T 37 | > (ic-gen "code2") 38 | 39 | (2AC UMINUS #:|t-375| F) 40 | (3AC DIV #:|t-376| #:|t-375| 5) 41 | (2COPY B #:|t-376|) 42 | T 43 | expr-tac> exit 44 | 45 | Script done on Fri Dec 13 22:00:49 2019 46 | -------------------------------------------------------------------------------- /project-material/project1_solutions/lexer.py: -------------------------------------------------------------------------------- 1 | import sly 2 | 3 | class Lexer(sly.Lexer): 4 | 5 | def __init__(self): 6 | super().__init__() 7 | self.keywords = {'if', 'else', 'while', 'print', 'and', 'fun', 'for', 'or', 'return', 'var'} 8 | 9 | tokens = { NUMBER, ID, WHILE, IF, ELSE, PRINT, 10 | PLUS, MINUS, TIMES, DIVIDE, ASSIGN, 11 | EQ, LT, LE, GT, GE, NE, AND, 12 | FALSE, TRUE, FUN, FOR, OR, 13 | RETURN, VAR, STRING, NOT} 14 | 15 | literals = { '(', ')', '{', '}', '[', ']', ';' , ',', '#'} 16 | 17 | ignore = ' \t\r\f\v' 18 | 19 | ignore_comment = r'//.*' 20 | 21 | EQ = r'==' 22 | LE = r'<=' 23 | GE = r'>=' 24 | NE = r'!=' 25 | 26 | ASSIGN = r'=' 27 | LT = r'<' 28 | GT = r'>' 29 | NOT = r'!' 30 | 31 | PLUS = r'\+' 32 | MINUS = r'-' 33 | TIMES = r'\*' 34 | DIVIDE = r'/' 35 | 36 | @_(r'"[^"]*"') 37 | def STRING(self, t): 38 | t.value = t.value[1:-1] 39 | return t 40 | 41 | @_(r'\d+(\.\d+)?') 42 | def NUMBER(self, t): 43 | t.value = float(t.value) 44 | return t 45 | 46 | @_(r'[a-zA-Z_][a-zA-Z0-9_]*') 47 | def ID(self, t): 48 | if t.value in self.keywords: 49 | t.type = t.value.upper() 50 | if t.value == 'true': 51 | t.value = True 52 | t.type = 'TRUE' 53 | elif t.value == 'false': 54 | t.value = False 55 | t.type = 'FALSE' 56 | return t 57 | 58 | @_(r'\n+') 59 | def ignore_newline(self, t): 60 | self.lineno += t.value.count('\n') 61 | 62 | def error(self, t): 63 | print('Line %d: Bad character %r' % (self.lineno, t.value[0])) 64 | self.index += 1 65 | t.value = t.value[0] 66 | return t 67 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lListener.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.tree.ParseTreeListener; 3 | 4 | /** 5 | * This interface defines a complete listener for a parse tree produced by 6 | * {@link lParser}. 7 | */ 8 | public interface lListener extends ParseTreeListener { 9 | /** 10 | * Enter a parse tree produced by {@link lParser#start}. 11 | * @param ctx the parse tree 12 | */ 13 | void enterStart(lParser.StartContext ctx); 14 | /** 15 | * Exit a parse tree produced by {@link lParser#start}. 16 | * @param ctx the parse tree 17 | */ 18 | void exitStart(lParser.StartContext ctx); 19 | /** 20 | * Enter a parse tree produced by {@link lParser#s}. 21 | * @param ctx the parse tree 22 | */ 23 | void enterS(lParser.SContext ctx); 24 | /** 25 | * Exit a parse tree produced by {@link lParser#s}. 26 | * @param ctx the parse tree 27 | */ 28 | void exitS(lParser.SContext ctx); 29 | /** 30 | * Enter a parse tree produced by {@link lParser#def}. 31 | * @param ctx the parse tree 32 | */ 33 | void enterDef(lParser.DefContext ctx); 34 | /** 35 | * Exit a parse tree produced by {@link lParser#def}. 36 | * @param ctx the parse tree 37 | */ 38 | void exitDef(lParser.DefContext ctx); 39 | /** 40 | * Enter a parse tree produced by {@link lParser#f}. 41 | * @param ctx the parse tree 42 | */ 43 | void enterF(lParser.FContext ctx); 44 | /** 45 | * Exit a parse tree produced by {@link lParser#f}. 46 | * @param ctx the parse tree 47 | */ 48 | void exitF(lParser.FContext ctx); 49 | /** 50 | * Enter a parse tree produced by {@link lParser#t}. 51 | * @param ctx the parse tree 52 | */ 53 | void enterT(lParser.TContext ctx); 54 | /** 55 | * Exit a parse tree produced by {@link lParser#t}. 56 | * @param ctx the parse tree 57 | */ 58 | void exitT(lParser.TContext ctx); 59 | } -------------------------------------------------------------------------------- /project-material/project_1_for_students/tester.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import argparse 4 | import pickle 5 | from ast_tools import PrintVisitor 6 | from misc import * 7 | from lexer import Lexer 8 | 9 | arg_parser = argparse.ArgumentParser() 10 | 11 | arg_parser.add_argument('test_type', choices=['scan', 'parse', 'analyze']) 12 | arg_parser.add_argument('filename', type=str) 13 | arg_parser.add_argument('--save', action='store_true') 14 | 15 | args = arg_parser.parse_args() 16 | 17 | with open(args.filename,'r') as f: 18 | source = f.read() 19 | 20 | if args.test_type == 'scan': 21 | toks = Lexer().tokenize(source) 22 | result = 'Tokens:\n'+'\n'.join([str(tok) for tok in toks]) 23 | print(result) 24 | if args.save: 25 | with open(args.filename+'.toks', 'w') as f: 26 | f.write(result) 27 | 28 | elif args.test_type == 'parse': 29 | intermediate = process(source) 30 | ast = generate_ast(intermediate) 31 | ast_str = PrintVisitor().visit(ast) 32 | print('PrintVisitor Output:') 33 | print(ast_str) 34 | if args.save: 35 | with open(args.filename+'.ast.pkl', 'wb') as f: 36 | pickle.dump(ast, f) 37 | with open(args.filename+'.ast', 'w') as f: 38 | f.write(ast_str) 39 | 40 | else: 41 | intermediate = process(source) 42 | ast = generate_ast(intermediate) 43 | print('PrintVisitor Output:') 44 | print(PrintVisitor().visit(ast)) 45 | undecl_vars = undeclared_vars(intermediate) 46 | multiple_decls = multiple_var_declarations(intermediate) 47 | result = 'Undeclared vars:\n' 48 | result = result + '\n'.join([str(iden) for iden in undecl_vars]) 49 | result = result + '\n'+'Multiple var declarations:\n' 50 | result = result + '\n'.join([str(iden) for iden in multiple_decls]) 51 | print(result) 52 | if args.save: 53 | with open(args.filename+'.log', 'w') as f: 54 | f.write(result) 55 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex3/workflow.log: -------------------------------------------------------------------------------- 1 | Script started on Fri Dec 13 22:49:25 2019 2 | 3 | The default interactive shell is now zsh. 4 | To update your account to use zsh, please run `chsh -s /bin/zsh`. 5 | For more details, please visit https://support.apple.com/kb/HT208050. 6 | [?1034hex3> yalalr 7 | This is SBCL 1.5.1, an implementation of ANSI Common Lisp. 8 | More information about SBCL is available at . 9 | 10 | SBCL is free software, provided as is, with absolutely no warranty. 11 | It is mostly in the public domain; some portions are provided under 12 | BSD-style licenses. See the CREDITS and COPYING files in the 13 | distribution for more information. 14 | STYLE-WARNING: Defining (*TOPCAT*) as a constant, even though the name follows 15 | the usual naming convention (names like *FOO*) for special variables 16 |  WARNING: redefining COMMON-LISP-USER::PARSE in DEFUN 17 | 18 | =================================================== 19 | Welcome to yalalr, version 2.0 20 | an interface to LALR parser of Mark Johnson 21 | --------------------------------------------------- 22 | Ready. 23 | =================================================== 24 | lexer ok 25 | SDD ok 26 | 27 | ; file: /Users/bozsahin/myrepos/yalalr/examples/ex3/sdd.lisp 28 | ; in: DEFUN IS-V 29 | ; (SPECIAL-OPERATOR-P E) 30 | ; 31 | ; caught WARNING: 32 | ; Derived type of E is 33 | ; (VALUES (AND ATOM (NOT SYMBOL)) &OPTIONAL), 34 | ; conflicting with its asserted type 35 | ; SYMBOL. 36 | ; See also: 37 | ; The SBCL Manual, Node "Handling of Types" 38 | ; 39 | ; compilation unit finished 40 | ; caught 1 WARNING condition 41 | Grammar loaded. LALR tables set. 42 | > (target-code "source.supervision") 43 | (((JOHN SAW THE MAN) ((SAW MAN) JOHN)) ((MARY WALKED) (WALK !MARY))) 44 | ex3> exit 45 | 46 | Script done on Fri Dec 13 22:49:32 2019 47 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-zac/sdd.lisp: -------------------------------------------------------------------------------- 1 | ;;;; this example compiles arithmetic expressions and their assignment to 2 | ;;;; a simple stack-based VM (i.e. zero-address MOVE, ADD, SUB, MULT, DIV, 3 | ;;;; and one-address LVAL, RVAL for pushing in left and right values) 4 | ;;;; (assume MOVE pops an rvalue, then an lvalue, and moves the rvalue to that lvalue in RAM) 5 | ;;;; -cem bozsahin 6 | 7 | 8 | ;; advice: never use a constant on the RHS of rules, put them in the lexicon and 9 | ;; symbolize them in lexforms 10 | 11 | ;; some aux functions 12 | 13 | (defun name (x) 14 | (second x)) 15 | 16 | (defun val (x) 17 | (name x)) 18 | 19 | ;;;; LALR data 20 | 21 | (defparameter grammar 22 | '( 23 | (start --> ID COLON EQLS e END #'(lambda (ID COLON EQLS e END) (append (list 'LVAL (val ID) '/) e '(MOVE)))) 24 | (e --> e ADD te #'(lambda (e ADD te) (append e te '(ADD /)))) 25 | (e --> e SUB te #'(lambda (e SUB te) (append e te '(SUB /)))) 26 | (e --> te #'(lambda (te) (identity te))) 27 | (te --> te MULT f #'(lambda (te MULT f) (append te f '(MULT /)))) 28 | (te --> te DIV f #'(lambda (te DIV f) (append te f '(DIV /)))) 29 | (te --> f #'(lambda (f)(identity f))) 30 | (f --> LP e RP #'(lambda (LP e RP) (identity e))) 31 | (f --> SUB ID #'(lambda (SUB ID) (append (list 'RVAL) (list (val ID) '/) '(NEG /)))) 32 | (f --> ID #'(lambda (ID) (list 'RVAL (val ID) '/))) 33 | )) 34 | 35 | (defparameter lexforms '(ID END COLON EQLS LP RP ADD SUB MULT DIV)) 36 | 37 | (defparameter lexicon '( 38 | (\; END) ;; all but ID goes in the lexicon 39 | (|:| COLON) 40 | (|=| EQLS) 41 | (|(| LP) 42 | (|)| RP) 43 | ($ $) ; this is for lalrparser.lisp's end of input 44 | (+ ADD) 45 | (- SUB) 46 | (* MULT) 47 | (/ DIV) 48 | )) 49 | ;; if you change the end-marker, change its hardcopy above in lexicon above as well. 50 | ;; (because LALR parser does not evaluate its lexicon symbols---sorry.) 51 | (defparameter *ENDMARKER* '$) 52 | 53 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '(' 4 | ')' 5 | null 6 | null 7 | null 8 | null 9 | null 10 | null 11 | 12 | token symbolic names: 13 | null 14 | null 15 | null 16 | WS 17 | OP 18 | NUM 19 | ID 20 | KEYWD 21 | NEWLINE 22 | 23 | rule names: 24 | T__0 25 | T__1 26 | WS 27 | OP 28 | NUM 29 | ID 30 | KEYWD 31 | NEWLINE 32 | 33 | channel names: 34 | DEFAULT_TOKEN_CHANNEL 35 | HIDDEN 36 | 37 | mode names: 38 | DEFAULT_MODE 39 | 40 | atn: 41 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 10, 53, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 6, 4, 25, 10, 4, 13, 4, 14, 4, 26, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 6, 6, 34, 10, 6, 13, 6, 14, 6, 35, 3, 7, 3, 7, 3, 7, 7, 7, 41, 10, 7, 12, 7, 14, 7, 44, 11, 7, 3, 8, 3, 8, 3, 8, 3, 9, 5, 9, 50, 10, 9, 3, 9, 3, 9, 2, 2, 10, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 3, 2, 6, 5, 2, 11, 12, 15, 15, 34, 34, 3, 2, 44, 49, 3, 2, 50, 59, 4, 2, 67, 92, 99, 124, 2, 57, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 3, 19, 3, 2, 2, 2, 5, 21, 3, 2, 2, 2, 7, 24, 3, 2, 2, 2, 9, 30, 3, 2, 2, 2, 11, 33, 3, 2, 2, 2, 13, 37, 3, 2, 2, 2, 15, 45, 3, 2, 2, 2, 17, 49, 3, 2, 2, 2, 19, 20, 7, 42, 2, 2, 20, 4, 3, 2, 2, 2, 21, 22, 7, 43, 2, 2, 22, 6, 3, 2, 2, 2, 23, 25, 9, 2, 2, 2, 24, 23, 3, 2, 2, 2, 25, 26, 3, 2, 2, 2, 26, 24, 3, 2, 2, 2, 26, 27, 3, 2, 2, 2, 27, 28, 3, 2, 2, 2, 28, 29, 8, 4, 2, 2, 29, 8, 3, 2, 2, 2, 30, 31, 9, 3, 2, 2, 31, 10, 3, 2, 2, 2, 32, 34, 9, 4, 2, 2, 33, 32, 3, 2, 2, 2, 34, 35, 3, 2, 2, 2, 35, 33, 3, 2, 2, 2, 35, 36, 3, 2, 2, 2, 36, 12, 3, 2, 2, 2, 37, 42, 9, 5, 2, 2, 38, 41, 9, 5, 2, 2, 39, 41, 5, 11, 6, 2, 40, 38, 3, 2, 2, 2, 40, 39, 3, 2, 2, 2, 41, 44, 3, 2, 2, 2, 42, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 14, 3, 2, 2, 2, 44, 42, 3, 2, 2, 2, 45, 46, 7, 97, 2, 2, 46, 47, 5, 13, 7, 2, 47, 16, 3, 2, 2, 2, 48, 50, 7, 15, 2, 2, 49, 48, 3, 2, 2, 2, 49, 50, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 7, 12, 2, 2, 52, 18, 3, 2, 2, 2, 8, 2, 26, 35, 40, 42, 49, 3, 8, 2, 2] -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lListener.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.tree.ParseTreeListener; 3 | 4 | /** 5 | * This interface defines a complete listener for a parse tree produced by 6 | * {@link lParser}. 7 | */ 8 | public interface lListener extends ParseTreeListener { 9 | /** 10 | * Enter a parse tree produced by {@link lParser#start}. 11 | * @param ctx the parse tree 12 | */ 13 | void enterStart(lParser.StartContext ctx); 14 | /** 15 | * Exit a parse tree produced by {@link lParser#start}. 16 | * @param ctx the parse tree 17 | */ 18 | void exitStart(lParser.StartContext ctx); 19 | /** 20 | * Enter a parse tree produced by {@link lParser#s}. 21 | * @param ctx the parse tree 22 | */ 23 | void enterS(lParser.SContext ctx); 24 | /** 25 | * Exit a parse tree produced by {@link lParser#s}. 26 | * @param ctx the parse tree 27 | */ 28 | void exitS(lParser.SContext ctx); 29 | /** 30 | * Enter a parse tree produced by {@link lParser#def}. 31 | * @param ctx the parse tree 32 | */ 33 | void enterDef(lParser.DefContext ctx); 34 | /** 35 | * Exit a parse tree produced by {@link lParser#def}. 36 | * @param ctx the parse tree 37 | */ 38 | void exitDef(lParser.DefContext ctx); 39 | /** 40 | * Enter a parse tree produced by {@link lParser#e}. 41 | * @param ctx the parse tree 42 | */ 43 | void enterE(lParser.EContext ctx); 44 | /** 45 | * Exit a parse tree produced by {@link lParser#e}. 46 | * @param ctx the parse tree 47 | */ 48 | void exitE(lParser.EContext ctx); 49 | /** 50 | * Enter a parse tree produced by {@link lParser#t}. 51 | * @param ctx the parse tree 52 | */ 53 | void enterT(lParser.TContext ctx); 54 | /** 55 | * Exit a parse tree produced by {@link lParser#t}. 56 | * @param ctx the parse tree 57 | */ 58 | void exitT(lParser.TContext ctx); 59 | /** 60 | * Enter a parse tree produced by {@link lParser#f}. 61 | * @param ctx the parse tree 62 | */ 63 | void enterF(lParser.FContext ctx); 64 | /** 65 | * Exit a parse tree produced by {@link lParser#f}. 66 | * @param ctx the parse tree 67 | */ 68 | void exitF(lParser.FContext ctx); 69 | } -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '$' 4 | '=' 5 | '=>' 6 | '(' 7 | ')' 8 | '~' 9 | '0' 10 | '1' 11 | null 12 | null 13 | null 14 | 15 | token symbolic names: 16 | null 17 | null 18 | null 19 | null 20 | null 21 | null 22 | null 23 | null 24 | null 25 | WS 26 | NEWLINE 27 | PL 28 | 29 | rule names: 30 | T__0 31 | T__1 32 | T__2 33 | T__3 34 | T__4 35 | T__5 36 | T__6 37 | T__7 38 | WS 39 | NEWLINE 40 | PL 41 | 42 | channel names: 43 | DEFAULT_TOKEN_CHANNEL 44 | HIDDEN 45 | 46 | mode names: 47 | DEFAULT_MODE 48 | 49 | atn: 50 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 56, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 6, 10, 44, 10, 10, 13, 10, 14, 10, 45, 3, 10, 3, 10, 3, 11, 5, 11, 51, 10, 11, 3, 11, 3, 11, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 4, 5, 2, 11, 12, 15, 15, 34, 34, 4, 2, 67, 92, 99, 124, 2, 57, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 32, 3, 2, 2, 2, 11, 34, 3, 2, 2, 2, 13, 36, 3, 2, 2, 2, 15, 38, 3, 2, 2, 2, 17, 40, 3, 2, 2, 2, 19, 43, 3, 2, 2, 2, 21, 50, 3, 2, 2, 2, 23, 54, 3, 2, 2, 2, 25, 26, 7, 38, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 63, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 63, 2, 2, 30, 31, 7, 64, 2, 2, 31, 8, 3, 2, 2, 2, 32, 33, 7, 42, 2, 2, 33, 10, 3, 2, 2, 2, 34, 35, 7, 43, 2, 2, 35, 12, 3, 2, 2, 2, 36, 37, 7, 128, 2, 2, 37, 14, 3, 2, 2, 2, 38, 39, 7, 50, 2, 2, 39, 16, 3, 2, 2, 2, 40, 41, 7, 51, 2, 2, 41, 18, 3, 2, 2, 2, 42, 44, 9, 2, 2, 2, 43, 42, 3, 2, 2, 2, 44, 45, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 45, 46, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 48, 8, 10, 2, 2, 48, 20, 3, 2, 2, 2, 49, 51, 7, 15, 2, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 12, 2, 2, 53, 22, 3, 2, 2, 2, 54, 55, 9, 3, 2, 2, 55, 24, 3, 2, 2, 2, 5, 2, 45, 50, 3, 8, 2, 2] -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '$' 4 | '=' 5 | '=>' 6 | '(' 7 | ')' 8 | '~' 9 | '0' 10 | '1' 11 | null 12 | null 13 | null 14 | 15 | token symbolic names: 16 | null 17 | null 18 | null 19 | null 20 | null 21 | null 22 | null 23 | null 24 | null 25 | WS 26 | NEWLINE 27 | PL 28 | 29 | rule names: 30 | T__0 31 | T__1 32 | T__2 33 | T__3 34 | T__4 35 | T__5 36 | T__6 37 | T__7 38 | WS 39 | NEWLINE 40 | PL 41 | 42 | channel names: 43 | DEFAULT_TOKEN_CHANNEL 44 | HIDDEN 45 | 46 | mode names: 47 | DEFAULT_MODE 48 | 49 | atn: 50 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 13, 56, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 6, 10, 44, 10, 10, 13, 10, 14, 10, 45, 3, 10, 3, 10, 3, 11, 5, 11, 51, 10, 11, 3, 11, 3, 11, 3, 12, 3, 12, 2, 2, 13, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 3, 2, 4, 5, 2, 11, 12, 15, 15, 34, 34, 4, 2, 67, 92, 99, 124, 2, 57, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 3, 25, 3, 2, 2, 2, 5, 27, 3, 2, 2, 2, 7, 29, 3, 2, 2, 2, 9, 32, 3, 2, 2, 2, 11, 34, 3, 2, 2, 2, 13, 36, 3, 2, 2, 2, 15, 38, 3, 2, 2, 2, 17, 40, 3, 2, 2, 2, 19, 43, 3, 2, 2, 2, 21, 50, 3, 2, 2, 2, 23, 54, 3, 2, 2, 2, 25, 26, 7, 38, 2, 2, 26, 4, 3, 2, 2, 2, 27, 28, 7, 63, 2, 2, 28, 6, 3, 2, 2, 2, 29, 30, 7, 63, 2, 2, 30, 31, 7, 64, 2, 2, 31, 8, 3, 2, 2, 2, 32, 33, 7, 42, 2, 2, 33, 10, 3, 2, 2, 2, 34, 35, 7, 43, 2, 2, 35, 12, 3, 2, 2, 2, 36, 37, 7, 128, 2, 2, 37, 14, 3, 2, 2, 2, 38, 39, 7, 50, 2, 2, 39, 16, 3, 2, 2, 2, 40, 41, 7, 51, 2, 2, 41, 18, 3, 2, 2, 2, 42, 44, 9, 2, 2, 2, 43, 42, 3, 2, 2, 2, 44, 45, 3, 2, 2, 2, 45, 43, 3, 2, 2, 2, 45, 46, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 48, 8, 10, 2, 2, 48, 20, 3, 2, 2, 2, 49, 51, 7, 15, 2, 2, 50, 49, 3, 2, 2, 2, 50, 51, 3, 2, 2, 2, 51, 52, 3, 2, 2, 2, 52, 53, 7, 12, 2, 2, 53, 22, 3, 2, 2, 2, 54, 55, 9, 3, 2, 2, 55, 24, 3, 2, 2, 2, 5, 2, 45, 50, 3, 8, 2, 2] -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpBaseListener.java: -------------------------------------------------------------------------------- 1 | // Generated from bp.g4 by ANTLR 4.7.1 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.tree.ErrorNode; 5 | import org.antlr.v4.runtime.tree.TerminalNode; 6 | 7 | /** 8 | * This class provides an empty implementation of {@link bpListener}, 9 | * which can be extended to create a listener which only needs to handle a subset 10 | * of the available methods. 11 | */ 12 | public class bpBaseListener implements bpListener { 13 | /** 14 | * {@inheritDoc} 15 | * 16 | *

The default implementation does nothing.

17 | */ 18 | @Override public void enterProg(bpParser.ProgContext ctx) { } 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

The default implementation does nothing.

23 | */ 24 | @Override public void exitProg(bpParser.ProgContext ctx) { } 25 | /** 26 | * {@inheritDoc} 27 | * 28 | *

The default implementation does nothing.

29 | */ 30 | @Override public void enterStart(bpParser.StartContext ctx) { } 31 | /** 32 | * {@inheritDoc} 33 | * 34 | *

The default implementation does nothing.

35 | */ 36 | @Override public void exitStart(bpParser.StartContext ctx) { } 37 | /** 38 | * {@inheritDoc} 39 | * 40 | *

The default implementation does nothing.

41 | */ 42 | @Override public void enterData(bpParser.DataContext ctx) { } 43 | /** 44 | * {@inheritDoc} 45 | * 46 | *

The default implementation does nothing.

47 | */ 48 | @Override public void exitData(bpParser.DataContext ctx) { } 49 | 50 | /** 51 | * {@inheritDoc} 52 | * 53 | *

The default implementation does nothing.

54 | */ 55 | @Override public void enterEveryRule(ParserRuleContext ctx) { } 56 | /** 57 | * {@inheritDoc} 58 | * 59 | *

The default implementation does nothing.

60 | */ 61 | @Override public void exitEveryRule(ParserRuleContext ctx) { } 62 | /** 63 | * {@inheritDoc} 64 | * 65 | *

The default implementation does nothing.

66 | */ 67 | @Override public void visitTerminal(TerminalNode node) { } 68 | /** 69 | * {@inheritDoc} 70 | * 71 | *

The default implementation does nothing.

72 | */ 73 | @Override public void visitErrorNode(ErrorNode node) { } 74 | } -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/ex2/workflow.log: -------------------------------------------------------------------------------- 1 | Script started on Fri Dec 13 22:44:22 2019 2 | 3 | The default interactive shell is now zsh. 4 | To update your account to use zsh, please run `chsh -s /bin/zsh`. 5 | For more details, please visit https://support.apple.com/kb/HT208050. 6 | [?1034hex2> yalalr 7 | This is SBCL 1.5.1, an implementation of ANSI Common Lisp. 8 | More information about SBCL is available at . 9 | 10 | SBCL is free software, provided as is, with absolutely no warranty. 11 | It is mostly in the public domain; some portions are provided under 12 | BSD-style licenses. See the CREDITS and COPYING files in the 13 | distribution for more information. 14 | STYLE-WARNING: Defining (*TOPCAT*) as a constant, even though the name follows 15 | the usual naming convention (names like *FOO*) for special variables 16 |  WARNING: redefining COMMON-LISP-USER::PARSE in DEFUN 17 | 18 | =================================================== 19 | Welcome to yalalr, version 2.0 20 | an interface to LALR parser of Mark Johnson 21 | --------------------------------------------------- 22 | Ready. 23 | =================================================== 24 | lexer ok 25 | SDD ok 26 | 27 | ; file: /Users/bozsahin/myrepos/yalalr/examples/ex2/sdd.lisp 28 | ; in: DEFUN IS-V 29 | ; (SPECIAL-OPERATOR-P E) 30 | ; 31 | ; caught WARNING: 32 | ; Derived type of E is 33 | ; (VALUES (AND ATOM (NOT SYMBOL)) &OPTIONAL), 34 | ; conflicting with its asserted type 35 | ; SYMBOL. 36 | ; See also: 37 | ; The SBCL Manual, Node "Handling of Types" 38 | ; 39 | ; compilation unit finished 40 | ; caught 1 WARNING condition 41 |  Grammar loaded. LALR tables set. 42 | > (target-code "source.ccg") 43 | (DEFPARAMETER *CCG-GRAMMAR* 44 | '(((KEY 1) (PHON JOHN) (MORPH N) 45 | (SYN 46 | (((BCAT S) (FEATS NIL)) (DIR FS) (MODAL ALL) 47 | (((BCAT S) (FEATS NIL)) (DIR BS) (MODAL ALL) ((BCAT NP) (FEATS NIL))))) 48 | (SEM (LAM P (P !JOHN))) (PARAM 1.0)) 49 | ((KEY 2) (PHON LIKES) (MORPH V) 50 | (SYN 51 | ((((BCAT S) (FEATS NIL)) (DIR BS) (MODAL ALL) ((BCAT NP) (FEATS NIL))) 52 | (DIR FS) (MODAL ALL) ((BCAT NP) (FEATS NIL)))) 53 | (SEM (LAM X (LAM Y ((!LIKES X) Y)))) (PARAM 1.0)))) 54 | ex2> exit 55 | 56 | Script done on Fri Dec 13 22:44:32 2019 57 | -------------------------------------------------------------------------------- /project-material/README.md: -------------------------------------------------------------------------------- 1 | The language to be compiled will be the same for project 1 and project 2. 2 | 3 | - Project 1 is about lexical analysis, syntactic analysis, AST generation, and a bit of error reporting. 4 | 5 | PROJECT 1 DUE DATE: December 4, 23.59 6 | 7 | - Project 2 is about code generation and execution. You can assume that the input is well-formed. 8 | 9 | PROJECT 2 DUE DATE: Last day of classes, 23.59 10 | 11 | This term's language is Vox, a modified version of Lox. 12 | 13 | -1 Namely, Vox is Lox minus closures, libraries and OOP stuff (i.e. classes and dynamic objects). 14 | 15 | -2 Vox is plus-Lox in data structures: We can have vectors of basic data types of Lox. 16 | 17 | -3 There are also some syntactic differences, for example in 18 | the multiple assignment statement, and the expression statement. 19 | Boolean use of an identifier and function call is marked, etc. 20 | Formal specification of Vox is given in this directory. 21 | 22 | Why have we made the changes 1-2 to Lox in a compiler course? Because we want you 23 | to go all the way down to a physical architecture, rather than settle for an interpreter. 24 | 25 | This is probably the only compiler course you will take, and it is important 26 | for a computer scientist to be left alone with the physical thing at least once. 27 | 28 | We will stay at the level of architecture for the real thing, looking at it 29 | from the perspective of RISC-V. 30 | 31 | VOX LEXICON: 32 | 33 | - Keywords and identifiers are case-sensitive. 34 | 35 | - Identifier convention is same as Lox. 36 | 37 | VOX SYNTAX: 38 | 39 | - Check out the formal specification of Vox grammar in this directory. 40 | 41 | - Indenting is not significant. 42 | 43 | - Comments start with // and end at the end of the same line. 44 | 45 | VOX SEMANTICS: 46 | 47 | - Vox programs commence execution by executing top-level statements in the order they are specified. 48 | 49 | - Variables must be declared before use. (Some say this is syntax; we'd say 50 | it's more about programmer's psychology.) 51 | 52 | - Variables cannot be re-declared in the same block (ditto). 53 | 54 | - Vectors are homogeneous. 55 | 56 | - Vector indices start from 0. They are integers. 57 | 58 | - To stay more or less compatible with Lox without libraries, we eschew the input statement. 59 | 60 | Happy Voxing, 61 | 62 | 63 | -Cem & Cem 64 | 65 | November 2022 66 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/deco.py: -------------------------------------------------------------------------------- 1 | # Decorator demo: input function with zero or more args, 2 | # composition, decorator with args, and fixpoint decorators 3 | # -cem bozsahin 4 | 5 | # this is the decorator d1, taking one function with some arguments 6 | def d1(fun): 7 | def inn(*args, **kwargs): 8 | print("here is the input to the decorator:",fun,*args,**kwargs) 9 | fun(*args, **kwargs) 10 | print("done") 11 | return inn # a decorator must always return a function 12 | 13 | @d1 # this is d1 decorating f 14 | def f(): 15 | print('f does this') 16 | 17 | # That is equilavent to f=d1(f) 18 | 19 | @d1 20 | def h(x,y): 21 | return x+y 22 | 23 | # That is equivalent to h=d1(h), i.e. same as 0-argument function above. 24 | 25 | @d1 26 | def g(x,y,z): 27 | print(x+y-z) 28 | 29 | # try fun calls such as f(), h(2,3), g(4,5,7) 30 | 31 | # these are decorators d2 and d3, for chaining, i.e. composition 32 | def d2(f): 33 | def inn(): 34 | v=f() 35 | return v * v 36 | return inn 37 | 38 | def d3(f): 39 | def inn(): 40 | v=f() 41 | return -v 42 | return inn 43 | 44 | @d2 45 | @d3 46 | def k23(): 47 | return 5 48 | 49 | @d3 50 | @d2 51 | def k32(): 52 | return 5 53 | 54 | # Try k23() and k32() function calls for composing squaring with negation 55 | # or negation with squaring. 56 | 57 | # d4 is an example of a decorator with an argument. 58 | def d4(n): 59 | def inn(f): 60 | def inn2(arg): 61 | return n * f(arg) 62 | return inn2 63 | return inn 64 | 65 | @d4(7) 66 | def f4(n): 67 | return n-1 68 | 69 | @d4(8) 70 | def f5(n): 71 | return n ** 2 72 | 73 | 74 | # these are equivalent to e,g, f4=d4(7,f4) 75 | # try f4(7) and f5(7) 76 | 77 | # fact is the fixpoint of the factorial, because fact=d5(fact) 78 | def d5(f): 79 | def inn(n): 80 | if n > 0: 81 | return n * f(n-1) 82 | else: 83 | return 1 84 | return inn 85 | 86 | @d5 87 | def fact(n): 88 | if n > 0: 89 | return n * fact(n-1) 90 | else: 91 | return 1 92 | 93 | # Try e.g. fact(6) with and without d5. (You'd need to eliminate d5 code and its use for the last one). 94 | 95 | # The following will give syntax errors if uncommented. 96 | # Decorators work on named functions 97 | #@d1 98 | #(lambda x: lambda y: print(x+y)) 99 | 100 | #@d1 101 | #w= (lambda x: lambda y: print(x+y)) 102 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lBaseListener.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.tree.ErrorNode; 5 | import org.antlr.v4.runtime.tree.TerminalNode; 6 | 7 | /** 8 | * This class provides an empty implementation of {@link lListener}, 9 | * which can be extended to create a listener which only needs to handle a subset 10 | * of the available methods. 11 | */ 12 | public class lBaseListener implements lListener { 13 | /** 14 | * {@inheritDoc} 15 | * 16 | *

The default implementation does nothing.

17 | */ 18 | @Override public void enterStart(lParser.StartContext ctx) { } 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

The default implementation does nothing.

23 | */ 24 | @Override public void exitStart(lParser.StartContext ctx) { } 25 | /** 26 | * {@inheritDoc} 27 | * 28 | *

The default implementation does nothing.

29 | */ 30 | @Override public void enterS(lParser.SContext ctx) { } 31 | /** 32 | * {@inheritDoc} 33 | * 34 | *

The default implementation does nothing.

35 | */ 36 | @Override public void exitS(lParser.SContext ctx) { } 37 | /** 38 | * {@inheritDoc} 39 | * 40 | *

The default implementation does nothing.

41 | */ 42 | @Override public void enterDef(lParser.DefContext ctx) { } 43 | /** 44 | * {@inheritDoc} 45 | * 46 | *

The default implementation does nothing.

47 | */ 48 | @Override public void exitDef(lParser.DefContext ctx) { } 49 | /** 50 | * {@inheritDoc} 51 | * 52 | *

The default implementation does nothing.

53 | */ 54 | @Override public void enterF(lParser.FContext ctx) { } 55 | /** 56 | * {@inheritDoc} 57 | * 58 | *

The default implementation does nothing.

59 | */ 60 | @Override public void exitF(lParser.FContext ctx) { } 61 | /** 62 | * {@inheritDoc} 63 | * 64 | *

The default implementation does nothing.

65 | */ 66 | @Override public void enterT(lParser.TContext ctx) { } 67 | /** 68 | * {@inheritDoc} 69 | * 70 | *

The default implementation does nothing.

71 | */ 72 | @Override public void exitT(lParser.TContext ctx) { } 73 | 74 | /** 75 | * {@inheritDoc} 76 | * 77 | *

The default implementation does nothing.

78 | */ 79 | @Override public void enterEveryRule(ParserRuleContext ctx) { } 80 | /** 81 | * {@inheritDoc} 82 | * 83 | *

The default implementation does nothing.

84 | */ 85 | @Override public void exitEveryRule(ParserRuleContext ctx) { } 86 | /** 87 | * {@inheritDoc} 88 | * 89 | *

The default implementation does nothing.

90 | */ 91 | @Override public void visitTerminal(TerminalNode node) { } 92 | /** 93 | * {@inheritDoc} 94 | * 95 | *

The default implementation does nothing.

96 | */ 97 | @Override public void visitErrorNode(ErrorNode node) { } 98 | } -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips-float/target_source1.s: -------------------------------------------------------------------------------- 1 | 2 | 3 | .data 4 | 5 | B: .float 0.0 6 | C: .float 0.0 7 | D: .float 0.0 8 | t369: .float 0.0 9 | t370: .float 0.0 10 | t371: .float 0.0 11 | E: .float 0.0 12 | F: .float 0.0 13 | t372: .float 0.0 14 | t373: .float 0.0 15 | t374: .float 0.0 16 | A: .float 0.0 17 | zzeerroo: .float 0.0 18 | 19 | .text 20 | 21 | main: 22 | l.s $f0,C 23 | l.s $f2,D 24 | mul.s $f0,$f0,$f2 25 | s.s $f0,t369 26 | l.s $f0,B 27 | l.s $f2,t369 28 | add.s $f0,$f0,$f2 29 | s.s $f0,t370 30 | l.s $f2,E 31 | #loading dummy zero float to $f0 32 | l.s $f0,zzeerroo 33 | sub.s $f0,$f0,$f2 34 | s.s $f0,t371 35 | l.s $f0,t371 36 | l.s $f2,F 37 | add.s $f0,$f0,$f2 38 | s.s $f0,t372 39 | l.s $f0,t372 40 | #converting to float 41 | li $t0,5 42 | mtc1 $t0,$f6 43 | cvt.s.w $f2,$f6 44 | #conversion done 45 | div.s $f0,$f0,$f2 46 | s.s $f0,t373 47 | l.s $f0,t370 48 | l.s $f2,t373 49 | sub.s $f0,$f0,$f2 50 | s.s $f0,t374 51 | l.s $f0,t374 52 | s.s $f0,A 53 | #MIPs termination protocol: 54 | li $v0,10 55 | syscall 56 | .end main 57 | 58 | .data 59 | 60 | B: .float 0.0 61 | C: .float 0.0 62 | D: .float 0.0 63 | t369: .float 0.0 64 | t370: .float 0.0 65 | t371: .float 0.0 66 | E: .float 0.0 67 | F: .float 0.0 68 | t372: .float 0.0 69 | t373: .float 0.0 70 | t374: .float 0.0 71 | A: .float 0.0 72 | zzeerroo: .float 0.0 73 | 74 | .text 75 | 76 | main: 77 | l.s $f0,C 78 | l.s $f2,D 79 | mul.s $f0,$f0,$f2 80 | s.s $f0,t369 81 | l.s $f0,B 82 | l.s $f2,t369 83 | add.s $f0,$f0,$f2 84 | s.s $f0,t370 85 | l.s $f2,E 86 | #loading dummy zero float to $f0 87 | l.s $f0,zzeerroo 88 | sub.s $f0,$f0,$f2 89 | s.s $f0,t371 90 | l.s $f0,t371 91 | l.s $f2,F 92 | add.s $f0,$f0,$f2 93 | s.s $f0,t372 94 | l.s $f0,t372 95 | #converting to float 96 | li $t0,5 97 | mtc1 $t0,$f6 98 | cvt.s.w $f2,$f6 99 | #conversion done 100 | div.s $f0,$f0,$f2 101 | s.s $f0,t373 102 | l.s $f0,t370 103 | l.s $f2,t373 104 | sub.s $f0,$f0,$f2 105 | s.s $f0,t374 106 | l.s $f0,t374 107 | s.s $f0,A 108 | #MIPs termination protocol: 109 | li $v0,10 110 | syscall 111 | .end main 112 | 113 | .data 114 | 115 | B: .float 0.0 116 | C: .float 0.0 117 | D: .float 0.0 118 | t369: .float 0.0 119 | t370: .float 0.0 120 | t371: .float 0.0 121 | E: .float 0.0 122 | F: .float 0.0 123 | t372: .float 0.0 124 | t373: .float 0.0 125 | t374: .float 0.0 126 | A: .float 0.0 127 | zzeerroo: .float 0.0 128 | 129 | .text 130 | 131 | main: 132 | l.s $f0,C 133 | l.s $f2,D 134 | mul.s $f0,$f0,$f2 135 | s.s $f0,t369 136 | l.s $f0,B 137 | l.s $f2,t369 138 | add.s $f0,$f0,$f2 139 | s.s $f0,t370 140 | l.s $f2,E 141 | #loading dummy zero float to $f0 142 | l.s $f0,zzeerroo 143 | sub.s $f0,$f0,$f2 144 | s.s $f0,t371 145 | l.s $f0,t371 146 | l.s $f2,F 147 | add.s $f0,$f0,$f2 148 | s.s $f0,t372 149 | l.s $f0,t372 150 | #converting to float 151 | li $t0,5 152 | mtc1 $t0,$f6 153 | cvt.s.w $f2,$f6 154 | #conversion done 155 | div.s $f0,$f0,$f2 156 | s.s $f0,t373 157 | l.s $f0,t370 158 | l.s $f2,t373 159 | sub.s $f0,$f0,$f2 160 | s.s $f0,t374 161 | l.s $f0,t374 162 | s.s $f0,A 163 | #MIPs termination protocol: 164 | li $v0,10 165 | syscall 166 | .end main -------------------------------------------------------------------------------- /lab-material/old_material/lalr-material/symbol-table.lisp: -------------------------------------------------------------------------------- 1 | ;; this is a simple hash implementation of symbol tables. 2 | ;; It makes use of the idea that Lisp's hashtables are collision-free 3 | ;; so that the same identifier in the same scope twice is an override 4 | ;; of same value, for which we will signal an error rather than allow 5 | ;; the override. 6 | ;; -cem bozsahin, 2018 7 | 8 | ;; it is implemented with a set of mk- (make) functions 9 | ;; and get- functions 10 | 11 | ;;;; top level use: 12 | ;; (demo-make-st) 13 | ;; (demo-show-st) 14 | 15 | (defparameter *st* nil) ; the symbol table 16 | 17 | (defun mk-key (id index) 18 | "makes a list for key of the hashtable. Index is a list, 19 | key is consed to that to make a flat list." 20 | (cons id index)) 21 | 22 | (defun mk-val (typ blockno) 23 | (list typ blockno)) 24 | 25 | (defun mk-symbol-table () 26 | "the key of the table is a list of (id index), where index is 27 | a sequence of indices for lexical scope of the id. For example 28 | (x 1 2 3) means that x is an identifier in the 3rd block 29 | of 2nd block which is nested in the 1st block at top level. 30 | The value for the key is x's type and its offset in the index 31 | (where it starts in the block). For example (int 2) means 32 | it is an int and it is the 2nd definition in the block 33 | indicated in the key. 34 | in CL, anything can be a hash key, including lists and hashtables, and even functions." 35 | (make-hash-table :test #'equal :size 100 :rehash-size 5 :rehash-threshold 0.9)) 36 | 37 | (defparameter *st* (mk-symbol-table)) ;; create once, use many times 38 | 39 | (defun add-entry (key val) 40 | "complain if key is already in the table. Return nil if error, t otherwise. 41 | 'format t' returns nil as intended, but false clause needs progn because 42 | setf returns 'val', which can be nil but and it must be added as such. 43 | The idea here is that the caller of add-entry might take action depending 44 | on its truth value (in a real compiler)." 45 | (if (gethash key *st*) 46 | (format t "~%Duplicate key: ~S; ignoring the value: ~S" key val) 47 | (progn (setf (gethash key *st*) val) 48 | t))) 49 | 50 | 51 | (defun demo-make-st () 52 | "just to show the idea at work. It has the side effect of setting the *st* parameter. 53 | I defined it as a global, rather than passing a global object of compiling as if 54 | it's a local variable." 55 | (clrhash *st*) ; initialize -- do not regenerate another hash table 56 | (add-entry (mk-key 'x '(1)) (mk-val 'int 3)) ; populate 57 | (add-entry (mk-key 'x '(1 2)) (mk-val 'real 1)) 58 | (add-entry (mk-key 'x '(1 2 1)) (mk-val 'char 4)) 59 | (add-entry (mk-key 'x '(1)) (mk-val 'real 4)) ; override complaint 60 | (add-entry (mk-key 'x '(1 2 1)) (mk-val 'float 4)) ; override complaint (that's why the hashtable must 61 | ; be of #'equal type so lists can be considered same) 62 | (add-entry (mk-key 'y '(1)) (mk-val 'int 33)) ; these are different keys, no complaint 63 | (add-entry (mk-key 'x '(1 3)) (mk-val 'real 11)) 64 | (add-entry (mk-key 'x '(2 2 1)) (mk-val 'char 44)) 65 | ) 66 | 67 | (defun demo-show-st () 68 | (maphash #'(lambda (key val) 69 | (format t "~%key=~S value=~S" key val)) 70 | *st*)) 71 | 72 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lBaseListener.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | 3 | import org.antlr.v4.runtime.ParserRuleContext; 4 | import org.antlr.v4.runtime.tree.ErrorNode; 5 | import org.antlr.v4.runtime.tree.TerminalNode; 6 | 7 | /** 8 | * This class provides an empty implementation of {@link lListener}, 9 | * which can be extended to create a listener which only needs to handle a subset 10 | * of the available methods. 11 | */ 12 | public class lBaseListener implements lListener { 13 | /** 14 | * {@inheritDoc} 15 | * 16 | *

The default implementation does nothing.

17 | */ 18 | @Override public void enterStart(lParser.StartContext ctx) { } 19 | /** 20 | * {@inheritDoc} 21 | * 22 | *

The default implementation does nothing.

23 | */ 24 | @Override public void exitStart(lParser.StartContext ctx) { } 25 | /** 26 | * {@inheritDoc} 27 | * 28 | *

The default implementation does nothing.

29 | */ 30 | @Override public void enterS(lParser.SContext ctx) { } 31 | /** 32 | * {@inheritDoc} 33 | * 34 | *

The default implementation does nothing.

35 | */ 36 | @Override public void exitS(lParser.SContext ctx) { } 37 | /** 38 | * {@inheritDoc} 39 | * 40 | *

The default implementation does nothing.

41 | */ 42 | @Override public void enterDef(lParser.DefContext ctx) { } 43 | /** 44 | * {@inheritDoc} 45 | * 46 | *

The default implementation does nothing.

47 | */ 48 | @Override public void exitDef(lParser.DefContext ctx) { } 49 | /** 50 | * {@inheritDoc} 51 | * 52 | *

The default implementation does nothing.

53 | */ 54 | @Override public void enterE(lParser.EContext ctx) { } 55 | /** 56 | * {@inheritDoc} 57 | * 58 | *

The default implementation does nothing.

59 | */ 60 | @Override public void exitE(lParser.EContext ctx) { } 61 | /** 62 | * {@inheritDoc} 63 | * 64 | *

The default implementation does nothing.

65 | */ 66 | @Override public void enterT(lParser.TContext ctx) { } 67 | /** 68 | * {@inheritDoc} 69 | * 70 | *

The default implementation does nothing.

71 | */ 72 | @Override public void exitT(lParser.TContext ctx) { } 73 | /** 74 | * {@inheritDoc} 75 | * 76 | *

The default implementation does nothing.

77 | */ 78 | @Override public void enterF(lParser.FContext ctx) { } 79 | /** 80 | * {@inheritDoc} 81 | * 82 | *

The default implementation does nothing.

83 | */ 84 | @Override public void exitF(lParser.FContext ctx) { } 85 | 86 | /** 87 | * {@inheritDoc} 88 | * 89 | *

The default implementation does nothing.

90 | */ 91 | @Override public void enterEveryRule(ParserRuleContext ctx) { } 92 | /** 93 | * {@inheritDoc} 94 | * 95 | *

The default implementation does nothing.

96 | */ 97 | @Override public void exitEveryRule(ParserRuleContext ctx) { } 98 | /** 99 | * {@inheritDoc} 100 | * 101 | *

The default implementation does nothing.

102 | */ 103 | @Override public void visitTerminal(TerminalNode node) { } 104 | /** 105 | * {@inheritDoc} 106 | * 107 | *

The default implementation does nothing.

108 | */ 109 | @Override public void visitErrorNode(ErrorNode node) { } 110 | } -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-tac/sdd.lisp: -------------------------------------------------------------------------------- 1 | ;;;; this example compiles arithmetic expressions and their assignment to 2 | ;;;; Three address code (TAC) 3 | ;;;; -cem bozsahin 4 | 5 | ;; advice: never use a constant on the RHS of rules, put them in the lexicon and 6 | ;; symbolize them in lexforms 7 | 8 | ;;; TAC Templates: 9 | ;; (3ac op p1 p2 p3) 10 | ;; (2ac op p1 p2) 11 | ;; (2copy p1 p1) 12 | 13 | ;; two functions to get type and value of tokens 14 | 15 | ;; in LALR parser, every token is a list whose first element is its type and second element its value. 16 | 17 | ;;; NOTE: the reason why i did not write any of these as macros is so that you can trace them if you feel like it 18 | 19 | (defun t-get-type (x) 20 | "token type" 21 | (first x)) 22 | 23 | (defun t-get-val (x) 24 | "token value" 25 | (second x)) 26 | 27 | (defun wrap (x) 28 | "to wrap code in parentheses" 29 | (list x)) 30 | 31 | (defun pprint-code (code) 32 | (dolist (instruction (second code)) 33 | (pprint instruction)) 34 | t) 35 | 36 | ;; some aux functions to retrieve amd make feature values for grammar variables 37 | 38 | (defun mk-place (v) 39 | (list 'place v)) 40 | 41 | (defun mk-code (v) 42 | (list 'code v)) 43 | 44 | (defun var-get-place (v) 45 | (second (assoc 'place v))) 46 | 47 | (defun var-get-code (v) 48 | (second (assoc 'code v))) 49 | 50 | (defun mk-2ac (op p1 p2) 51 | (wrap (list '2ac op p1 p2))) 52 | 53 | (defun mk-3ac (op p1 p2 p3) 54 | (wrap (list '3ac op p1 p2 p3))) 55 | 56 | (defun mk-2copy (p1 p2) 57 | (wrap (list '2copy p1 p2))) 58 | 59 | (defun newtemp () 60 | (gensym "t-")) ; returns a new symbol prefixed t- at run-time 61 | 62 | ;;;; LALR data 63 | 64 | (defparameter grammar 65 | '( 66 | (start --> ID COLON EQLS e END #'(lambda (ID COLON EQLS e END) (pprint-code (mk-code (append (var-get-code e) 67 | (mk-2copy (t-get-val ID) 68 | (var-get-place e))))))) 69 | (e --> e ADD te #'(lambda (e ADD te) (let ((newplace (newtemp))) 70 | (list (mk-place newplace) 71 | (mk-code (append (var-get-code e) 72 | (var-get-code te) 73 | (mk-3ac 'add newplace 74 | (var-get-place e) 75 | (var-get-place te)))))))) 76 | (e --> e SUB te #'(lambda (e SUB te) (let ((newplace (newtemp))) 77 | (list (mk-place newplace) 78 | (mk-code (append (var-get-code e) 79 | (var-get-code te) 80 | (mk-3ac 'sub newplace 81 | (var-get-place e) 82 | (var-get-place te)))))))) 83 | (e --> te #'(lambda (te) (identity te))) 84 | (te --> te MULT f #'(lambda (te MULT f) (let ((newplace (newtemp))) 85 | (list (mk-place newplace) 86 | (mk-code (append (var-get-code te) 87 | (var-get-code f) 88 | (mk-3ac 'mult newplace 89 | (var-get-place te) 90 | (var-get-place f)))))))) 91 | (te --> te DIV f #'(lambda (te DIV f) (let ((newplace (newtemp))) 92 | (list (mk-place newplace) 93 | (mk-code (append (var-get-code te) 94 | (var-get-code f) 95 | (mk-3ac 'div newplace 96 | (var-get-place te) 97 | (var-get-place f)))))))) 98 | (te --> f #'(lambda (f)(identity f))) 99 | (f --> LP e RP #'(lambda (LP e RP) (identity e))) 100 | (f --> SUB ID #'(lambda (SUB ID) (let ((newplace (newtemp))) 101 | (list (mk-place newplace) 102 | (mk-code (mk-2ac 'uminus newplace 103 | (t-get-val ID))))))) 104 | (f --> ID #'(lambda (ID) (list (mk-place (t-get-val ID)) 105 | (mk-code nil)))) 106 | )) 107 | 108 | (defparameter lexforms '(ID END COLON EQLS LP RP ADD SUB MULT DIV)) 109 | 110 | (defparameter lexicon '( 111 | (\; END) ;; all but ID goes in the lexicon 112 | (|:| COLON) 113 | (|=| EQLS) 114 | (|(| LP) 115 | (|)| RP) 116 | ($ $) ; this is for lalrparser.lisp's end of input 117 | (+ ADD) 118 | (- SUB) 119 | (* MULT) 120 | (/ DIV) 121 | )) 122 | ;; if you change the end-marker, change its hardcopy above in lexicon above as well. 123 | ;; (because LALR parser does not evaluate its lexicon symbols---sorry.) 124 | (defparameter *ENDMARKER* '$) 125 | 126 | -------------------------------------------------------------------------------- /lab-material/mips-material/codegen-examples/expr-mips/workflow.log: -------------------------------------------------------------------------------- 1 | Script started on Fri Dec 13 22:10:20 2019 2 | 3 | The default interactive shell is now zsh. 4 | To update your account to use zsh, please run `chsh -s /bin/zsh`. 5 | For more details, please visit https://support.apple.com/kb/HT208050. 6 | [?1034hexpr-mips> yalalr 7 | This is SBCL 1.5.1, an implementation of ANSI Common Lisp. 8 | More information about SBCL is available at . 9 | 10 | SBCL is free software, provided as is, with absolutely no warranty. 11 | It is mostly in the public domain; some portions are provided under 12 | BSD-style licenses. See the CREDITS and COPYING files in the 13 | distribution for more information. 14 | STYLE-WARNING: Defining (*TOPCAT*) as a constant, even though the name follows 15 | the usual naming convention (names like *FOO*) for special variables 16 |  WARNING: redefining COMMON-LISP-USER::PARSE in DEFUN 17 | 18 | =================================================== 19 | Welcome to yalalr, version 2.0 20 | an interface to LALR parser of Mark Johnson 21 | --------------------------------------------------- 22 | Ready. 23 | =================================================== 24 | lexer ok 25 | SDD ok 26 | Grammar loaded. LALR tables set. 27 | > (target-code-mips "source1") 28 | 29 | 30 | TAC code: 31 | 32 | 33 | (3AC MULT #:|t369| C D) 34 | (3AC ADD #:|t370| B #:|t369|) 35 | (2AC UMINUS #:|t371| E) 36 | (3AC ADD #:|t372| #:|t371| F) 37 | (3AC DIV #:|t373| #:|t372| 5) 38 | (3AC SUB #:|t374| #:|t370| #:|t373|) 39 | (2COPY A #:|t374|) 40 | 41 | MIPS-style code using register ops only: 42 | 43 | 44 | 45 | .data 46 | 47 | B: .word 0 48 | C: .word 0 49 | D: .word 0 50 | t369: .word 0 51 | t370: .word 0 52 | t371: .word 0 53 | E: .word 0 54 | F: .word 0 55 | t372: .word 0 56 | t373: .word 0 57 | t374: .word 0 58 | A: .word 0 59 | 60 | .text 61 | 62 | main: 63 | lw $t0,C 64 | lw $t1,D 65 | mul $t0,$t0,$t1 66 | sw $t0,t369 67 | lw $t0,B 68 | lw $t1,t369 69 | add $t0,$t0,$t1 70 | sw $t0,t370 71 | lw $t1,E 72 | sub $t0,$zero,$t1 73 | sw $t0,t371 74 | lw $t0,t371 75 | lw $t1,F 76 | add $t0,$t0,$t1 77 | sw $t0,t372 78 | lw $t0,t372 79 | li $t1,5 80 | div $t0,$t0,$t1 81 | sw $t0,t373 82 | lw $t0,t370 83 | lw $t1,t373 84 | sub $t0,$t0,$t1 85 | sw $t0,t374 86 | lw $t0,t374 87 | sw $t0,A 88 | NIL 89 | > (target-code-mips "source2") 90 | 91 | 92 | TAC code: 93 | 94 | 95 | (2AC UMINUS #:|t375| F) 96 | (3AC DIV #:|t376| #:|t375| 5) 97 | (2COPY B #:|t376|) 98 | 99 | MIPS-style code using register ops only: 100 | 101 | 102 | 103 | .data 104 | 105 | t375: .word 0 106 | F: .word 0 107 | t376: .word 0 108 | B: .word 0 109 | 110 | .text 111 | 112 | main: 113 | lw $t1,F 114 | sub $t0,$zero,$t1 115 | sw $t0,t375 116 | lw $t0,t375 117 | li $t1,5 118 | div $t0,$t0,$t1 119 | sw $t0,t376 120 | lw $t0,t376 121 | sw $t0,B 122 | NIL 123 | > (target-code-mips "source3") 124 | 125 | 126 | TAC code: 127 | 128 | 129 | (3AC MULT #:|t377| C 78.45) 130 | (3AC ADD #:|t378| B #:|t377|) 131 | (2AC UMINUS #:|t379| E) 132 | (3AC ADD #:|t380| #:|t379| F) 133 | (3AC DIV #:|t381| #:|t380| 12.5) 134 | (3AC SUB #:|t382| #:|t378| #:|t381|) 135 | (2COPY A #:|t382|) 136 | 137 | MIPS-style code using register ops only: 138 | 139 | 140 | 141 | .data 142 | 143 | B: .word 0 144 | C: .word 0 145 | t377: .word 0 146 | t378: .word 0 147 | t379: .word 0 148 | E: .word 0 149 | F: .word 0 150 | t380: .word 0 151 | t381: .word 0 152 | t382: .word 0 153 | A: .word 0 154 | 155 | .text 156 | 157 | main: 158 | lw $t0,C 159 | li $t1,78.45 160 | mul $t0,$t0,$t1 161 | sw $t0,t377 162 | lw $t0,B 163 | lw $t1,t377 164 | add $t0,$t0,$t1 165 | sw $t0,t378 166 | lw $t1,E 167 | sub $t0,$zero,$t1 168 | sw $t0,t379 169 | lw $t0,t379 170 | lw $t1,F 171 | add $t0,$t0,$t1 172 | sw $t0,t380 173 | lw $t0,t380 174 | li $t1,12.5 175 | div $t0,$t0,$t1 176 | sw $t0,t381 177 | lw $t0,t378 178 | lw $t1,t381 179 | sub $t0,$t0,$t1 180 | sw $t0,t382 181 | lw $t0,t382 182 | sw $t0,A 183 | NIL 184 | > (target-code-mips "source4") 185 | "Error before (B + C * 78.45 - ( - E + F ) / 12.5 ; $)" 186 | 187 | Script done on Fri Dec 13 22:10:42 2019 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ceng444: Language processors 2 | Middle East Technical University CENG introductory compiler course 3 | 4 | This is the website of the course when I teach it. 5 | 6 | Term: Fall 2022 (for the academic year 2022-2023) 7 | 8 | Instructor: Cem Bozsahin (Cogsci). TA: Cem Onem (CEng). 9 | 10 | Office hours: Open door except lecture days TWTh (my office is B-209 at Informatics, tel: 7758) 11 | 12 | Course hours: W 14.40-16.30, Th 15.40-17.30 Room BMB-2 (CENG building). 13 | 14 | The course is 3 lecture hours, not 4. I asked for two two-hour slots for flexibility. 15 | 16 | We will probably do 75 minutes without break each day, something like W14.40-15.55 Th15.40-16.55. 17 | 18 | If there is course clash, we can try 19 | 2+1 or 1+2 on WTh. We'll discuss this in FIRST class. 20 | 21 | **(So please attend first class, whether you are registered or not.)** 22 | 23 | Textbook: Compilers: Principles, Techniques and Tools. Aho, Lam, Sethi, Ullman (2007). Addison-Wesley/Pearson. 24 | 2nd Edition of the Dragon Book. 25 | 26 | The first edition was a classic in CS, and 2nd edition adds more to the legend. 27 | 28 | 29 | Catalog description: Formal description and classification of programming languages. Syntactic specification. The parsing problem. Top-down and bottom-up parsing. Attaching semantics to syntax. Translator writing systems. Translator writing case study. 30 | 31 | Course objectives: Assuming familiarity with formal grammars, i.e., Ceng280 material, we emphasize modern tools and techniques for compiler construction, which can be used for any task of mapping from one formal representation to another. 32 | 33 | Course prerequisite: Officially, none, according to METU catalog. Unofficially, you need to feel comfortable with 34 | programming, data structures, and formal languages. 3rd-year standing in CS, or CENG280 in the bag, or 35 | COGS501 *and* COGS502 will suffice. 36 | 37 | *Informatics Students*: Please contact me DURING REGISTRATION so that I can 38 | tell you whether you are eligible for the course, and to inform CENG department in time for them to open 39 | a quota for you. 40 | 41 | Course outline 42 | 43 |
    44 |
  1. Introduction: a walk through all stages of compiling (1 week) 45 |
  2. Scanning (lexical analysis) (1) 46 |
  3. Parsing (syntactic analysis) (3) 47 |
  4. Intermediate code (1) 48 |
  5. Virtual machines (1) 49 |
  6. Code generation (syntax-directed derivation/description---SDD) (1) 50 |
  7. Scope handling and run-time (1) 51 |
  8. A preview of compiling functional languages (2) 52 |
53 | 54 | Course conduct: 11 weeks of lecture, 2 weeks of in-class labs; 1 week in-class exam; 2 programming projects; no extra homework. 55 | 56 |

We will use TWO tools for compiler design: (1) sly.py (which is lex and yacc in python; see the bottom of this page for sly install), (2) Spike for RISC-V code generation. 57 | 58 | 59 |

In-class labs introduce sly.py and RISC-V. 60 | 61 |

We will give you a newly designed PL. You will write a compiler for it. 62 | 63 |

The first part of the project uses sly to do lexical analysis and parsing into abstract syntax trees. 64 | 65 |

The second part of the project includes code generation and execution, in 66 | RISC-V, using Spike. (We also accept LLVM, MIPS, x86 code generation; however, these 67 | you have to do without expecting too much help from us.) 68 | 69 | Grading: 70 |

    71 |
  1. Mid-term exam: %20 ( in class) 72 |
  2. mini-project 1 (lex analysis and parsing into abstract syntax trees): %25 73 |
  3. mini-project 2 (code generation and execution): %35 74 |
  4. Final exam: %20 75 |
  5. Gazozuna Kompaylır Ödülü : priceless!! 76 |
    Highest honour we give out to best successful completion of the second project. 77 |
    It is, ehm, officially recognized, 78 |
    and those who are in the know reading your CV at least in Turkey would know what you achieved. 79 |
    Usually handed by the end of first spring term after completion, with a ceremony! 80 |
    You will be a proud owner of 4 bottles of a yerli ve milli soft drink, 81 |
    with a certificate in a low-budget print, namely my handwriting. 82 |
83 | 84 | 2022-2023 Gazozuna Kompaylır ödülü: 85 |
    86 |
  • Lütfullah Erkaya: Vox -> sly -> RISC-V 87 |
88 | 89 | Tebrikler! 90 | - Cem Bozşahin, Cem Önem 91 | -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/balanced-parentheses/bpLexer.java: -------------------------------------------------------------------------------- 1 | // Generated from bp.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.Lexer; 3 | import org.antlr.v4.runtime.CharStream; 4 | import org.antlr.v4.runtime.Token; 5 | import org.antlr.v4.runtime.TokenStream; 6 | import org.antlr.v4.runtime.*; 7 | import org.antlr.v4.runtime.atn.*; 8 | import org.antlr.v4.runtime.dfa.DFA; 9 | import org.antlr.v4.runtime.misc.*; 10 | 11 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) 12 | public class bpLexer extends Lexer { 13 | static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); } 14 | 15 | protected static final DFA[] _decisionToDFA; 16 | protected static final PredictionContextCache _sharedContextCache = 17 | new PredictionContextCache(); 18 | public static final int 19 | T__0=1, T__1=2, WS=3, OP=4, NUM=5, ID=6, KEYWD=7, NEWLINE=8; 20 | public static String[] channelNames = { 21 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 22 | }; 23 | 24 | public static String[] modeNames = { 25 | "DEFAULT_MODE" 26 | }; 27 | 28 | public static final String[] ruleNames = { 29 | "T__0", "T__1", "WS", "OP", "NUM", "ID", "KEYWD", "NEWLINE" 30 | }; 31 | 32 | private static final String[] _LITERAL_NAMES = { 33 | null, "'('", "')'" 34 | }; 35 | private static final String[] _SYMBOLIC_NAMES = { 36 | null, null, null, "WS", "OP", "NUM", "ID", "KEYWD", "NEWLINE" 37 | }; 38 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 39 | 40 | /** 41 | * @deprecated Use {@link #VOCABULARY} instead. 42 | */ 43 | @Deprecated 44 | public static final String[] tokenNames; 45 | static { 46 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 47 | for (int i = 0; i < tokenNames.length; i++) { 48 | tokenNames[i] = VOCABULARY.getLiteralName(i); 49 | if (tokenNames[i] == null) { 50 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 51 | } 52 | 53 | if (tokenNames[i] == null) { 54 | tokenNames[i] = ""; 55 | } 56 | } 57 | } 58 | 59 | @Override 60 | @Deprecated 61 | public String[] getTokenNames() { 62 | return tokenNames; 63 | } 64 | 65 | @Override 66 | 67 | public Vocabulary getVocabulary() { 68 | return VOCABULARY; 69 | } 70 | 71 | 72 | public bpLexer(CharStream input) { 73 | super(input); 74 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 75 | } 76 | 77 | @Override 78 | public String getGrammarFileName() { return "bp.g4"; } 79 | 80 | @Override 81 | public String[] getRuleNames() { return ruleNames; } 82 | 83 | @Override 84 | public String getSerializedATN() { return _serializedATN; } 85 | 86 | @Override 87 | public String[] getChannelNames() { return channelNames; } 88 | 89 | @Override 90 | public String[] getModeNames() { return modeNames; } 91 | 92 | @Override 93 | public ATN getATN() { return _ATN; } 94 | 95 | public static final String _serializedATN = 96 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\n\65\b\1\4\2\t\2"+ 97 | "\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\3\2\3\2\3\3\3"+ 98 | "\3\3\4\6\4\31\n\4\r\4\16\4\32\3\4\3\4\3\5\3\5\3\6\6\6\"\n\6\r\6\16\6#"+ 99 | "\3\7\3\7\3\7\7\7)\n\7\f\7\16\7,\13\7\3\b\3\b\3\b\3\t\5\t\62\n\t\3\t\3"+ 100 | "\t\2\2\n\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\3\2\6\5\2\13\f\17\17\"\"\3"+ 101 | "\2,\61\3\2\62;\4\2C\\c|\29\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2"+ 102 | "\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\3\23\3\2\2\2\5"+ 103 | "\25\3\2\2\2\7\30\3\2\2\2\t\36\3\2\2\2\13!\3\2\2\2\r%\3\2\2\2\17-\3\2\2"+ 104 | "\2\21\61\3\2\2\2\23\24\7*\2\2\24\4\3\2\2\2\25\26\7+\2\2\26\6\3\2\2\2\27"+ 105 | "\31\t\2\2\2\30\27\3\2\2\2\31\32\3\2\2\2\32\30\3\2\2\2\32\33\3\2\2\2\33"+ 106 | "\34\3\2\2\2\34\35\b\4\2\2\35\b\3\2\2\2\36\37\t\3\2\2\37\n\3\2\2\2 \"\t"+ 107 | "\4\2\2! \3\2\2\2\"#\3\2\2\2#!\3\2\2\2#$\3\2\2\2$\f\3\2\2\2%*\t\5\2\2&"+ 108 | ")\t\5\2\2\')\5\13\6\2(&\3\2\2\2(\'\3\2\2\2),\3\2\2\2*(\3\2\2\2*+\3\2\2"+ 109 | "\2+\16\3\2\2\2,*\3\2\2\2-.\7a\2\2./\5\r\7\2/\20\3\2\2\2\60\62\7\17\2\2"+ 110 | "\61\60\3\2\2\2\61\62\3\2\2\2\62\63\3\2\2\2\63\64\7\f\2\2\64\22\3\2\2\2"+ 111 | "\b\2\32#(*\61\3\b\2\2"; 112 | public static final ATN _ATN = 113 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 114 | static { 115 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 116 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 117 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 118 | } 119 | } 120 | } -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L/lLexer.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.Lexer; 3 | import org.antlr.v4.runtime.CharStream; 4 | import org.antlr.v4.runtime.Token; 5 | import org.antlr.v4.runtime.TokenStream; 6 | import org.antlr.v4.runtime.*; 7 | import org.antlr.v4.runtime.atn.*; 8 | import org.antlr.v4.runtime.dfa.DFA; 9 | import org.antlr.v4.runtime.misc.*; 10 | 11 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) 12 | public class lLexer extends Lexer { 13 | static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); } 14 | 15 | protected static final DFA[] _decisionToDFA; 16 | protected static final PredictionContextCache _sharedContextCache = 17 | new PredictionContextCache(); 18 | public static final int 19 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, WS=9, 20 | NEWLINE=10, PL=11; 21 | public static String[] channelNames = { 22 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 23 | }; 24 | 25 | public static String[] modeNames = { 26 | "DEFAULT_MODE" 27 | }; 28 | 29 | public static final String[] ruleNames = { 30 | "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "WS", 31 | "NEWLINE", "PL" 32 | }; 33 | 34 | private static final String[] _LITERAL_NAMES = { 35 | null, "'$'", "'='", "'=>'", "'('", "')'", "'~'", "'0'", "'1'" 36 | }; 37 | private static final String[] _SYMBOLIC_NAMES = { 38 | null, null, null, null, null, null, null, null, null, "WS", "NEWLINE", 39 | "PL" 40 | }; 41 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 42 | 43 | /** 44 | * @deprecated Use {@link #VOCABULARY} instead. 45 | */ 46 | @Deprecated 47 | public static final String[] tokenNames; 48 | static { 49 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 50 | for (int i = 0; i < tokenNames.length; i++) { 51 | tokenNames[i] = VOCABULARY.getLiteralName(i); 52 | if (tokenNames[i] == null) { 53 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 54 | } 55 | 56 | if (tokenNames[i] == null) { 57 | tokenNames[i] = ""; 58 | } 59 | } 60 | } 61 | 62 | @Override 63 | @Deprecated 64 | public String[] getTokenNames() { 65 | return tokenNames; 66 | } 67 | 68 | @Override 69 | 70 | public Vocabulary getVocabulary() { 71 | return VOCABULARY; 72 | } 73 | 74 | 75 | public lLexer(CharStream input) { 76 | super(input); 77 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 78 | } 79 | 80 | @Override 81 | public String getGrammarFileName() { return "l.g4"; } 82 | 83 | @Override 84 | public String[] getRuleNames() { return ruleNames; } 85 | 86 | @Override 87 | public String getSerializedATN() { return _serializedATN; } 88 | 89 | @Override 90 | public String[] getChannelNames() { return channelNames; } 91 | 92 | @Override 93 | public String[] getModeNames() { return modeNames; } 94 | 95 | @Override 96 | public ATN getATN() { return _ATN; } 97 | 98 | public static final String _serializedATN = 99 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\r8\b\1\4\2\t\2\4"+ 100 | "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+ 101 | "\13\4\f\t\f\3\2\3\2\3\3\3\3\3\4\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3"+ 102 | "\b\3\t\3\t\3\n\6\n,\n\n\r\n\16\n-\3\n\3\n\3\13\5\13\63\n\13\3\13\3\13"+ 103 | "\3\f\3\f\2\2\r\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\3\2"+ 104 | "\4\5\2\13\f\17\17\"\"\4\2C\\c|\29\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2"+ 105 | "\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3"+ 106 | "\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\3\31\3\2\2\2\5\33\3\2\2\2\7\35\3\2\2"+ 107 | "\2\t \3\2\2\2\13\"\3\2\2\2\r$\3\2\2\2\17&\3\2\2\2\21(\3\2\2\2\23+\3\2"+ 108 | "\2\2\25\62\3\2\2\2\27\66\3\2\2\2\31\32\7&\2\2\32\4\3\2\2\2\33\34\7?\2"+ 109 | "\2\34\6\3\2\2\2\35\36\7?\2\2\36\37\7@\2\2\37\b\3\2\2\2 !\7*\2\2!\n\3\2"+ 110 | "\2\2\"#\7+\2\2#\f\3\2\2\2$%\7\u0080\2\2%\16\3\2\2\2&\'\7\62\2\2\'\20\3"+ 111 | "\2\2\2()\7\63\2\2)\22\3\2\2\2*,\t\2\2\2+*\3\2\2\2,-\3\2\2\2-+\3\2\2\2"+ 112 | "-.\3\2\2\2./\3\2\2\2/\60\b\n\2\2\60\24\3\2\2\2\61\63\7\17\2\2\62\61\3"+ 113 | "\2\2\2\62\63\3\2\2\2\63\64\3\2\2\2\64\65\7\f\2\2\65\26\3\2\2\2\66\67\t"+ 114 | "\3\2\2\67\30\3\2\2\2\5\2-\62\3\b\2\2"; 115 | public static final ATN _ATN = 116 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 117 | static { 118 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 119 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 120 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /lab-material/old_material/antLR-material/language-L-bad-trees/lLexer.java: -------------------------------------------------------------------------------- 1 | // Generated from l.g4 by ANTLR 4.7.1 2 | import org.antlr.v4.runtime.Lexer; 3 | import org.antlr.v4.runtime.CharStream; 4 | import org.antlr.v4.runtime.Token; 5 | import org.antlr.v4.runtime.TokenStream; 6 | import org.antlr.v4.runtime.*; 7 | import org.antlr.v4.runtime.atn.*; 8 | import org.antlr.v4.runtime.dfa.DFA; 9 | import org.antlr.v4.runtime.misc.*; 10 | 11 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) 12 | public class lLexer extends Lexer { 13 | static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); } 14 | 15 | protected static final DFA[] _decisionToDFA; 16 | protected static final PredictionContextCache _sharedContextCache = 17 | new PredictionContextCache(); 18 | public static final int 19 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, WS=9, 20 | NEWLINE=10, PL=11; 21 | public static String[] channelNames = { 22 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 23 | }; 24 | 25 | public static String[] modeNames = { 26 | "DEFAULT_MODE" 27 | }; 28 | 29 | public static final String[] ruleNames = { 30 | "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "WS", 31 | "NEWLINE", "PL" 32 | }; 33 | 34 | private static final String[] _LITERAL_NAMES = { 35 | null, "'$'", "'='", "'=>'", "'('", "')'", "'~'", "'0'", "'1'" 36 | }; 37 | private static final String[] _SYMBOLIC_NAMES = { 38 | null, null, null, null, null, null, null, null, null, "WS", "NEWLINE", 39 | "PL" 40 | }; 41 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 42 | 43 | /** 44 | * @deprecated Use {@link #VOCABULARY} instead. 45 | */ 46 | @Deprecated 47 | public static final String[] tokenNames; 48 | static { 49 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 50 | for (int i = 0; i < tokenNames.length; i++) { 51 | tokenNames[i] = VOCABULARY.getLiteralName(i); 52 | if (tokenNames[i] == null) { 53 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 54 | } 55 | 56 | if (tokenNames[i] == null) { 57 | tokenNames[i] = ""; 58 | } 59 | } 60 | } 61 | 62 | @Override 63 | @Deprecated 64 | public String[] getTokenNames() { 65 | return tokenNames; 66 | } 67 | 68 | @Override 69 | 70 | public Vocabulary getVocabulary() { 71 | return VOCABULARY; 72 | } 73 | 74 | 75 | public lLexer(CharStream input) { 76 | super(input); 77 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 78 | } 79 | 80 | @Override 81 | public String getGrammarFileName() { return "l.g4"; } 82 | 83 | @Override 84 | public String[] getRuleNames() { return ruleNames; } 85 | 86 | @Override 87 | public String getSerializedATN() { return _serializedATN; } 88 | 89 | @Override 90 | public String[] getChannelNames() { return channelNames; } 91 | 92 | @Override 93 | public String[] getModeNames() { return modeNames; } 94 | 95 | @Override 96 | public ATN getATN() { return _ATN; } 97 | 98 | public static final String _serializedATN = 99 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\r8\b\1\4\2\t\2\4"+ 100 | "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+ 101 | "\13\4\f\t\f\3\2\3\2\3\3\3\3\3\4\3\4\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\b\3"+ 102 | "\b\3\t\3\t\3\n\6\n,\n\n\r\n\16\n-\3\n\3\n\3\13\5\13\63\n\13\3\13\3\13"+ 103 | "\3\f\3\f\2\2\r\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\3\2"+ 104 | "\4\5\2\13\f\17\17\"\"\4\2C\\c|\29\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2"+ 105 | "\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3"+ 106 | "\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\3\31\3\2\2\2\5\33\3\2\2\2\7\35\3\2\2"+ 107 | "\2\t \3\2\2\2\13\"\3\2\2\2\r$\3\2\2\2\17&\3\2\2\2\21(\3\2\2\2\23+\3\2"+ 108 | "\2\2\25\62\3\2\2\2\27\66\3\2\2\2\31\32\7&\2\2\32\4\3\2\2\2\33\34\7?\2"+ 109 | "\2\34\6\3\2\2\2\35\36\7?\2\2\36\37\7@\2\2\37\b\3\2\2\2 !\7*\2\2!\n\3\2"+ 110 | "\2\2\"#\7+\2\2#\f\3\2\2\2$%\7\u0080\2\2%\16\3\2\2\2&\'\7\62\2\2\'\20\3"+ 111 | "\2\2\2()\7\63\2\2)\22\3\2\2\2*,\t\2\2\2+*\3\2\2\2,-\3\2\2\2-+\3\2\2\2"+ 112 | "-.\3\2\2\2./\3\2\2\2/\60\b\n\2\2\60\24\3\2\2\2\61\63\7\17\2\2\62\61\3"+ 113 | "\2\2\2\62\63\3\2\2\2\63\64\3\2\2\2\64\65\7\f\2\2\65\26\3\2\2\2\66\67\t"+ 114 | "\3\2\2\67\30\3\2\2\2\5\2-\62\3\b\2\2"; 115 | public static final ATN _ATN = 116 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 117 | static { 118 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 119 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 120 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 121 | } 122 | } 123 | } -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test.src: -------------------------------------------------------------------------------- 1 | % First Monadic Grammar with all grammar patterns covered. 2 | % -Cem Bozsahin, March 2022 3 | 4 | 5 | |it is more | n :: xp[typ=x] : it; % NB. expletive it for subject's type 6 | |john | n :: np[agr=?x, num=sg] : john; 7 | |mary | n :: np : mary; 8 | 9 | |study | inf :: iv : \x.study x <17, 1.27>; % last bit is optional for grammarians 10 | |persuaded | v :: (s[type=decl]\np[det=none, h=?x])/vp[h=?x]/np : \x.\p.\y.persuade (p x) x y; 11 | |promised | v :: (s\np)/vp/np : \x\p\y.promise (p y) x y; % lambdas can be grouped 12 | |wanted | v :: (s\np)/.vp/np : \x\p\y.want (p x) y; 13 | |expected | v :: (s\.np)/^vp/+np : \x\p\y.expect (p x) y <21, 2.8>; 14 | |considered | v :: (s\np)//propp/np: \x\p\y.consider (p x) y; 15 | |seemed | v :: (s\'it is less')/s : \p\x.seem p; 16 | |seemed | v :: (s\"it is less")/s : \p\x.seem p; 17 | |seemed | v :: (s\\np)/*vp : \p\x.seem (p x); 18 | |and | c :: (@x\@x)/@x : \p\q\x.and (p x) (q x); 19 | |boldly | j :: (s\np)/(s[o=kirk, s=?y]\np) : \p\x.boldly (p x); 20 | 21 | 22 | 23 | |to | p :: vp/iv : \p.p; 24 | |have | aux :: iv/iv : \p.p; 25 | |bought | v :: iv/np : \x\y.buy x y; % this one's for perfective have/had bought 26 | % Cf. the relational rule down below for bare/tensed form 27 | 28 | |the | det :: np/*n : def; 29 | |car | n :: n : car; 30 | |handsome | p :: propp : \x.handsome x; 31 | 32 | |kicked the bucked | idio :: s\np :\x.die_euphemistic x; % frozen expression 33 | |kicked | v :: (s\np)/'bucket'/PredP : \p\x\y.die_ (euphemistic p x) y; % not so frozen expression 34 | |pick up | pv :: iv/np : \x\y.pick_culminate x y ; % phrasal verb. All POSs are up to you. 35 | |pick | pv2 :: iv/'up'/np : \x\y\z.hold (culminate y) x z ; % separable phrasal verb 36 | 37 | % relational rules (as opposed to combining rules) 38 | 39 | #past (run, iv:\x.run x) <--> (ran, s\np:\x.past run x); % a symmetric rule 40 | #subj (np : lt) --> (s/(s\np):\lt\p.p lt) ; % an asymmetric rule 41 | 42 | % <--> means these two are related During parsing, we pick the one in surface form. 43 | % --> means the surface string bearing the category on the lhs ALSO 44 | % has the category on the rhs in parsing. 45 | 46 | % In --> we must take the whole lambda term (lt) in the lhs as first input 47 | % on the rhs and restructure by reductions on the rhs. 48 | % Otherwise we need pattern matching (yikes). 49 | 50 | % This can be done since every item in lt 51 | % is known, per rule. For example, the following example is from 52 | % Turkish, turning adjectives to nouns (Lewis 1967), 53 | % mapping input lambda term \p\x.and(p x)(nompred x) to 54 | % \x.and(nompred x)(nompred x). 55 | #lewis-rule (np/np : lt) --> (np : \lt.lt nompred) ; 56 | % example: zengin adam `rich man', zengin: `the rich' 57 | % it is asymmetric: 'Mehmet' but *'Mehmet adam' 58 | 59 | 60 | #past (buy, iv/np:\x\y.buy x y) <--> (bought, (s\np)/np:\x\y.past buy x y) ; 61 | 62 | % NB. rule name is same as run <--> ran. Useful 63 | % (in fact essential) for capturing morphological 64 | % paradigms, Greg Stump-style. 65 | % Note however that these paradigms are categorial, in this example 66 | % across verbal categories. 67 | 68 | % To lexical rule aficionados: these are not lexical 69 | % rules because they do not necessarily work on 70 | % lexical forms to produce lexical forms. 71 | % NB. There is no POS tag on either rule type. 72 | % We don't use the L-word in Monadic Grammar. 73 | % All you have is elements of grammar. 74 | 75 | % I won't offer a universal POS tag set after having written a book 76 | % on linguistic diversity. 77 | % Nothing in monadic grammar depends on universal set of POS tags or universal set of basic categories. 78 | % There is no synthetic notion that is necessary. 79 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world-bad.src: -------------------------------------------------------------------------------- 1 | % First Monadic Grammar with all grammar patterns covered. 2 | % -Cem Bozsahin, March 2022 3 | 4 | % - The stuff before '::' is the element of grammar with its POS defined after '| '. 5 | % It can be a multi-word expression, subword element, intonation, pitch accent etc. 6 | % It can also be a serialized sign pattern; in fact, any phonological value that is worth a category. 7 | % - The stuff after '::' is the category. 8 | % - '%' and anything up to end of line is considered a comment. 9 | % - Whitespacing does not matter. 10 | % - Every entry must be line-terminated. If they are long, let them be one long line. 11 | 12 | |it | n :: xp : it; % NB. expletive it for subject's type 13 | |john | n :: np : john; 14 | |mary | n :: np : mary 15 | 16 | |study | inf :: iv : \x.study x; 17 | |persuaded | v :: (s\np)/vp/np : \x.\p.\y.persuade (p x) x y; 18 | |promised | v :: (s\np)/vp/np \x\p\y.promise (p y) x y; % lambdas can be grouped 19 | |wanted | v :: (s\np)/vp/np : \x\p\y.want (p x) y; 20 | |expected | v :: (s\np)/vp/np : \x\p\y.expect (p x) y; 21 | |considered | v :: (s\np)/propp/np: \x\p\y.consider (p x) y; 22 | |seemed | v :: (s\xp)/s : p\x.seem p; 23 | |seemed | v :: (s\np)/vp : \p\x.seem (p x); 24 | 25 | |to | p :: vp/iv : \p.p; 26 | |have | aux :: iv/iv : \p.p; 27 | |bought | v :: iv/np : \x\y.buy x y; % this one's for perfective have/had bought 28 | % Cf. the relational rule down below for bare/tensed form 29 | 30 | |the | det :: np/*n : def 31 | |car n :: n : car; 32 | |handsome | p propp : \x.handsome x; 33 | 34 | |kicked the bucked | idio :: s\np :\x.die_euphemistic x; % frozen expression 35 | |kicked | v :: (s\np)/'bucket'/PredP : \p\x\y.die_ (euphemistic p x) y; % not so frozen expression 36 | |pick up | pv :: iv/np : \x\y.pick_culminate x y ; % phrasal verb. All POSs are up to you. 37 | |pick | pv2 :: iv/'up'/np : \x\y\z.hold (culminate y) x z ; % separable phrasal verb 38 | 39 | % relational rules (as opposed to combining rules) 40 | 41 | #past (run, iv:\x.run x) <--> ran, s\np:\x.past run x); % a symmetric rule 42 | #subj (np : lt) -> (s/(s\np):\lt\p.p lt) ; % an asymmetric rule 43 | 44 | % <--> means these two are related During parsing, we pick the one in surface form. 45 | % --> means the surface string bearing the category on the lhs ALSO 46 | % has the category on the rhs in parsing. 47 | 48 | % In --> we must take the whole lambda term (lt) in the lhs as first input 49 | % on the rhs and restructure by reductions on the rhs. 50 | % Otherwise we need pattern matching (yikes). 51 | 52 | % This can be done since every item in lt 53 | % is known, per rule. For example, the following example is from 54 | % Turkish, turning adjectives to nouns (Lewis 1967), 55 | % mapping input lambda term \p\x.and(p x)(nompred x) to 56 | % \x.and(nompred x)(nompred x). 57 | #lewis-rule (np/np : lt) --> (np : \lt.lt nompred) ; 58 | % example: zengin adam `rich man', zengin: `the rich' 59 | % it is asymmetric: 'Mehmet' but *'Mehmet adam' 60 | 61 | 62 | #past (buy, iv/np:\x\y.buy x y) <--> (bought, (s\np)/np:\x\y.past buy x y) ; 63 | 64 | % NB. rule name is same as run <--> ran. Useful 65 | % (in fact essential) for capturing morphological 66 | % paradigms, Greg Stump-style. 67 | % Note however that these paradigms are categorial, in this example 68 | % across verbal categories. 69 | 70 | % To lexical rule aficionados: these are not lexical 71 | % rules because they do not necessarily work on 72 | % lexical forms to produce lexical forms. 73 | % NB. There is no POS tag on either rule type. 74 | % We don't use the L-word in Monadic Grammar. 75 | % All you have is elements of grammar. 76 | 77 | % I won't offer a universal POS tag set after having written a book 78 | % on linguistic diversity. 79 | % Nothing in monadic grammar depends on universal set of POS tags or universal set of basic categories. 80 | % There is no synthetic notion that is necessary. 81 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world.src: -------------------------------------------------------------------------------- 1 | % First Monadic Grammar with all grammar patterns covered. 2 | % -Cem Bozsahin, March 2022 3 | 4 | % - The stuff sandwhiched as |..| before '::' is the element of grammar. POS tag is defined before '::' 5 | % An element can be a multi-word expression, subword element, intonation, pitch accent etc. 6 | % It can also be a serialized sign pattern; in fact, any phonological value that is worth a category. 7 | % - The stuff after '::' is the category. 8 | % - Relational rule entries (symmetric and asymmetric) start with the rule name, prefixed by #. 9 | % - '%' and anything up to end of line is considered a comment. 10 | % - Every entry must start on a new line, and must be line-terminated. If they are long, let them be one long line. 11 | % - Information part of every entry must be terminated by ';' (i.e. before any in-line commenting on the right) 12 | % - Whitespacing does not matter except in quotes. 13 | 14 | |it | n :: xp[lex=no,per=s3] : it; % NB. expletive it for subject's type 15 | |john | n :: np[per=3s,lex=yes] : john; 16 | |mary | n :: np : mary; 17 | 18 | |and | c :: @x/(@x\@x) : \p\q\x. and (p x) (q x); % syncategorematic 19 | 20 | |study | inf :: iv : \x.study x; 21 | |persuaded | v :: (s\np)/vp/+np : \x.\p.\y.persuade (p x) x y; 22 | |promised | v :: (s\\ np)/vp//np : \x\p\y.promise (p y) x y; % lambdas can be grouped 23 | |wanted | v :: (s\*np)/^vp/.np : \x\p\y.want (p x) y; 24 | |expected | v :: (s\np)/vp/np : \x\p\y.expect (p x) y; 25 | |considered | v :: (s\np)/propp/np: \x\p\y.consider (p x) y; 26 | |seemed | v :: (s\xp)/s : \p\x.seem p; 27 | |seemed | v :: (s\np)/vp : \p\x.seem (p x); 28 | 29 | |to | p :: vp/iv : \p.p; 30 | |have | aux :: iv/iv : \p.p; 31 | |bought | v :: iv/np : \x\y.buy x y; % this one's for perfective have/had bought 32 | % Cf. the relational rule down below for bare/tensed form 33 | 34 | |the | det :: np/*n : def; 35 | |car | n :: n : car; 36 | |handsome | p :: propp : \x.handsome x; 37 | 38 | |kicked the bucked | idio :: s\np :\x.die_euphemistic x; % frozen expression 39 | |kicked | v :: (s\np)/'the bucket'/PredP : \p\x\y.die_ (euphemistic p x) y; % not so frozen expression 40 | |pick up | pv :: iv/np : \x\y.pick_culminate x y ; % phrasal verb. All POSs are up to you. 41 | |pick | pv2 :: iv/'up'/np : \x\y\z.hold (culminate y) x z ; % separable phrasal verb 42 | 43 | % relational rules (as opposed to combining rules) 44 | 45 | #past ( run a mile, iv:\x.run x) <--> ( km, s\np:\x.past run x); % a symmetric rule 46 | #subj (np : lt) --> (s/(s\np):\lt\p.p lt) ; % an asymmetric rule 47 | 48 | % <--> means these two are related During parsing, we pick the one in surface form. 49 | % --> means the surface string bearing the category on the lhs ALSO 50 | % has the category on the rhs in parsing. 51 | 52 | % In --> we must take the whole lambda term (lt) in the lhs as first input 53 | % on the rhs and restructure by reductions on the rhs. 54 | % Otherwise we need pattern matching (yikes). 55 | 56 | % This can be done since every item in lt 57 | % is known, per rule. For example, the following example is from 58 | % Turkish, turning adjectives to nouns (Lewis 1967), 59 | % mapping input lambda term \p\x.and(p x)(nompred x) to 60 | % \x.and(nompred x)(nompred x). 61 | #lewis-rule (np/np : lt) --> (np : \lt.lt nompred) ; 62 | % example: zengin adam `rich man', zengin: `the rich' 63 | % it is asymmetric: 'Mehmet' but *'Mehmet adam' 64 | 65 | 66 | #past (buy, iv/np:\x\y.buy x y) <--> (bought something, (s\np)/np:\x\y.past buy x y) ; 67 | 68 | % NB. rule name is same as run <--> ran. Useful 69 | % (in fact essential) for capturing morphological 70 | % paradigms, Greg Stump-style. 71 | % Note however that these paradigms are categorial, in this example 72 | % across verbal categories. 73 | 74 | % To lexical rule aficionados: these are not lexical 75 | % rules because they do not necessarily work on 76 | % lexical forms to produce lexical forms. 77 | % NB. There is no POS tag on either rule type. 78 | % We don't use the L-word in Monadic Grammar. 79 | % All you have is elements of grammar. 80 | 81 | % I won't offer a universal POS tag set after having written a book 82 | % on linguistic diversity. 83 | % Nothing in monadic grammar depends on universal set of POS tags or universal set of basic categories. 84 | % There is no synthetic notion that is necessary. 85 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world.tc: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from hello-world.tc October 07, 2022, 11:03:40 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 201535)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 954999)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 230030)(PARAM 1.0)(PHON it) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (lex no)(per s3))))(SEM it) 21 | ) 22 | ( 23 | (KEY 161028)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (per 3s)(lex yes))))(SEM john) 25 | ) 26 | ( 27 | (KEY 500495)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 268140)(PARAM 1.0)(PHON and) 32 | (MORPH c)(SYN (((BCAT @x)special)(DIR FS)(MODAL ALL)(((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 33 | ) 34 | ( 35 | (KEY 363373)(PARAM 1.0)(PHON study) 36 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 37 | ) 38 | ( 39 | (KEY 326489)(PARAM 1.0)(PHON persuaded) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 41 | ) 42 | ( 43 | (KEY 654614)(PARAM 1.0)(PHON promised) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 45 | ) 46 | ( 47 | (KEY 776926)(PARAM 1.0)(PHON wanted) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL STAR)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 816684)(PARAM 1.0)(PHON expected) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 48365)(PARAM 1.0)(PHON considered) 56 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 57 | ) 58 | ( 59 | (KEY 975021)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT xp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 61 | ) 62 | ( 63 | (KEY 35841)(PARAM 1.0)(PHON seemed) 64 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 65 | ) 66 | ( 67 | (KEY 627789)(PARAM 1.0)(PHON to) 68 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 69 | ) 70 | ( 71 | (KEY 904595)(PARAM 1.0)(PHON have) 72 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 73 | ) 74 | ( 75 | (KEY 569723)(PARAM 1.0)(PHON bought) 76 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 77 | ) 78 | ( 79 | (KEY 535736)(PARAM 1.0)(PHON the) 80 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 81 | ) 82 | ( 83 | (KEY 136308)(PARAM 1.0)(PHON car) 84 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 85 | ) 86 | ( 87 | (KEY 846581)(PARAM 1.0)(PHON handsome) 88 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 89 | ) 90 | ( 91 | (KEY 89290)(PARAM 1.0)(PHON kicked the bucked) 92 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 93 | ) 94 | ( 95 | (KEY 147038)(PARAM 1.0)(PHON kicked) 96 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (the bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 97 | ) 98 | ( 99 | (KEY 560700)(PARAM 1.0)(PHON pick up) 100 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 101 | ) 102 | ( 103 | (KEY 948611)(PARAM 1.0)(PHON pick) 104 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 105 | ) 106 | ( 107 | (KEY 37827)(PARAM 1.0)(PHON run a mile) 108 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 109 | ) 110 | ( 111 | (KEY 554538)(PARAM 1.0)(PHON km) 112 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 113 | ) 114 | ( 115 | (KEY 210342)(PARAM 1.0)(PHON buy) 116 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 117 | ) 118 | ( 119 | (KEY 28601)(PARAM 1.0)(PHON bought something) 120 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 121 | ) 122 | ;; 123 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 124 | ) 125 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/hello-world.tc.lisp: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from hello-world.tc October 07, 2022, 11:03:40 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 201535)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 954999)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 230030)(PARAM 1.0)(PHON it) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (lex no)(per s3))))(SEM it) 21 | ) 22 | ( 23 | (KEY 161028)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (per 3s)(lex yes))))(SEM john) 25 | ) 26 | ( 27 | (KEY 500495)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 268140)(PARAM 1.0)(PHON and) 32 | (MORPH c)(SYN (((BCAT @x)special)(DIR FS)(MODAL ALL)(((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 33 | ) 34 | ( 35 | (KEY 363373)(PARAM 1.0)(PHON study) 36 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 37 | ) 38 | ( 39 | (KEY 326489)(PARAM 1.0)(PHON persuaded) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 41 | ) 42 | ( 43 | (KEY 654614)(PARAM 1.0)(PHON promised) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 45 | ) 46 | ( 47 | (KEY 776926)(PARAM 1.0)(PHON wanted) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL STAR)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 816684)(PARAM 1.0)(PHON expected) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 48365)(PARAM 1.0)(PHON considered) 56 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 57 | ) 58 | ( 59 | (KEY 975021)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT xp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 61 | ) 62 | ( 63 | (KEY 35841)(PARAM 1.0)(PHON seemed) 64 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 65 | ) 66 | ( 67 | (KEY 627789)(PARAM 1.0)(PHON to) 68 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 69 | ) 70 | ( 71 | (KEY 904595)(PARAM 1.0)(PHON have) 72 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 73 | ) 74 | ( 75 | (KEY 569723)(PARAM 1.0)(PHON bought) 76 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 77 | ) 78 | ( 79 | (KEY 535736)(PARAM 1.0)(PHON the) 80 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 81 | ) 82 | ( 83 | (KEY 136308)(PARAM 1.0)(PHON car) 84 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 85 | ) 86 | ( 87 | (KEY 846581)(PARAM 1.0)(PHON handsome) 88 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 89 | ) 90 | ( 91 | (KEY 89290)(PARAM 1.0)(PHON kicked the bucked) 92 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 93 | ) 94 | ( 95 | (KEY 147038)(PARAM 1.0)(PHON kicked) 96 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (the bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 97 | ) 98 | ( 99 | (KEY 560700)(PARAM 1.0)(PHON pick up) 100 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 101 | ) 102 | ( 103 | (KEY 948611)(PARAM 1.0)(PHON pick) 104 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 105 | ) 106 | ( 107 | (KEY 37827)(PARAM 1.0)(PHON run a mile) 108 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 109 | ) 110 | ( 111 | (KEY 554538)(PARAM 1.0)(PHON km) 112 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 113 | ) 114 | ( 115 | (KEY 210342)(PARAM 1.0)(PHON buy) 116 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 117 | ) 118 | ( 119 | (KEY 28601)(PARAM 1.0)(PHON bought something) 120 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 121 | ) 122 | ;; 123 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 124 | ) 125 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test2.tc: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from acid-test2.tc October 07, 2022, 12:11:19 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 575660)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 385)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 66866)(PARAM 1.0)(PHON it is more) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (typ x))))(SEM it) 21 | ) 22 | ( 23 | (KEY 891443)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (agr ?x)(num sg))))(SEM john) 25 | ) 26 | ( 27 | (KEY 455944)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 17)(PARAM 1.27)(PHON study) 32 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 33 | ) 34 | ( 35 | (KEY 803681)(PARAM 1.0)(PHON persuaded) 36 | (MORPH v)(SYN (((((BCAT s)(FEATS (type decl)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS (det none)(h ?x))))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS (h ?x))))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 37 | ) 38 | ( 39 | (KEY 330452)(PARAM 1.0)(PHON promised) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 41 | ) 42 | ( 43 | (KEY 524672)(PARAM 1.0)(PHON wanted) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 45 | ) 46 | ( 47 | (KEY 21)(PARAM 2.8)(PHON expected) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 713195)(PARAM 1.0)(PHON considered) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 602858)(PARAM 1.0)(PHON seemed) 56 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 57 | ) 58 | ( 59 | (KEY 136174)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL STAR)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 61 | ) 62 | ( 63 | (KEY 220906)(PARAM 1.0)(PHON and) 64 | (MORPH c)(SYN ((((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))(DIR FS)(MODAL ALL)((BCAT @x)special)))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 65 | ) 66 | ( 67 | (KEY 925746)(PARAM 1.0)(PHON boldly) 68 | (MORPH j)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS (o kirk)(s ?y)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(SEM (LAM p (LAM x (boldly (p x))))) 69 | ) 70 | ( 71 | (KEY 636524)(PARAM 1.0)(PHON to) 72 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 73 | ) 74 | ( 75 | (KEY 563112)(PARAM 1.0)(PHON have) 76 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 77 | ) 78 | ( 79 | (KEY 903945)(PARAM 1.0)(PHON bought) 80 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 81 | ) 82 | ( 83 | (KEY 574974)(PARAM 1.0)(PHON the) 84 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 85 | ) 86 | ( 87 | (KEY 270679)(PARAM 1.0)(PHON car) 88 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 89 | ) 90 | ( 91 | (KEY 347363)(PARAM 1.0)(PHON handsome) 92 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 93 | ) 94 | ( 95 | (KEY 795757)(PARAM 1.0)(PHON kicked the bucked) 96 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 97 | ) 98 | ( 99 | (KEY 566088)(PARAM 1.0)(PHON kicked) 100 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 101 | ) 102 | ( 103 | (KEY 319026)(PARAM 1.0)(PHON pick up) 104 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 105 | ) 106 | ( 107 | (KEY 907008)(PARAM 1.0)(PHON pick) 108 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 109 | ) 110 | ( 111 | (KEY 138467)(PARAM 1.0)(PHON run) 112 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 113 | ) 114 | ( 115 | (KEY 811382)(PARAM 1.0)(PHON ran) 116 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 117 | ) 118 | ( 119 | (KEY 529659)(PARAM 1.0)(PHON buy) 120 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 121 | ) 122 | ( 123 | (KEY 606295)(PARAM 1.0)(PHON bought) 124 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 125 | ) 126 | ;; 127 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 128 | ) 129 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test2.tc.lisp: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from acid-test2.tc October 07, 2022, 11:05:00 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 575660)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 385)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 66866)(PARAM 1.0)(PHON it is more) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (typ x))))(SEM it) 21 | ) 22 | ( 23 | (KEY 891443)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (agr ?x)(num sg))))(SEM john) 25 | ) 26 | ( 27 | (KEY 455944)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 17)(PARAM 1.27)(PHON study) 32 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 33 | ) 34 | ( 35 | (KEY 803681)(PARAM 1.0)(PHON persuaded) 36 | (MORPH v)(SYN (((((BCAT s)(FEATS (type decl)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS (det none)(h ?x))))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS (h ?x))))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 37 | ) 38 | ( 39 | (KEY 330452)(PARAM 1.0)(PHON promised) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 41 | ) 42 | ( 43 | (KEY 524672)(PARAM 1.0)(PHON wanted) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 45 | ) 46 | ( 47 | (KEY 21)(PARAM 2.8)(PHON expected) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 713195)(PARAM 1.0)(PHON considered) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 602858)(PARAM 1.0)(PHON seemed) 56 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 57 | ) 58 | ( 59 | (KEY 136174)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL STAR)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 61 | ) 62 | ( 63 | (KEY 220906)(PARAM 1.0)(PHON and) 64 | (MORPH c)(SYN ((((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))(DIR FS)(MODAL ALL)((BCAT @x)special)))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 65 | ) 66 | ( 67 | (KEY 925746)(PARAM 1.0)(PHON boldly) 68 | (MORPH j)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS (o kirk)(s ?y)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(SEM (LAM p (LAM x (boldly (p x))))) 69 | ) 70 | ( 71 | (KEY 636524)(PARAM 1.0)(PHON to) 72 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 73 | ) 74 | ( 75 | (KEY 563112)(PARAM 1.0)(PHON have) 76 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 77 | ) 78 | ( 79 | (KEY 903945)(PARAM 1.0)(PHON bought) 80 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 81 | ) 82 | ( 83 | (KEY 574974)(PARAM 1.0)(PHON the) 84 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 85 | ) 86 | ( 87 | (KEY 270679)(PARAM 1.0)(PHON car) 88 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 89 | ) 90 | ( 91 | (KEY 347363)(PARAM 1.0)(PHON handsome) 92 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 93 | ) 94 | ( 95 | (KEY 795757)(PARAM 1.0)(PHON kicked the bucked) 96 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 97 | ) 98 | ( 99 | (KEY 566088)(PARAM 1.0)(PHON kicked) 100 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 101 | ) 102 | ( 103 | (KEY 319026)(PARAM 1.0)(PHON pick up) 104 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 105 | ) 106 | ( 107 | (KEY 907008)(PARAM 1.0)(PHON pick) 108 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 109 | ) 110 | ( 111 | (KEY 138467)(PARAM 1.0)(PHON run) 112 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 113 | ) 114 | ( 115 | (KEY 877110)(PARAM 1.0)(PHON ran) 116 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 117 | ) 118 | ( 119 | (KEY 529659)(PARAM 1.0)(PHON buy) 120 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 121 | ) 122 | ( 123 | (KEY 752727)(PARAM 1.0)(PHON bought) 124 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 125 | ) 126 | ;; 127 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 128 | ) 129 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test2.src: -------------------------------------------------------------------------------- 1 | % First Monadic Grammar with all grammar patterns covered. 2 | % -Cem Bozsahin, March 2022 3 | 4 | % - The stuff before '::' is the element of grammar with its POS defined after '| '. 5 | % It can be a multi-word expression, subword element, intonation, pitch accent etc. 6 | % It can also be a serialized sign pattern; in fact, any phonological value that is worth a category. 7 | % - The stuff after '::' is the category. 8 | % - Relational rule entries (symmetric and asymmetric) start with the rule name, prefixed by #. 9 | % - '%' and anything up to end of line is considered a comment. 10 | % - Every entry must start on a new line, and must be line-terminated. If they are long, let them be one long line. 11 | % - Information part of every entry must be terminated by ';' (i.e. before in-line commenting on the right) 12 | % - Whitespacing does not matter. 13 | 14 | |it is more | n :: xp[typ=x] : it <66866 , 1.0>; % NB. expletive it for subject's type 15 | |john | n :: np[agr=?x, num=sg] : john <891443 , 1.0>; 16 | |mary | n :: np : mary <455944 , 1.0>; 17 | 18 | |study | inf :: iv : \x.study x <17, 1.27>; % last bit is optional for grammarians 19 | |persuaded | v :: (s[type=decl]\np[det=none, h=?x])/vp[h=?x]/np : \x.\p.\y.persuade (p x) x y <803681 , 1.0>; 20 | |promised | v :: (s\np)/vp/np : \x\p\y.promise (p y) x y <330452 , 1.0>; % lambdas can be grouped 21 | |wanted | v :: (s\np)/.vp/np : \x\p\y.want (p x) y <524672 , 1.0>; 22 | |expected | v :: (s\.np)/^vp/+np : \x\p\y.expect (p x) y <21, 2.8>; 23 | |considered | v :: (s\np)//propp/np: \x\p\y.consider (p x) y <713195 , 1.0>; 24 | |seemed | v :: (s\'it is less')/s : \p\x.seem p <602858 , 1.0>; 25 | |seemed | v :: (s\\np)/*vp : \p\x.seem (p x) <136174 , 1.0>; 26 | |and | c :: (@x\@x)/@x : \p\q\x.and (p x) (q x) <220906 , 1.0>; 27 | |boldly | j :: (s\np)/(s[o=kirk, s=?y]\np) : \p\x.boldly (p x) <925746 , 1.0>; 28 | 29 | 30 | 31 | |to | p :: vp/iv : \p.p <636524 , 1.0>; 32 | |have | aux :: iv/iv : \p.p <563112 , 1.0>; 33 | |bought | v :: iv/np : \x\y.buy x y <903945 , 1.0>; % this one's for perfective have/had bought 34 | % Cf. the relational rule down below for bare/tensed form 35 | 36 | |the | det :: np/*n : def <574974 , 1.0>; 37 | |car | n :: n : car <270679 , 1.0>; 38 | |handsome | p :: propp : \x.handsome x <347363 , 1.0>; 39 | 40 | |kicked the bucked | idio :: s\np :\x.die_euphemistic x <795757 , 1.0>; % frozen expression 41 | |kicked | v :: (s\np)/'bucket'/PredP : \p\x\y.die_ (euphemistic p x) y <566088 , 1.0>; % not so frozen expression 42 | |pick up | pv :: iv/np : \x\y.pick_culminate x y <319026 , 1.0>; % phrasal verb. All POSs are up to you. 43 | |pick | pv2 :: iv/'up'/np : \x\y\z.hold (culminate y) x z <907008 , 1.0>; % separable phrasal verb 44 | 45 | % relational rules (as opposed to combining rules) 46 | 47 | #past (run, iv:\x.run x) <--> (ran, s\np:\x.past run x) <138467 , 1.0>; % a symmetric rule 48 | #subj (np : lt) --> (s/(s\np):\lt\p.p lt) <575660 , 1.0>; % an asymmetric rule 49 | 50 | % <--> means these two are related During parsing, we pick the one in surface form. 51 | % --> means the surface string bearing the category on the lhs ALSO 52 | % has the category on the rhs in parsing. 53 | 54 | % In --> we must take the whole lambda term (lt) in the lhs as first input 55 | % on the rhs and restructure by reductions on the rhs. 56 | % Otherwise we need pattern matching (yikes). 57 | 58 | % This can be done since every item in lt 59 | % is known, per rule. For example, the following example is from 60 | % Turkish, turning adjectives to nouns (Lewis 1967), 61 | % mapping input lambda term \p\x.and(p x)(nompred x) to 62 | % \x.and(nompred x)(nompred x). 63 | #lewis-rule (np/np : lt) --> (np : \lt.lt nompred) <385 , 1.0>; 64 | % example: zengin adam `rich man', zengin: `the rich' 65 | % it is asymmetric: 'Mehmet' but *'Mehmet adam' 66 | 67 | 68 | #past (buy, iv/np:\x\y.buy x y) <--> (bought, (s\np)/np:\x\y.past buy x y) <529659 , 1.0>; 69 | 70 | % NB. rule name is same as run <--> ran. Useful 71 | % (in fact essential) for capturing morphological 72 | % paradigms, Greg Stump-style. 73 | % Note however that these paradigms are categorial, in this example 74 | % across verbal categories. 75 | 76 | % To lexical rule aficionados: these are not lexical 77 | % rules because they do not necessarily work on 78 | % lexical forms to produce lexical forms. 79 | % NB. There is no POS tag on either rule type. 80 | % We don't use the L-word in Monadic Grammar. 81 | % All you have is elements of grammar. 82 | 83 | % I won't offer a universal POS tag set after having written a book 84 | % on linguistic diversity. 85 | % Nothing in monadic grammar depends on universal set of POS tags or universal set of basic categories. 86 | % There is no synthetic notion that is necessary. 87 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test.tc: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from acid-test.tc October 07, 2022, 12:10:37 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 576602)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 659624)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 618799)(PARAM 1.0)(PHON it is more) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (typ x))))(SEM it) 21 | ) 22 | ( 23 | (KEY 248533)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (agr ?x)(num sg))))(SEM john) 25 | ) 26 | ( 27 | (KEY 643705)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 17)(PARAM 1.27)(PHON study) 32 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 33 | ) 34 | ( 35 | (KEY 320952)(PARAM 1.0)(PHON persuaded) 36 | (MORPH v)(SYN (((((BCAT s)(FEATS (type decl)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS (det none)(h ?x))))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS (h ?x))))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 37 | ) 38 | ( 39 | (KEY 118868)(PARAM 1.0)(PHON promised) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 41 | ) 42 | ( 43 | (KEY 734641)(PARAM 1.0)(PHON wanted) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 45 | ) 46 | ( 47 | (KEY 21)(PARAM 2.8)(PHON expected) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 647502)(PARAM 1.0)(PHON considered) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 659030)(PARAM 1.0)(PHON seemed) 56 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 57 | ) 58 | ( 59 | (KEY 513845)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 61 | ) 62 | ( 63 | (KEY 982456)(PARAM 1.0)(PHON seemed) 64 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL STAR)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 65 | ) 66 | ( 67 | (KEY 449563)(PARAM 1.0)(PHON and) 68 | (MORPH c)(SYN ((((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))(DIR FS)(MODAL ALL)((BCAT @x)special)))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 69 | ) 70 | ( 71 | (KEY 675752)(PARAM 1.0)(PHON boldly) 72 | (MORPH j)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS (o kirk)(s ?y)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(SEM (LAM p (LAM x (boldly (p x))))) 73 | ) 74 | ( 75 | (KEY 289913)(PARAM 1.0)(PHON to) 76 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 77 | ) 78 | ( 79 | (KEY 796664)(PARAM 1.0)(PHON have) 80 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 81 | ) 82 | ( 83 | (KEY 924325)(PARAM 1.0)(PHON bought) 84 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 85 | ) 86 | ( 87 | (KEY 115572)(PARAM 1.0)(PHON the) 88 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 89 | ) 90 | ( 91 | (KEY 364862)(PARAM 1.0)(PHON car) 92 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 93 | ) 94 | ( 95 | (KEY 990939)(PARAM 1.0)(PHON handsome) 96 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 97 | ) 98 | ( 99 | (KEY 862921)(PARAM 1.0)(PHON kicked the bucked) 100 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 101 | ) 102 | ( 103 | (KEY 645679)(PARAM 1.0)(PHON kicked) 104 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 105 | ) 106 | ( 107 | (KEY 380666)(PARAM 1.0)(PHON pick up) 108 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 109 | ) 110 | ( 111 | (KEY 295632)(PARAM 1.0)(PHON pick) 112 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 113 | ) 114 | ( 115 | (KEY 461892)(PARAM 1.0)(PHON run) 116 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 117 | ) 118 | ( 119 | (KEY 257738)(PARAM 1.0)(PHON ran) 120 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 121 | ) 122 | ( 123 | (KEY 942854)(PARAM 1.0)(PHON buy) 124 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 125 | ) 126 | ( 127 | (KEY 292677)(PARAM 1.0)(PHON bought) 128 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 129 | ) 130 | ;; 131 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 132 | ) 133 | -------------------------------------------------------------------------------- /lab-material/sly-material/cb-sly-example/acid-test.tc.lisp: -------------------------------------------------------------------------------- 1 | ( 2 | ;;;;;;;;;; bench.py-generated monadic Lisp grammar 3 | ;;;;;;;;;; from acid-test.tc October 07, 2022, 11:05:35 4 | ;; 5 | ;; a rules 6 | ;; 7 | ( 8 | (KEY 981571)(PARAM 1.0)(INDEX subj) 9 | (INSYN ((BCAT np)(FEATS NIL)))(OUTSYN (((BCAT s)(FEATS NIL))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(INSEM lt)(OUTSEM (LAM lt (LAM p (p lt)))) 10 | ) 11 | ( 12 | (KEY 837459)(PARAM 1.0)(INDEX lewis-rule) 13 | (INSYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(OUTSYN ((BCAT np)(FEATS NIL)))(INSEM lt)(OUTSEM (LAM lt (lt nompred))) 14 | ) 15 | ;; 16 | ;; elements 17 | ;; 18 | ( 19 | (KEY 172945)(PARAM 1.0)(PHON it is more) 20 | (MORPH n)(SYN ((BCAT xp)(FEATS (typ x))))(SEM it) 21 | ) 22 | ( 23 | (KEY 412754)(PARAM 1.0)(PHON john) 24 | (MORPH n)(SYN ((BCAT np)(FEATS (agr ?x)(num sg))))(SEM john) 25 | ) 26 | ( 27 | (KEY 223632)(PARAM 1.0)(PHON mary) 28 | (MORPH n)(SYN ((BCAT np)(FEATS NIL)))(SEM mary) 29 | ) 30 | ( 31 | (KEY 17)(PARAM 1.27)(PHON study) 32 | (MORPH inf)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (study x))) 33 | ) 34 | ( 35 | (KEY 804652)(PARAM 1.0)(PHON persuaded) 36 | (MORPH v)(SYN (((((BCAT s)(FEATS (type decl)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS (det none)(h ?x))))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS (h ?x))))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((persuade (p x)) x) y))))) 37 | ) 38 | ( 39 | (KEY 383234)(PARAM 1.0)(PHON promised) 40 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y (((promise (p y)) x) y))))) 41 | ) 42 | ( 43 | (KEY 288913)(PARAM 1.0)(PHON wanted) 44 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((want (p x)) y))))) 45 | ) 46 | ( 47 | (KEY 21)(PARAM 2.8)(PHON expected) 48 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL HARMONIC)((BCAT vp)(FEATS NIL)))(DIR FS)(MODAL CROSS)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((expect (p x)) y))))) 49 | ) 50 | ( 51 | (KEY 882063)(PARAM 1.0)(PHON considered) 52 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(LEX t)((BCAT propp)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM p (LAM y ((consider (p x)) y))))) 53 | ) 54 | ( 55 | (KEY 37207)(PARAM 1.0)(PHON seemed) 56 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 57 | ) 58 | ( 59 | (KEY 137224)(PARAM 1.0)(PHON seemed) 60 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT (it is less))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT s)(FEATS NIL))))(SEM (LAM p (LAM x (seem p)))) 61 | ) 62 | ( 63 | (KEY 506041)(PARAM 1.0)(PHON seemed) 64 | (MORPH v)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)(LEX t)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL STAR)((BCAT vp)(FEATS NIL))))(SEM (LAM p (LAM x (seem (p x))))) 65 | ) 66 | ( 67 | (KEY 638546)(PARAM 1.0)(PHON and) 68 | (MORPH c)(SYN ((((BCAT @x)special)(DIR BS)(MODAL ALL)((BCAT @x)special))(DIR FS)(MODAL ALL)((BCAT @x)special)))(SEM (LAM p (LAM q (LAM x ((and (p x)) (q x)))))) 69 | ) 70 | ( 71 | (KEY 449734)(PARAM 1.0)(PHON boldly) 72 | (MORPH j)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)(((BCAT s)(FEATS (o kirk)(s ?y)))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))))(SEM (LAM p (LAM x (boldly (p x))))) 73 | ) 74 | ( 75 | (KEY 779803)(PARAM 1.0)(PHON to) 76 | (MORPH p)(SYN (((BCAT vp)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 77 | ) 78 | ( 79 | (KEY 568008)(PARAM 1.0)(PHON have) 80 | (MORPH aux)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT iv)(FEATS NIL))))(SEM (LAM p p)) 81 | ) 82 | ( 83 | (KEY 403749)(PARAM 1.0)(PHON bought) 84 | (MORPH v)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 85 | ) 86 | ( 87 | (KEY 192172)(PARAM 1.0)(PHON the) 88 | (MORPH det)(SYN (((BCAT np)(FEATS NIL))(DIR FS)(MODAL STAR)((BCAT n)(FEATS NIL))))(SEM def) 89 | ) 90 | ( 91 | (KEY 764254)(PARAM 1.0)(PHON car) 92 | (MORPH n)(SYN ((BCAT n)(FEATS NIL)))(SEM car) 93 | ) 94 | ( 95 | (KEY 802702)(PARAM 1.0)(PHON handsome) 96 | (MORPH p)(SYN ((BCAT propp)(FEATS NIL)))(SEM (LAM x (handsome x))) 97 | ) 98 | ( 99 | (KEY 104262)(PARAM 1.0)(PHON kicked the bucked) 100 | (MORPH idio)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (die_euphemistic x))) 101 | ) 102 | ( 103 | (KEY 450421)(PARAM 1.0)(PHON kicked) 104 | (MORPH v)(SYN (((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT (bucket))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT PredP)(FEATS NIL))))(SEM (LAM p (LAM x (LAM y ((die_ ((euphemistic p) x)) y))))) 105 | ) 106 | ( 107 | (KEY 452324)(PARAM 1.0)(PHON pick up) 108 | (MORPH pv)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((pick_culminate x) y)))) 109 | ) 110 | ( 111 | (KEY 666879)(PARAM 1.0)(PHON pick) 112 | (MORPH pv2)(SYN ((((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT (up))(BCONST T)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (LAM z (((hold (culminate y)) x) z))))) 113 | ) 114 | ( 115 | (KEY 679461)(PARAM 1.0)(PHON run) 116 | (MORPH past)(SYN ((BCAT iv)(FEATS NIL)))(SEM (LAM x (run x))) 117 | ) 118 | ( 119 | (KEY 672671)(PARAM 1.0)(PHON ran) 120 | (MORPH past)(SYN (((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x ((past run) x))) 121 | ) 122 | ( 123 | (KEY 657663)(PARAM 1.0)(PHON buy) 124 | (MORPH past)(SYN (((BCAT iv)(FEATS NIL))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y ((buy x) y)))) 125 | ) 126 | ( 127 | (KEY 584584)(PARAM 1.0)(PHON bought) 128 | (MORPH past)(SYN ((((BCAT s)(FEATS NIL))(DIR BS)(MODAL ALL)((BCAT np)(FEATS NIL)))(DIR FS)(MODAL ALL)((BCAT np)(FEATS NIL))))(SEM (LAM x (LAM y (((past buy) x) y)))) 129 | ) 130 | ;; 131 | ;;;;;;;;;; end of bench.py-generated monadic Lisp grammar 132 | ) 133 | -------------------------------------------------------------------------------- /project-material/project1_solutions/misc.py: -------------------------------------------------------------------------------- 1 | from re import A 2 | from ast_tools import * 3 | from typing import List 4 | 5 | from parser import Parser 6 | from lexer import Lexer 7 | 8 | def process(source): 9 | return Parser().parse(Lexer().tokenize(source)) 10 | 11 | def generate_ast(intermediate) -> Program: 12 | return intermediate 13 | 14 | def undeclared_vars(intermediate) -> List[Identifier]: 15 | varVisitor = VarVisitor() 16 | varVisitor.visit(intermediate) 17 | return varVisitor.undeclared_vars 18 | 19 | def multiple_var_declarations(intermediate) -> List[Identifier]: 20 | varVisitor = VarVisitor() 21 | varVisitor.visit(intermediate) 22 | return varVisitor.multiple_decls 23 | 24 | 25 | class Environment: 26 | def __init__(self, prev = None): 27 | self.prev = prev 28 | self.table = set() 29 | 30 | def member(self, elem): 31 | return elem in self.table 32 | 33 | def recursive_member(self, elem): 34 | if elem in self.table: 35 | return True 36 | elif self.prev is not None: 37 | return self.prev.recursive_member(elem) 38 | 39 | return False 40 | 41 | def add(self, elem): 42 | self.table.add(elem) 43 | 44 | class VarVisitor(ASTNodeVisitor): 45 | def __init__(self): 46 | super().__init__() 47 | self.top_environment = Environment() 48 | self.current_environment = self.top_environment 49 | self.multiple_decls = [] 50 | self.undeclared_vars = [] 51 | 52 | def add_to_current_env(self, identifier: Identifier): 53 | if self.current_environment.member(identifier.name): 54 | self.multiple_decls.append(identifier) 55 | else: 56 | self.current_environment.add(identifier.name) 57 | 58 | def get_identifier(self, identifier: Identifier): 59 | if not self.current_environment.recursive_member(identifier.name): 60 | self.undeclared_vars.append(identifier) 61 | 62 | def visit_nonscoped_body(self, body: Block): 63 | for elem in body.var_decls: 64 | self.visit(elem) 65 | for elem in body.statements: 66 | self.visit(elem) 67 | 68 | def visit_SLiteral(self, sliteral: SLiteral): 69 | pass 70 | 71 | def visit_Program(self, program: Program): 72 | for elem in program.var_decls: 73 | self.visit(elem) 74 | for elem in program.fun_decls: 75 | self.visit(elem) 76 | for elem in program.statements: 77 | self.visit(elem) 78 | 79 | def visit_ErrorStmt(self, errorstmt: ErrorStmt): 80 | pass 81 | 82 | def visit_VarDecl(self, vardecl: VarDecl): 83 | self.add_to_current_env(vardecl.identifier) 84 | if vardecl.initializer is not None: 85 | if type(vardecl.initializer) == list: 86 | for elem in vardecl.initializer: 87 | self.visit(elem) 88 | else: 89 | self.visit(vardecl.initializer) 90 | 91 | 92 | def visit_FunDecl(self, fundecl: FunDecl): 93 | self.current_environment = Environment(self.current_environment) 94 | for elem in fundecl.params: 95 | self.add_to_current_env(elem) 96 | #self.visit_nonscoped_body(fundecl.body) <- uncomment this and comment other for implementation that regards formal parameters as variable decls 97 | self.visit(fundecl.body) # comment this for the above 98 | self.current_environment = self.current_environment.prev 99 | 100 | def visit_Assign(self, assign: Assign): 101 | self.get_identifier(assign.identifier) 102 | self.visit(assign.expr) 103 | 104 | def visit_SetVector(self, setvector: SetVector): 105 | self.get_identifier(setvector.identifier) 106 | self.visit(setvector.vector_index) 107 | self.visit(setvector.expr) 108 | 109 | def visit_ForLoop(self, forloop: ForLoop): 110 | if not forloop.initializer is None: 111 | self.visit(forloop.initializer) 112 | if not forloop.condition is None: 113 | self.visit(forloop.condition) 114 | if not forloop.increment is None: 115 | self.visit(forloop.increment) 116 | self.visit(forloop.body) 117 | 118 | def visit_Return(self, returnn: Return): 119 | self.visit(returnn.expr) 120 | 121 | def visit_WhileLoop(self, whileloop: WhileLoop): 122 | self.visit(whileloop.condition) 123 | self.visit(whileloop.body) 124 | 125 | def visit_Block(self, block: Block): 126 | self.current_environment = Environment(self.current_environment) 127 | self.visit_nonscoped_body(block) 128 | self.current_environment = self.current_environment.prev 129 | 130 | def visit_Print(self, print: Print): 131 | self.visit(print.expr) 132 | 133 | def visit_IfElse(self, ifelse: IfElse): 134 | self.visit(ifelse.condition) 135 | self.visit(ifelse.if_branch) 136 | if ifelse.else_branch: 137 | self.visit(ifelse.else_branch) 138 | 139 | def visit_LBinary(self, lbinary: LBinary): 140 | self.visit(lbinary.left) 141 | self.visit(lbinary.right) 142 | 143 | def visit_Comparison(self, comparison: Comparison): 144 | self.visit(comparison.left) 145 | self.visit(comparison.right) 146 | 147 | def visit_LLiteral(self, lliteral: LLiteral): 148 | pass 149 | 150 | def visit_LPrimary(self, lprimary: LPrimary): 151 | self.visit(lprimary.primary) 152 | 153 | def visit_GetVector(self, getvector: GetVector): 154 | self.get_identifier(getvector.identifier) 155 | self.visit(getvector.vector_index) 156 | 157 | def visit_Variable(self, variable: Variable): 158 | self.get_identifier(variable.identifier) 159 | 160 | def visit_LNot(self, lnot: LNot): 161 | self.visit(lnot.right) 162 | 163 | def visit_ABinary(self, abinary: ABinary): 164 | self.visit(abinary.left) 165 | self.visit(abinary.right) 166 | 167 | def visit_AUMinus(self, auminus: AUMinus): 168 | self.visit(auminus.right) 169 | 170 | def visit_ALiteral(self, aliteral: ALiteral): 171 | pass 172 | 173 | def visit_Call(self, call: Call): 174 | for elem in call.arguments: 175 | self.visit(elem) --------------------------------------------------------------------------------