Draw a state diagram to recognize hexadecimal integer consta

Draw a state diagram to recognize hexadecimal integer constants as defined by the following EBNF rules: rightarrow [] rightarrow | rightarrow [] | [] rightarrow u | U rightarrow 1 | L rightarrow 0x | 0X rightarrow h | H rightarrow | rightarrow 0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|A|B|C|D|E|F Use as few states as possible. States that are legal ending points for hexadecimal integer constants should be drawn as double circles (see the states labeled \"id\" and \"int\" in Figure 4.1 of Sebesta). To save space, omit the \"addchar; getChar\" labels and \"return\" actions shown in Sebesta\'s diagrams. You may use names to represent character classes as long as you define what the names mean. For example, you might use HexDigit to represent the characters listed in the rule. Using the syntax of C, write a recursive-descent subprogram named initializer that corresponds to the following rules (taken from the C99 standard): initializer: assignment-expression {initializer-list} {initializer-list, } Note that {and} are terminals, not metasymbols. Assume that recursive-descent subprograms named assignment-expression and initializer-list already exist.

Solution

#include struct S { int x; struct Foo { int i; int j; int a[3]; } b; }; union U { int a; const char* b; }; int main() { S s1 = { 1, { 2, 3, {4, 5, 6} } }; S s2 = { 1, 2, 3, 4, 5, 6}; // same, but with brace elision S s3{1, {2, 3, {4, 5, 6} } }; // same, using direct-list-initialization syntax S s4{1, 2, 3, 4, 5, 6}; // error in C++11: brace-elision only allowed with equals sign // okay in C++14 int ar[] = {1,2,3}; // ar is int[3] // char cr[3] = {\'a\', \'b\', \'c\', \'d\'}; // too many initializer clauses char cr[3] = {\'a\'}; // array initialized as {\'a\', \'\\0\', \'\\0\'} int ar2d1[2][2] = {{1, 2}, {3, 4}}; // fully-braced 2D array: {1, 2} // {3, 4} int ar2d2[2][2] = {1, 2, 3, 4}; // brace elision: {1, 2} // {3, 4} int ar2d3[2][2] = {{1}, {2}}; // only first column: {1, 0} // {2, 0} std::array std_ar2{ {1,2,3} }; // std::array is an aggregate std::array std_ar1 = {1, 2, 3}; // brace-elision okay int ai[] = { 1, 2.0 }; // narrowing conversion from double to int: // error in C++11, okay in C++03 std::string ars[] = {std::string(\"one\"), // copy-initialization \"two\", // conversion, then copy-initialization {\'t\', \'h\', \'r\', \'e\', \'e\'} }; // list-initialization U u1 = {1}; // OK, first member of the union // U u2 = { 0, \"asdf\" }; // error: too many initializers for union // U u3 = { \"asdf\" }; // error: invalid conversion to int } // aggregate struct base1 { int b1, b2 = 42; }; // non-aggregate struct base2 { base2() : b3(42) {} int b3; }; // aggregate in C++17 struct derived : base1, base2 { int d; }; derived d1{ {1, 2}, { }, 4}; // d1.b1 = 1, d1.b2 = 2, d1.b3 = 42, d1.d = 4 derived d2{ { }, { }, 4}; // d2.b1 = 0, d2.b2 = 42, d2.b3 = 42, d2.d = 4
 Draw a state diagram to recognize hexadecimal integer constants as defined by the following EBNF rules: rightarrow [] rightarrow | rightarrow [] | [] rightarro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site