Question

Please help me with the coding for LL(1)!!

The given grammar was:

P → PL | L
L → N; | M; | C
N → print E
M → print "W"
W → TW | ε
C → if E {P} | if E {P} else {P}
E → (EOE) | V (note: this has a variable O)
O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal 0 (zero))
T → a | b | c | d

And the grammar transformed in LL(1) is:

1. T all clad V 0 1 2 3 E CEOE) C else (P) E 8, N print M 10, L N IC 12.

5.1 Parsing strings with an LL(1) table driven parser

Implement a program which parses strings using an LL(1) table driven parser using the table you determined for G′ in the previous exercise.

You may use Python, Java, C, C++, or Haskell. If you’d like to use a different language then please check with us first.

• Input: The first command line argument is the filename of a file containing the string of characters to test.

• Output: 1. Print a trace of the execution, showing the steps followed by the program as it performs the left-most derivation. This should look similar to parsing the string through a PDA. An example of this is given in the appendices.

2. After parsing the whole input file, print ACCEPTED or REJECTED, depending on whether or not the string could be derived by the grammar.

3. If there is a symbol in the input string which is not a terminal from the grammar, the program should output ERROR_INVALID_SYMBOL (This could be during or before trying to parse the input.) Note: all whitespace in the input file should be ignored (line breaks, spaces, etc.) The output will be easier to read if you remove the whitespace before starting the parse. Examples of the program output syntax are provided in the appendices.

5.2 Evaluating programs written in G′

If a second command line argument “eval” is given, then instead of printing the trace of the parse, your program should:

1. Build a parse tree as it performs the leftmost derivation

2. Evaluate that parse tree. The semantics (meaning) which we are applying to our rules are as follows:

• V variables derive integers • W variables derive strings • E expressions are evaluated like normal integer arithmetic

• print E statements output (to screen) the result of evaluating the expression E. (i.e. print (1+1) outputs 2)

• print "W" statements output the string derived from W (i.e. print "abba" outputs abba)

• if statements evaluate the contents of their if block if and only if the condition evaluated to a non-zero value, otherwise the else block is evaluated instead (if there is one). If the input could not be parsed then output REJECTED instead. Some examples of programs and their expected output are provided in the appendices.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Propositional logic, also known as sentential logic and statement logic, is the branch of logic that studies ways of joining and/or modifying entire propositions, statements or sentences to form more complicated propositions, statements or sentences, as well as the logical relationships and properties that are derived from these methods of combining or altering statements. In propositional logic, the simplest statements are considered as indivisible units, and hence, propositional logic does not study those logical properties and relations that depend upon parts of statements that are not themselves statements on their own, such as the subject and predicate of a statement. The most thoroughly researched branch of propositional logic is classical truth-functional propositional logic, which studies logical operators and connectives that are used to produce complex statements whose truth-value depends entirely on the truth-values of the simpler statements making them up, and in which it is assumed that every statement is either true or false and not both. However, there are other forms of propositional logic in which other truth-values are considered, or in which there is consideration of connectives that are used to produce statements whose truth-values depend not simply on the truth-values of the parts, but additional things such as their necessity, possibility or relatedness to one another.

Add a comment
Know the answer?
Add Answer to:
Please help me with the coding for LL(1)!! The given grammar was: P → PL |...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Recursive Descent Parsing Consider the following BNF grammar: A -> I = E E -> P...

    Recursive Descent Parsing Consider the following BNF grammar: A -> I = E E -> P O P | P O -> + | - | * | / | ** P -> I | L | UI | UL | (E) U -> + | - | ! I -> C | CI C -> a | b | ... | y | z L -> D | DL D -> 0 | 1 | ... | 8 |...

  • NEED THIS SOON. Recursive Descent Parsing Consider the following BNF grammar: A -> I = E...

    NEED THIS SOON. Recursive Descent Parsing Consider the following BNF grammar: A -> I = E E -> P O P | P O -> + | - | * | / | ** P -> I | L | UI | UL | (E) U -> + | - | ! I -> C | CI C -> a | b | ... | y | z L -> D | DL D -> 0 | 1 | ......

  • If someone can help me with the recursive descent parsing, it woule be very helpful. This...

    If someone can help me with the recursive descent parsing, it woule be very helpful. This problem should be completed with only c without using lex or yacc. Problem — LL(1) Grammars and Recursive Descent Parsing The Grammar:: <program> ::=      program <block> . <block> ::=            begin <stmtlist> end <stmtlist> ::=        <stmt> <morestmts> <morestmts> ::= ; <stmtlist <stmt> ::=             <assign> | <ifstmt> | <whilestmt> | <block> <assign> ::=          <variable> = <expr> <ifstmt> ::=           if <testexpr> then <stmt> else <stmt> <whilestmt> ::=    while <testexpr> do <stmt> <testexpr>...

  • Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const...

    Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const 1), write down derivation of: c-5+a 2) What are terminals and what are non-terminals in the grammar? Show a complete parse, including the parse stack contents, input string, and action for the string: id - id + id, using the grammar and parse table below. (10 points) 4. Grammar State id S4 4. T F 5. F (E) R2 S7 R4 R4 R2İR2 Parse...

  • 1. Given grammar: E -> E*E | E + E | num and input string num...

    1. Given grammar: E -> E*E | E + E | num and input string num + num *num. 1a.Write 2 possible leftmost derivations from E to the input string. 1b.Draw parse tree for the two leftmost derivation that you wrote above.

  • Compute CLR-1 and LALR-1 Table of following grammar,

    Compute CLR-1 and LALR-1 Table of following grammar, Analyze the table and find, if there are any conflicts?? If YES, what type of conflicts are they?? Also parse following input along semantic rules by showing stack state while parsing. a id bi id * + [CLO-4, PLO-36] (10+4) S→SE+|Ef|F { print top of stack 2 times} E→EE*|F {if top of stack is E , print Good, else print Bad } F→aF|bi|id {print how many elements are there in stack}

  • (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1...

    (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1 d A Ad IB A BA ASJAE Consider the following grammar G: S'S S (S)S|e fa) (10] Construct the collection of the sets of LR(0) items (b) [5] When constructing the action table of SLR parser of G what are the rules to determine the parsing actions? That is, what is the rule for a shift action at state /? What is the rule...

  • Question 1 Consider the following BNF grammar: Not complete Marked out of 3.00 p Flag question...

    Question 1 Consider the following BNF grammar: Not complete Marked out of 3.00 p Flag question <letter> ::= "a" | "b" | "C" | "d" | "e" | "F" | "g" | "h" | "1" ";" | "K" | "1" | "m" | "n" | "0" | "p" | "q" | "r" | "S" | "t" || "u" | "V" | "W" | "x" | "y" | "z" <digit> ::= "O" | "1" | "2" | "3" | "4" |...

  • 1. Construct a DFSM to accept the language: L w E ab): w contains at least 3 as and no more than 3 bs) 2. Let E (acgt a...

    1. Construct a DFSM to accept the language: L w E ab): w contains at least 3 as and no more than 3 bs) 2. Let E (acgt and let L be the language of strings consisting of repeated copies of the pairs at, ta, cg. ge. Construct both a DFSM to accept the language and a regular expression that represents the language. 3. Let ab. For a string w E , let w denote the string w with the...

  • I need help with this code, I'm stuck on it, please remember step 4, I'm very...

    I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT