From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- Homework/cs5300/project-three/data/Expr.cfg | 25 ++++++++ .../cs5300/project-three/data/ExprLexer.tokens | 39 +++++++++++++ Homework/cs5300/project-three/data/Paren.cfg | 17 ++++++ .../cs5300/project-three/data/ParenLexer.tokens | 19 +++++++ Homework/cs5300/project-three/data/Simple.cfg | 13 +++++ .../cs5300/project-three/data/SimpleLexer.tokens | 15 +++++ Homework/cs5300/project-three/data/Tiny copy.cfg | 63 +++++++++++++++++++++ Homework/cs5300/project-three/data/Tiny.cfg | 63 +++++++++++++++++++++ .../cs5300/project-three/data/TinyLexer.tokens | 41 ++++++++++++++ Homework/cs5300/project-three/data/expr1.dat | 1 + Homework/cs5300/project-three/data/expr2.dat | 1 + Homework/cs5300/project-three/data/expr3.dat | 1 + Homework/cs5300/project-three/data/expr4.dat | 1 + Homework/cs5300/project-three/data/expr5.dat | 1 + Homework/cs5300/project-three/data/expr6.dat | 1 + Homework/cs5300/project-three/data/paren0.dat | 1 + Homework/cs5300/project-three/data/paren1.dat | 3 + Homework/cs5300/project-three/data/paren2.dat | 3 + Homework/cs5300/project-three/data/paren3.dat | 1 + Homework/cs5300/project-three/data/paren4.dat | 1 + Homework/cs5300/project-three/data/tiny1.dat | 3 + Homework/cs5300/project-three/data/tiny2.dat | 7 +++ Homework/cs5300/project-three/data/tiny3.dat | 4 ++ Homework/cs5300/project-three/data/tiny4.dat | 4 ++ Homework/cs5300/project-three/data/tinyGrammar.pdf | Bin 0 -> 83316 bytes 25 files changed, 328 insertions(+) create mode 100644 Homework/cs5300/project-three/data/Expr.cfg create mode 100644 Homework/cs5300/project-three/data/ExprLexer.tokens create mode 100644 Homework/cs5300/project-three/data/Paren.cfg create mode 100644 Homework/cs5300/project-three/data/ParenLexer.tokens create mode 100644 Homework/cs5300/project-three/data/Simple.cfg create mode 100644 Homework/cs5300/project-three/data/SimpleLexer.tokens create mode 100644 Homework/cs5300/project-three/data/Tiny copy.cfg create mode 100644 Homework/cs5300/project-three/data/Tiny.cfg create mode 100644 Homework/cs5300/project-three/data/TinyLexer.tokens create mode 100644 Homework/cs5300/project-three/data/expr1.dat create mode 100644 Homework/cs5300/project-three/data/expr2.dat create mode 100644 Homework/cs5300/project-three/data/expr3.dat create mode 100644 Homework/cs5300/project-three/data/expr4.dat create mode 100644 Homework/cs5300/project-three/data/expr5.dat create mode 100644 Homework/cs5300/project-three/data/expr6.dat create mode 100644 Homework/cs5300/project-three/data/paren0.dat create mode 100644 Homework/cs5300/project-three/data/paren1.dat create mode 100644 Homework/cs5300/project-three/data/paren2.dat create mode 100644 Homework/cs5300/project-three/data/paren3.dat create mode 100644 Homework/cs5300/project-three/data/paren4.dat create mode 100644 Homework/cs5300/project-three/data/tiny1.dat create mode 100644 Homework/cs5300/project-three/data/tiny2.dat create mode 100644 Homework/cs5300/project-three/data/tiny3.dat create mode 100644 Homework/cs5300/project-three/data/tiny4.dat create mode 100644 Homework/cs5300/project-three/data/tinyGrammar.pdf (limited to 'Homework/cs5300/project-three/data') diff --git a/Homework/cs5300/project-three/data/Expr.cfg b/Homework/cs5300/project-three/data/Expr.cfg new file mode 100644 index 0000000..7493e3e --- /dev/null +++ b/Homework/cs5300/project-three/data/Expr.cfg @@ -0,0 +1,25 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file contains an expression grammar that uses tokens described in +// ExprLexer.tokens. + +grammar Expr; + +goal: expr; + +expr: expr PLUS term + | expr MINUS term + | term + ; + +term : term MULTIPLY factor + | term DIVIDE factor + | factor + ; + +factor: OPAREN expr CPAREN + | INT + | FLOAT + | IDENTIFIER + ; \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/ExprLexer.tokens b/Homework/cs5300/project-three/data/ExprLexer.tokens new file mode 100644 index 0000000..ccb798a --- /dev/null +++ b/Homework/cs5300/project-three/data/ExprLexer.tokens @@ -0,0 +1,39 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file describes the tokens that will be available to the parser +// that uses the grammar described in Expr.cfg. + +lexer grammar ExprLexer; + +PLUS: '+' ; +MINUS: '-' ; +MULTIPLY: '*' ; +DIVIDE: '/' ; +OPAREN: '(' ; +CPAREN: ')' ; + +FLOAT + : DIGIT+ '.' DIGIT+ + ; + +INT + : DIGIT+ + ; + +IDENTIFIER + : LETTER (LETTER | DIGIT)* + ; + +COMMENT + : ( '//' ~[\r\n]* '\r'? '\n' + | '/*' .*? '*/' + ) -> skip + ; + +WS + : (' ' | '\t' | '\n' | '\r' | '\f')+ -> skip + ; + +fragment LETTER : ('a'..'z' | 'A'..'Z'); +fragment DIGIT : ('0'..'9'); \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/Paren.cfg b/Homework/cs5300/project-three/data/Paren.cfg new file mode 100644 index 0000000..184b11c --- /dev/null +++ b/Homework/cs5300/project-three/data/Paren.cfg @@ -0,0 +1,17 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file contains an expression grammar that uses tokens described in +// ParenLexer.tokens. + +grammar Paren; + +goal: list; + +list: list pair + | pair + ; + +pair: OPAREN list CPAREN + | OPAREN CPAREN + ; diff --git a/Homework/cs5300/project-three/data/ParenLexer.tokens b/Homework/cs5300/project-three/data/ParenLexer.tokens new file mode 100644 index 0000000..51e5258 --- /dev/null +++ b/Homework/cs5300/project-three/data/ParenLexer.tokens @@ -0,0 +1,19 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file describes the tokens that will be available to the parser +// that uses the grammar described in Paren.cfg. + +lexer grammar ParenLexer; + +OPAREN + : '(' + ; + +CPAREN + : ')' + ; + +WS + : (' ' | '\t' | '\n' | '\r' | '\f')+ -> skip + ; diff --git a/Homework/cs5300/project-three/data/Simple.cfg b/Homework/cs5300/project-three/data/Simple.cfg new file mode 100644 index 0000000..80c1e18 --- /dev/null +++ b/Homework/cs5300/project-three/data/Simple.cfg @@ -0,0 +1,13 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file contains an expression grammar that uses tokens described in +// ParenLexer.tokens. + +grammar Simple; + +G: N; + +N: N X + | X + ; diff --git a/Homework/cs5300/project-three/data/SimpleLexer.tokens b/Homework/cs5300/project-three/data/SimpleLexer.tokens new file mode 100644 index 0000000..64ec3c1 --- /dev/null +++ b/Homework/cs5300/project-three/data/SimpleLexer.tokens @@ -0,0 +1,15 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file describes the tokens that will be available to the parser +// that uses the grammar described in Simple.cfg. + +lexer grammar SimpleLexer; + +X + : 'x' + ; + +WS + : (' ' | '\t' | '\n' | '\r' | '\f')+ -> skip + ; diff --git a/Homework/cs5300/project-three/data/Tiny copy.cfg b/Homework/cs5300/project-three/data/Tiny copy.cfg new file mode 100644 index 0000000..71fb8d9 --- /dev/null +++ b/Homework/cs5300/project-three/data/Tiny copy.cfg @@ -0,0 +1,63 @@ +// +// WRITE A CORRECT GRAMMAR FOR THE TINY LANGUAGE IN THIS FILE. +// +// The grammar is described in data/tinyGrammar.pdf. Do not use dashes +// in your non-terminal names. I recommend you use mixed case naming for your +// non-terminals instead (e.g. stmtSeq). +// +// Do not put any string literals in this grammar (e.g. "="). Use only token +// names given in TinyLexer.tokens. +// +// This file contains an expression grammar that uses tokens described in +// TinyLexer.tokens. +// +// NOTE ONE ERROR in the pdf: the second production rule should read: +// stmt-seq -> stmt-seq stmt | stmt + +grammar Tiny; + +goal: program; + +program: stmtseq; + +stmtseq: stmtseq stmt + | stmt; + +stmt: ifstmt + | repeatstmt + | assignstmt + | readstmt + | writestmt + ; + +ifstmt: IF exp THEN stmtseq END + | IF exp THEN stmtseq ELSE stmtseq END + ; + +repeatstmt: REPEAT stmtseq UNTIL exp; + +assignstmt: ID EQUAL exp; + +readstmt: READ ID; + +writestmt: WRITE exp; + +exp: simpleexp LT simpleexp + | simpleexp EQUAL simpleexp + | simpleexp + ; + +simpleexp: simpleexp PLUS term + | simpleexp MINUS term + | term + ; + +term: term MULTIPLY factor + | term DIVIDE factor + | factor + ; + +factor: OPAREN exp CPAREN + | NUM + | ID + ; \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/Tiny.cfg b/Homework/cs5300/project-three/data/Tiny.cfg new file mode 100644 index 0000000..71fb8d9 --- /dev/null +++ b/Homework/cs5300/project-three/data/Tiny.cfg @@ -0,0 +1,63 @@ +// +// WRITE A CORRECT GRAMMAR FOR THE TINY LANGUAGE IN THIS FILE. +// +// The grammar is described in data/tinyGrammar.pdf. Do not use dashes +// in your non-terminal names. I recommend you use mixed case naming for your +// non-terminals instead (e.g. stmtSeq). +// +// Do not put any string literals in this grammar (e.g. "="). Use only token +// names given in TinyLexer.tokens. +// +// This file contains an expression grammar that uses tokens described in +// TinyLexer.tokens. +// +// NOTE ONE ERROR in the pdf: the second production rule should read: +// stmt-seq -> stmt-seq stmt | stmt + +grammar Tiny; + +goal: program; + +program: stmtseq; + +stmtseq: stmtseq stmt + | stmt; + +stmt: ifstmt + | repeatstmt + | assignstmt + | readstmt + | writestmt + ; + +ifstmt: IF exp THEN stmtseq END + | IF exp THEN stmtseq ELSE stmtseq END + ; + +repeatstmt: REPEAT stmtseq UNTIL exp; + +assignstmt: ID EQUAL exp; + +readstmt: READ ID; + +writestmt: WRITE exp; + +exp: simpleexp LT simpleexp + | simpleexp EQUAL simpleexp + | simpleexp + ; + +simpleexp: simpleexp PLUS term + | simpleexp MINUS term + | term + ; + +term: term MULTIPLY factor + | term DIVIDE factor + | factor + ; + +factor: OPAREN exp CPAREN + | NUM + | ID + ; \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/TinyLexer.tokens b/Homework/cs5300/project-three/data/TinyLexer.tokens new file mode 100644 index 0000000..ad6b2a7 --- /dev/null +++ b/Homework/cs5300/project-three/data/TinyLexer.tokens @@ -0,0 +1,41 @@ +// +// DO NOT MODIFY THIS FILE. +// +// This file describes the tokens that will be available to the parser +// that uses the grammar described in Tiny.cfg. + +lexer grammar TinyLexer; + +IF : 'if' ; +THEN : 'then' ; +ELSE : 'else' ; +END : 'end' ; +REPEAT : 'repeat' ; +UNTIL : 'until' ; +READ : 'read' ; +WRITE : 'write' ; +OPAREN : '(' ; +CPAREN : ')' ; + +PLUS: '+' ; +MINUS: '-' ; +MULTIPLY: '*' ; +DIVIDE: '/' ; +LT: '<' ; +EQUAL: '=' ; + +NUM : DIGIT+ ; +ID : LETTER+ ; + +COMMENT + : ( '//' ~[\r\n]* '\r'? '\n' + | '/*' .*? '*/' + ) -> skip + ; + +WS + : (' ' | '\t' | '\n' | '\r' | '\f')+ -> skip + ; + +fragment LETTER : ('a'..'z' | 'A'..'Z'); +fragment DIGIT : ('0'..'9'); \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/expr1.dat b/Homework/cs5300/project-three/data/expr1.dat new file mode 100644 index 0000000..846e7d3 --- /dev/null +++ b/Homework/cs5300/project-three/data/expr1.dat @@ -0,0 +1 @@ +3 + 4 * 5 / 8 \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/expr2.dat b/Homework/cs5300/project-three/data/expr2.dat new file mode 100644 index 0000000..8e0c0b7 --- /dev/null +++ b/Homework/cs5300/project-three/data/expr2.dat @@ -0,0 +1 @@ +3 + + 42 * 34 \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/expr3.dat b/Homework/cs5300/project-three/data/expr3.dat new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/Homework/cs5300/project-three/data/expr3.dat @@ -0,0 +1 @@ +3 diff --git a/Homework/cs5300/project-three/data/expr4.dat b/Homework/cs5300/project-three/data/expr4.dat new file mode 100644 index 0000000..84a357a --- /dev/null +++ b/Homework/cs5300/project-three/data/expr4.dat @@ -0,0 +1 @@ +(a + b) * ((c-def)/43) \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/expr5.dat b/Homework/cs5300/project-three/data/expr5.dat new file mode 100644 index 0000000..c2c433b --- /dev/null +++ b/Homework/cs5300/project-three/data/expr5.dat @@ -0,0 +1 @@ +(a + b) * ((c-d)/43 diff --git a/Homework/cs5300/project-three/data/expr6.dat b/Homework/cs5300/project-three/data/expr6.dat new file mode 100644 index 0000000..f46d387 --- /dev/null +++ b/Homework/cs5300/project-three/data/expr6.dat @@ -0,0 +1 @@ +( \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/paren0.dat b/Homework/cs5300/project-three/data/paren0.dat new file mode 100644 index 0000000..dd626a0 --- /dev/null +++ b/Homework/cs5300/project-three/data/paren0.dat @@ -0,0 +1 @@ +() \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/paren1.dat b/Homework/cs5300/project-three/data/paren1.dat new file mode 100644 index 0000000..f7e9493 --- /dev/null +++ b/Homework/cs5300/project-three/data/paren1.dat @@ -0,0 +1,3 @@ +(( +))( +)(((()))()(())) \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/paren2.dat b/Homework/cs5300/project-three/data/paren2.dat new file mode 100644 index 0000000..4f879eb --- /dev/null +++ b/Homework/cs5300/project-three/data/paren2.dat @@ -0,0 +1,3 @@ +( +))( +) \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/paren3.dat b/Homework/cs5300/project-three/data/paren3.dat new file mode 100644 index 0000000..e4a2fe8 --- /dev/null +++ b/Homework/cs5300/project-three/data/paren3.dat @@ -0,0 +1 @@ +)()( diff --git a/Homework/cs5300/project-three/data/paren4.dat b/Homework/cs5300/project-three/data/paren4.dat new file mode 100644 index 0000000..3077d74 --- /dev/null +++ b/Homework/cs5300/project-three/data/paren4.dat @@ -0,0 +1 @@ +()()(()()) diff --git a/Homework/cs5300/project-three/data/tiny1.dat b/Homework/cs5300/project-three/data/tiny1.dat new file mode 100644 index 0000000..7f9078f --- /dev/null +++ b/Homework/cs5300/project-three/data/tiny1.dat @@ -0,0 +1,3 @@ +a = 3 +b = 4 +c = a + b diff --git a/Homework/cs5300/project-three/data/tiny2.dat b/Homework/cs5300/project-three/data/tiny2.dat new file mode 100644 index 0000000..09195b8 --- /dev/null +++ b/Homework/cs5300/project-three/data/tiny2.dat @@ -0,0 +1,7 @@ +a = 3 +b = 4 +if a = b then + write (a + b * (c - d)) +else + write a +end \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/tiny3.dat b/Homework/cs5300/project-three/data/tiny3.dat new file mode 100644 index 0000000..768addd --- /dev/null +++ b/Homework/cs5300/project-three/data/tiny3.dat @@ -0,0 +1,4 @@ +a = 3 +if a = then + write a +end \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/tiny4.dat b/Homework/cs5300/project-three/data/tiny4.dat new file mode 100644 index 0000000..1d66283 --- /dev/null +++ b/Homework/cs5300/project-three/data/tiny4.dat @@ -0,0 +1,4 @@ +a = 3 +if (a = b) then + write a = 3) +end \ No newline at end of file diff --git a/Homework/cs5300/project-three/data/tinyGrammar.pdf b/Homework/cs5300/project-three/data/tinyGrammar.pdf new file mode 100644 index 0000000..855d45b Binary files /dev/null and b/Homework/cs5300/project-three/data/tinyGrammar.pdf differ -- cgit v1.3