/magic-spells

The super-repository for all of the parts and the final product of Compiler Design.

Primary LanguageYaccGNU General Public License v3.0GPL-3.0

The super-repository for all of the parts and the final product of Compiler Design. Name here is a reference to Crystal Castles' song Magic Spells which can be heard here. Definitely one of my favorite electronic albums of all time, but programming and compilation are by no means 'magic.' The sub-repositories are in order of creation, so the newest version is at the bottom. As of yakety-yak, the compiler has a makefile (please see each sub-header for more details) that creates the output jsgc which stands for John's Super Good Compiler.

  1. Usage: ./jsgc <input.txt> <output.c>
  2. Notes get ignored, so they will not show up in the output file
  3. You will need to specify it as an <outputName.c> with the .c extension in order to use gcc
  4. There is a stream mode if you don't use any parameters when running, but it will not save any work you do
  5. The makefile has commands: a) make
    compiles the program. highly recommend to use because compiling without it takes a lot of typing
    b) make clean
    removes all intermediate files (mainly from flex and bison, and also the output files from other make commands)
    c) there are other make commands, but they include some direct file paths, so I suggest using the regular usage
    i) make 1
    ii) make 2
    iii) make 3
    iv) make 4
    v) make 5
    vi) make sample
    vii) make fail
    please note that these make commands require the .txt files to be in /main/programs
  6. Errors caught in program:
    a) Syntax Errors
    b) Double declared variables
    c) Undeclared variables
    d) Integer overflow/invalid number
    e) i/o file errors
    f) segmentation fault error message (there is just a message of what it means when a seg fault happens, the error is not actually caught and will still seg fault the compilation)
  7. Most errors will just show the error in the console along with some relevant information (line no, variable name), but will not acutally stop the compilation, so your program may still compile when you use gcc
  • Flexicution This is the flex file that takes the strings and tokenizes them
  • HandItOver This is the c file that creates structures to turn tokens into strings for c file
  • instructions Instructions for the project
  • Makefile Makefile for program
  • YaketyYak File takes tokens and structures from Flexicution.l and HandItOver.c and ensures the grammar is legal. Also finds errors described in 5) and creates output c files that can be compiled

Note: The repository links below are broken on this branch. Please refer to the branch named "old" to see the old files.

Hip to be Square is a song by Huey Lewis and the News and I had absolutely no reason to name it this as I cannot think of any connection that it has to the song. The only connection is that a compiler (that is being designed in this class) is taking code and making it 'square' by compiling it, but that is such a stretch that you might as well completely disregard this.

Project part 1A where we modify the earlier code (in this case, hip-to-be-square) to use flex to find tokens. The temporary name this had was FlexicalAnalysis since the first part of the project was LexicalAnalysis and it felt very fitting. The only song that I knew had 'flex' in the tile is Logic's Flexicution which you can listen to here. Program contains a menu that details its uses (but not the language that it compiles, please see instructions or input.txt). It does not accept a parameter via the command line but I plan to add that in the next iteration of the project.

Yakety Yak is a song by The Coasters. The reason that I named it this is because (very logical reasoning incoming) bison which is like yak which is said the same as yacc. Personally, I really hate this song, and it frustrated me beyond belief while coding this because it was stuck in my head for almost six hours. Some important things to note about this are:

  • Usage: ./jsgc <file.txt>

  • There is a makefile for convenience, compiles both files (creating a header file for the bison) and outputs the compiled code jsgc.

    • to use, just type 'make'
    • to clean, type 'make clean'
  • The code is no longer in C++. The code is now entirely in C and uses gcc for compilation.

  • The code no longer has the basic "user interface" that it had in flexicution.

  • There is no 'graceful' exit from typing directly into parser.

  • Things typed directly into the parser are not saved.

  • It does not create output files (as of 3/23/23, may be changed soon).

  • The main function is now in the bison file.

  • Program no longer outputs tokens like it did in flexicution, outputs parse messages.

  • Please note that the parse messages are displayed from depth first, following the bottom-most rule it can before showing the more general rules.

  • response

  • sample-failure

  • flexical-analysis

  • Makefile

  • sample-success

  • yakety-yak

  • CFG: document with the grammar

Hand It Over is a song on MGMT's album called Little Dark Age. This is an intermediate step of the project, so I didn't include the main files as this is just a header file (you can include it in your file by adding the line #include "HandItOver.h" to your code, but it does not do anything at this point).