Author Topic: Questions relating to 'Introduction to Compilers' class  (Read 4411 times)

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3038
  • LV: 372
  • Gender: Male
  • Bringer of Salt
    • View Profile
Questions relating to 'Introduction to Compilers' class
« on: June 08, 2013, 09:18:08 AM »
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 AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901
Join the CP Discord Server

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19929
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: Questions relating to 'Introduction to Compilers' class
« Reply #1 on: June 08, 2013, 10:07:18 AM »
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      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


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

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

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3038
  • LV: 372
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Questions relating to 'Introduction to Compilers' class
« Reply #2 on: June 09, 2013, 09:29:30 AM »
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 AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901
Join the CP Discord Server

Online KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3038
  • LV: 372
  • Gender: Male
  • Bringer of Salt
    • View Profile
Re: Questions relating to 'Introduction to Compilers' class
« Reply #3 on: June 13, 2013, 11:10:12 PM »
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.
(click to show/hide)

2.) Remove left recursion and backtracking in the following grammar:
Code: [Select]
X -> XaY | XbY
X -> Y
Y -> YcB
Y -> a | B
B -> X



Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


NNID: KK20-CP
Discord: KK20 Tyler#8901
Join the CP Discord Server