Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. %{
  2. #include <math.h>
  3. #include <string.h>
  4. %}
  5.  
  6. INTEGER (0|-?[1-9][0-9]*)
  7. FLOAT (-?0\.[0-9]*[1-9]|-?[1-9][0-9]*\.[0-9]*[1-9])
  8. STRING \"[,\(\)%\/:=.\\a-zA-Z0-9]*\"
  9. IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
  10.  
  11. %%
  12. . {
  13. if(isLanguageSpecific(yytext)){
  14. printf("Language specific: %s\n", yytext);
  15. }
  16. }
  17. {INTEGER} {
  18. printf("An integer: %s\n", yytext);
  19. }
  20.  
  21. {FLOAT} {
  22. printf("A float: %s\n", yytext);
  23. }
  24.  
  25. {IDENTIFIER} printf("An indentifier: %s\n", yytext);
  26.  
  27. {STRING} {
  28. printf("A string: %s\n", yytext);
  29. }
  30.  
  31. %%
  32. char codesTable[100][50];
  33. int codesTableDim = 0;
  34.  
  35. int isLanguageSpecific(char* atom){
  36. int i;
  37. for(i = 0; i < codesTableDim; i++){
  38. if(strcmp(codesTable[i], atom) == 0){
  39. return 1;
  40. }
  41. }
  42. return 0;
  43. }
  44.  
  45. void buildCodesVector(){
  46. printf("Building...");
  47. FILE* f = fopen("resources\\codesTable.txt", "r");
  48. char buffer[50];
  49.  
  50. while(fgets(buffer, 50, f)){
  51. //codesTable[codesTableDim++] = buffer;
  52. strcpy(codesTable[codesTableDim++], buffer);
  53. }
  54. }
  55.  
  56. int main(int argc, char **argv){
  57. ++argv; --argc; // skip over program name
  58.  
  59. buildCodesVector();
  60.  
  61. if(argc > 0){
  62. yyin = fopen(argv[0], "r");
  63. } else {
  64. yyin = stdin;
  65. }
  66. //yylex();
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement