![]() |
.. (לתיקייה המכילה) | |
We tried to use compile "simple" example, from the tutorial by "lex simple.lex", | |
The problem here is that example.lex was written on a Windows PC, which has a different representation for endline than Unix. Lex can't handle this. To convert example.lex to Unix "format", run the following: dos2unix example.lex > tmp mv tmp example.lex Note that if you plan to work on Windows, you will need to do this for all your files before you run Lex on them. |
Are hexadecimal numbers case sensitive? (As in is 1D a legal hex?) | |
Yes, they are: letters may only appear in lowercase (e.g, 0xab is a valid HEX, while 0xAB is not.) |
Does the following line contain one or two strings? | |
Two strings. |
Can the REAL type contain leading zeroes? (e.g, 00e1 and 00.01) | |
Yes it can. |
Are the following legal REALs? | |
No they are not: the exponent has to be preceded by some digits (with or without a decimal point). |
Are the following legal COMPLEX lexemes: | |
1-0x1i is a VALID complex: each of the components (real and imaginary) can be any type of number, including HEX. -0x1i+1 is NOT a valid complex: "-0x1" is not a valid HEX, so it can't be used as a component. (Note that in the first example, the sign (-) isn't part of the hex number: it only connects the two components.) |
Can HEX numbers have leading zeroes? (e.g, 0x001) | |
Yes. |
Is the exponent in a REAL limited in length? | |
No, it isn't. |
Can the second component in a COMPLEX be signed (other than the | |
No: the only operator allowed is the one that connects the real part and the imaginary. |
Can a string contain a newline (\n)? | |
Yes. |
Do tokens have to be separated by whitespace? | |
No, they do not. |
Are the following numbers legal: | |
Those are all valid numbers. |
Can a PAIR contain complex numbers (e.g, <7i, 8i>)? | |
No. |
Is -54.2e-7.8 a valid REAL? | |
No, the exponent can only be an integer. |
Are the following legal REALs? | |
Only the last one is a valid REAL. |
1. Is the hex number 0x acceptable? | |
1. No. 2. 0+i: no, 0i: yes, +0i: yes, -0i: yes. (Each component must have an explicit coefficient.) 3. Yes. 4. Yes. |
You said that a string can contain newline (\n). Do you mean a newline or a literal '\n'? I.e are the following strings legal? | |
Both cases are valid STRINGs. In the second case, you should print the number of the last line that contains part of the token. (E.g, if the string mentioned in the question starts on line 1, then the line number printed should be 3.) |
Are 0xa45b and 0x12d34g8 legal hex? | |
'0xa45b' is a valid HEX, but '0x12d34g8' is not. |
Is 0d01 a legal int ? | |
No, INTs can't have leading zeroes. |
we want to write an expression that will include \n as a character and | |
Use this instead: (.|\n) |
Should error messages be printed to stderr or stdout? | |
stdout. |
Is 2.5e-0d5 legal? | |
No, the exponent can only be a "simple" integer. |
How should this string be analyzed: | |
The comment is part of the string. E.g, when given such a string in its input, your lexical analyzer should output: Line n: Found token STRING (lexeme: '" /* comment */ "'). |
Can a HEX have a decimal point, a sign or an exponent? (e.g, 0x-4, 0x4.5, 0x4.a, 0x4.5e-abc) | |
No. |
Do C++ style comments have to start at the beginning of the line and be the | |
No, they don't. For example: x = 1 + 1; // Put 2 in x Your lexical analyzer should identify the last part ("//Put 2 in x") as a comment, and ignore it. |
Is the number 4e+0002 a legal one? or 4e0001 ? (leading zeroes after "e") | |
Yes. |
Is 0e+1 legal? | |
Yes. |
Is 5i legal? (without any sign) | |
Yes. |
Is 5+001i legal? or 5+0000i ? (leading zeroes before i) | |
No: the coefficients must be valid numbers, and "001" or "0000" are not valid INTs, REALs or HEXes. |
Can " apperas in a string as a charecter (like in C language, we can write \" in the string in order to get it as a character in the string) | |
A quotation mark can't appear inside a string. (The first quotation mark ends the string.) |