Questions relating to 'Introduction to Compilers' class

Started by KK20, June 08, 2013, 03:18:08 am

Previous topic - Next topic

KK20

I may have some more questions regarding this class I am taking right now, so I'll be making a thread just to make sure.

Anyways, my friend discovered in the course text a possible error. It says that the regular expression for a legal floating-point constant in Pascal is as follows:

(ε|+|-)(0|d*).(0|d*)

ε = null character
d = 0..9
The text says this ensures that a number exists on both the left and right sides of the decimal point. But how can that be?

If I choose ε and d* in both instances and set them to have zero repetitions, that would leave me with only the decimal point (from what I saw, this caused an error in Pascal).

Thus, I proposed this:

(ε|+|-)((d+.d*)|(d*.d+))

This ensures that we have at least one digit on the left or right sides of the decimal, right? Is there a better way to do this?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Blizzard

I agree, the first one seems like it's possible to just get a dot character and your regular expression seems to solve that problem.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

KK20

Cool, thanks for the confirmation. It looks like we have something to address to the teacher, seeing as this is an instructor's text.

No other problems found so far. Got the DFSM for the lexer working. And they said it would take 20 hours to do... (half my time was spent figuring out how to use C++ again :P)

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

KK20

Bleh, that was a brutal first exam. Here are two questions I struggled with:

1.) Given that the alphabet is {a,b}, write a regular expression that contains all the strings that have exactly 2 a's and at least 1 b.
My Answer after 20 minutes: ShowHide

b+ab*ab* | ab*ab+ | ab+ab*


2.) Remove left recursion and backtracking in the following grammar:

X -> XaY | XbY
X -> Y
Y -> YcB
Y -> a | B
B -> X

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!