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/Tiny.cfg | 63 +++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Homework/cs5300/project-three/data/Tiny.cfg (limited to 'Homework/cs5300/project-three/data/Tiny.cfg') 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 -- cgit v1.3