Unlock all 4 pages
Get it free by sharing your own notes, buy just this one, or become a member and unlock documents with your plan.
How to unlock this document
Choose the way that suits you. Each one gives you all 4 pages to read online and the PDF to download.
Share your notes, unlock for free
2 free unlocks for every 5 approved uploads
- Upload your own lecture notes, assignments, essays or past papers
- PDF, Word, PowerPoint and Excel files all work, and you can send many at once
- We check each upload; you get a notification when it is approved
- Spend a free unlock on this document or any other, and keep it for good
- Shared under your public username, never your email
Then upload your notes from your profile.
Buy this document
$4 one-time payment
- All 4 pages of this document, yours to keep
- Download the PDF and read it any time, also offline
- No subscription and nothing to cancel
- Find it again any time under My Profile → Library
You log in or create a free account first, then pay securely.
Become a member
Unlock documents from the whole library, which keeps growing
- Choose any documents you like, up to your plan’s unlocks
- Documents you unlock stay yours, even if you cancel later
- Your unlocks start again with every renewal
- Secure checkout by Dodo Payments
You log in or create a free account first, then pay securely.
Compare the plansAlready a member, or bought this before? Log in to open it
About this document
- Pages
- 4 pages
- Price
- $4 one-time, yours to keep
- Membership
- Included in every plan
- Format
- Subject
- Computer Science
This document shows how to specify a parser for a simple arithmetic expression evaluator in Java using the CUP parser generator. It explains the grammar and the actions to evaluate expressions.
What's inside
- CUP specification for expression evaluator
- Terminal and non-terminal symbols
- Grammar rules for expressions
- Precedence of operators
- Actions to evaluate expressions
Who it is for: Students learning Java programming and compiler design. (Undergraduate)
Share with classmates: WhatsApp Telegram X LinkedIn Facebook
Summary
A simple expression evaluator is a system for evaluating arithmetic expressions over integers. It reads expressions from standard input, evaluates them and prints the result on standard output. A student gets an overview of how to specify a parser for such a system using Java CUP.
Setting up the scanner
The scanner is set up and used to read tokens from the input. It is initialized and then called to get the next token. This part explains how to use the scanner in the Java CUP specification.
Defining the grammar
The grammar for the input expressions is defined using terminal and non-terminal symbols. The grammar rules specify how expressions can be constructed using these symbols. This part explains the grammar rules for the simple expression evaluator.
Adding actions to the grammar
Actions are added to the grammar rules to perform operations on the input expressions. These actions are specified using Java code. This part explains how to add actions to the grammar rules to evaluate the expressions.
Specifying the grammar
The grammar is specified using Java CUP syntax. The grammar rules are written using terminal and non-terminal symbols. This part explains how to specify the grammar using Java CUP syntax.
Key terms
- Terminal symbols
- Symbols that appear on input, such as SEMI, PLUS, MINUS.
- Non-terminal symbols
- Symbols that represent parts of the grammar, such as expr_list, expr_part.
- Grammar rules
- Rules that specify how expressions can be constructed using terminal and non-terminal symbols.
- Actions
- Java code that performs operations on the input expressions.
- Scanner
- A tool that reads tokens from the input.
- Java CUP
- A tool for specifying and generating parsers in Java.
Questions this document helps with
- How do you set up a scanner in Java CUP?
- What are the grammar rules for a simple expression evaluator?
- How do you add actions to a grammar in Java CUP?
Summary written with AI from the document's text.
Ask the AI Teacher
Ask any question about this document or your course, and get a clear explanation.
Log in to ask Create a free account
Free accounts can ask 5 questions a day.