Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Submission You should submit your programs at the submission site (you can click the left highlighted words to go to the submission site). The

image text in transcribedimage text in transcribedimage text in transcribed

1 Submission You should submit your programs at the submission site (you can click the left highlighted words to go to the submission site). The due date is Friday before the last lab note that the due time is not the same as the last lab assignment. It is worth 8 points. We will use your last submission for your final marks for this assignment. You must test your program on our sample inputs and other cases devised by you before submission. Passing the sample inputs will not guarantee a high mark. You must fully understand the grammar and implement that grammar correctly so that your parser can cope with all situations. 2 Assignment Specification This assignment is to parse Tiny programs using JavaCUP. You need to write a JavaCUP file and a JLex file so that a parser for Tiny language can be generated. The parser will be able to tell whether a Tiny program is syntactically correct. You need to rewrite EBNF grammar into CFG that is acceptable by JavaCUP. Comments in Tiny program should be thrown away in the scanner. We will run the following commands to generate the scanner and the parser. You can modify the lex file you created in assignment 2. >java JLex.Main A3.lex >java java cup. Main -parser A3Parser -syabols AaSyabol javac A3.lex.java AsParser.java A3Symbol.java A3User.java >java A3User The program A3User invokes the parser. It is defined as below: import java.io..: class A3User ! public static void main(String[] args) throws Exception { File input File - new Pile ("A3.tiny"): A3Parser parser=new AsParser(new ABScanner(new FileInputStrean (inputFile))): Integer result =(Integer) parser.parse().value: FileWriter fu=new FileWriter (new File("A3.output)): fw.write("Number of methods: *+ result. intValue(): fw.close(): } } If your lex and cup files are correct, all of those command and especially A3User will run smoothly without any error report, and an A3.output file will be created which should consists of one line as follows: Number of methode: number Of Mehtodsind 2 Input If your programs are not correct, during the process there will be some error messages. Here is a sample A3.tiny file and A3.output file. For incorrect Tiny programs such as A31.tiny and A32.tiny, your parser will report an error and no A3.output file is generated. Note that you don't need to write any Java programs. The parser and the scanner are generated from your cup and lex specifications. Also, we will test your program on our own data. 3 What to submit You need to turn in two files: the JLex file, named A3.lex, which can be used to generate the scanner; the javaCUP file, named A3.cup, which can be used to generate the parser. 4 Installing JavaCup Download the JavaCup tar file by right-clicking on the link here. Save that file on your 2140 directory. Then run the following the extract the files to your 2140 directory: 1 tar -xvf javaCup.tar It will create the java cup directory, and extract the classes into that directory. The result of running the command will look like this: 214 Jianguolu$ tar -xvf javaCup.tar I java_cup/CUP $parsersactions.class 1 java_cup/Main.class I java_cup/Main.java 1 java_cup/action_part.class I java_cup/action-part.java I java-cup/action_production.class I java cup/action_production.java javacup/assoc.class 1 java_cup/assoc.java 1 java_cup/anit.class I java_cup/emit.java Unlike JLex, java cup has java files as well as class files, hence you do not need to compile them. To run your javaCup, you go to the directory that is one layer above java cup (for instance 2140), type java java_cup. Main java JLex.Main A3.lex >java java cup. Main -parser A3Parser -syabols AaSyabol javac A3.lex.java AsParser.java A3Symbol.java A3User.java >java A3User The program A3User invokes the parser. It is defined as below: import java.io..: class A3User ! public static void main(String[] args) throws Exception { File input File - new Pile ("A3.tiny"): A3Parser parser=new AsParser(new ABScanner(new FileInputStrean (inputFile))): Integer result =(Integer) parser.parse().value: FileWriter fu=new FileWriter (new File("A3.output)): fw.write("Number of methods: *+ result. intValue(): fw.close(): } } If your lex and cup files are correct, all of those command and especially A3User will run smoothly without any error report, and an A3.output file will be created which should consists of one line as follows: Number of methode: number Of Mehtodsind 2 Input If your programs are not correct, during the process there will be some error messages. Here is a sample A3.tiny file and A3.output file. For incorrect Tiny programs such as A31.tiny and A32.tiny, your parser will report an error and no A3.output file is generated. Note that you don't need to write any Java programs. The parser and the scanner are generated from your cup and lex specifications. Also, we will test your program on our own data. 3 What to submit You need to turn in two files: the JLex file, named A3.lex, which can be used to generate the scanner; the javaCUP file, named A3.cup, which can be used to generate the parser. 4 Installing JavaCup Download the JavaCup tar file by right-clicking on the link here. Save that file on your 2140 directory. Then run the following the extract the files to your 2140 directory: 1 tar -xvf javaCup.tar It will create the java cup directory, and extract the classes into that directory. The result of running the command will look like this: 214 Jianguolu$ tar -xvf javaCup.tar I java_cup/CUP $parsersactions.class 1 java_cup/Main.class I java_cup/Main.java 1 java_cup/action_part.class I java_cup/action-part.java I java-cup/action_production.class I java cup/action_production.java javacup/assoc.class 1 java_cup/assoc.java 1 java_cup/anit.class I java_cup/emit.java Unlike JLex, java cup has java files as well as class files, hence you do not need to compile them. To run your javaCup, you go to the directory that is one layer above java cup (for instance 2140), type java java_cup. Main

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimizing Data Collection In Warzones

Authors: Aaget Aamber

1st Edition

B0CQRRFP5F, 979-8869065902

More Books

Students also viewed these Databases questions